| 19 | | self._addComponent(Button, command=self.robot.incBodyPosition, key="button_004", mapper=MapperSetValue(dz=+5)) |
| 20 | | self._addComponent(Button, command=self.robot.incBodyPosition, key="button_005", mapper=MapperSetValue(dz=-5)) |
| | 18 | self._addComponent(Button, configs="walk", command=GaitSequencer().walkStop, key="button_000") |
| | 19 | self._addComponent(Button, configs="walk", command=GaitSequencer().walkStep, key="button_002") |
| | 20 | self._addComponent(Button, configs="walk", command=GaitSequencer().selectNextGait, key="button_006", trigger="hold") |
| | 21 | self._addComponent(Button, configs="walk", command=GaitSequencer().selectPrevGait, key="button_007", trigger="hold") |
| | 22 | |
| 23 | | self._addComponent(Analog, configs="body", command=self.robot.setBodyExtraPosition, key="analog_00", mapper=MapperSetMultiply('yaw', coef=-15)) |
| 24 | | self._addComponent(Analog, configs="body", command=self.robot.setBodyExtraPosition, key="analog_03", mapper=MapperSetMultiply('pitch', coef=-15)) |
| 25 | | self._addComponent(Analog, configs="body", command=self.robot.setBodyExtraPosition, key="analog_02", mapper=MapperSetMultiply('roll', coef=15)) |
| | 25 | # Body inc. translation |
| | 26 | self._addComponent(Analog, command=self.robot.incBodyPosition, key="analog_04", modifier="button_008", mapper=MapperSetMultiply('dx', coef=5)) |
| | 27 | self._addComponent(Analog, command=self.robot.incBodyPosition, key="analog_05", modifier="button_008", mapper=MapperSetMultiply('dy', coef=5)) |
| | 28 | self._addComponent(Button, command=self.robot.incBodyPosition, key="button_004", modifier="button_008", mapper=MapperSetValue(dz=+10)) |
| | 29 | self._addComponent(Button, command=self.robot.incBodyPosition, key="button_005", modifier="button_008", mapper=MapperSetValue(dz=-10)) |
| | 30 | |
| | 31 | # Body inc. rotation |
| | 32 | self._addComponent(Analog, command=self.robot.incBodyPosition, key="analog_04", modifier="button_009", mapper=MapperSetMultiply('droll', coef=5)) |
| | 33 | self._addComponent(Analog, command=self.robot.incBodyPosition, key="analog_05", modifier="button_009", mapper=MapperSetMultiply('dpitch', coef=-5)) |
| | 34 | self._addComponent(Button, command=self.robot.incBodyPosition, key="button_004", modifier="button_009", mapper=MapperSetValue(dyaw=+5)) |
| | 35 | self._addComponent(Button, command=self.robot.incBodyPosition, key="button_006", modifier="button_009", mapper=MapperSetValue(dyaw=-5)) |
| | 36 | |
| | 37 | # Body extra translation |
| | 38 | self._addComponent(Analog, configs="body", command=self.robot.setBodyExtraPosition, key="analog_02", modifier="button_008", mapper=MapperSetMultiply('x', coef=30)) |
| | 39 | self._addComponent(Analog, configs="body", command=self.robot.setBodyExtraPosition, key="analog_03", modifier="button_008", mapper=MapperSetMultiply('y', coef=30)) |
| | 40 | self._addComponent(Analog, configs="body", command=self.robot.setBodyExtraPosition, key="analog_01", modifier="button_008", mapper=MapperSetMultiply('z', coef=20)) |
| | 41 | |
| | 42 | # Body extra rotation |
| | 43 | self._addComponent(Analog, configs="body", command=self.robot.setBodyExtraPosition, key="analog_00", modifier="button_009", mapper=MapperSetMultiply('yaw', coef=-10)) |
| | 44 | self._addComponent(Analog, configs="body", command=self.robot.setBodyExtraPosition, key="analog_03", modifier="button_009", mapper=MapperSetMultiply('pitch', coef=-10)) |
| | 45 | self._addComponent(Analog, configs="body", command=self.robot.setBodyExtraPosition, key="analog_02", modifier="button_009", mapper=MapperSetMultiply('roll', coef=10)) |
| | 46 | |
| | 47 | # Inc feet neutral position |
| | 48 | self._addComponent(Button, command=self.robot.incFeetNeutral, key="button_005", mapper=MapperSetValue(dneutral=-10)) |
| | 49 | self._addComponent(Button, command=self.robot.incFeetNeutral, key="button_007", mapper=MapperSetValue(dneutral=+10)) |
| | 56 | We first define 2 remote control configs, ''walk'' and ''body'', as we don't have enough buttons to do all we want. In the first config, ''walk'', we define some components to make the robot walk, but also to change the body position (by increments). Note that when the config is not specified in the component definition, it means it is available in all configs. In the second config, ''body'', we define additional components to control the body. |
| | 57 | |
| | 58 | Then we add the components, using the {{{_addComponent()}}} method helper. This method takes the component class, the command to execute, the frontend key, a optional modifier, and a mapper. |
| | 59 | |
| | 60 | |
| | 61 | |
| | 62 | |
| | 63 | |
| | 64 | '''Mappers''' are simple objects helping to adapt params from '''!RemoteControl''' '''Components''' output to '''Robot'''/'''!GaitSequencer''' methods input. |
| | 65 | |
| | 66 | For example, to control the robot walk, we can create a '''Joystick''' component with 3 axes: X, Y, RZ. |
| | 67 | |
| | 68 | But the '''!GaitSequencer''' {{{walk()}}} method expects '''speed''', '''direction''', '''length''' and '''angle''' params. Using the '''!MapperWalk''' mapper, you can compute all these params from X/Y/RZ axes, and send them to the '''walk()''' method. That's what we did in the [[Tutorials|tutorials]]. |
| | 69 | |
| | 70 | See [https://framagit.org/fma38/Py4bot/blob/master/py4bot/inputs/mappers/mapper.py py4bot/inputs/mappers/mapper.py] to see how this mapper is defined. |
| | 71 | |
| | 72 | Of course, you can define your own '''Mappers'''. |
| | 73 | |
| | 74 | |