| 5 | | The first method, '''{{{_createFrontend}}}''' must return a valid frontend. We just saw in [[Tutorial4AddInputFrontendSupport|previous tutorial]] how to create such frontends. |
| | 5 | As we've seen in [[Tutorial1FirstRobot|tutorial 1]], we created a '''{{{Gamepad}}}''' class in order to control our robot. This class inherits from '''{{{RemoteControl}}}''', and implements a few virtual methods: |
| | 6 | |
| | 7 | {{{ |
| | 8 | #!python |
| | 9 | |
| | 10 | class Gamepad(RemoteControl): |
| | 11 | def _createFrontend(self): |
| | 12 | return Thrustmaster(settings.THRUSTMASTER_PATH) |
| | 13 | |
| | 14 | def _buildComponents(self): |
| | 15 | self._addConfig("walk") |
| | 16 | self._addConfig("body") |
| | 17 | |
| | 18 | self._addComponent(Button, command=self.selectNextConfig, key="button_008", trigger="hold") |
| | 19 | self._addComponent(Button, command=self.selectPreviousConfig, key="button_009", trigger="hold") |
| | 20 | |
| | 21 | self._addComponent(Button, command=self.robot.incBodyPosition, key="button_004", mapper=MapperSetValue(dz=+5)) |
| | 22 | self._addComponent(Button, command=self.robot.incBodyPosition, key="button_005", mapper=MapperSetValue(dz=-5)) |
| | 23 | self._addComponent(Joystick, configs="walk", command=GaitSequencer().walk, keys=("analog_02", "analog_03", "analog_00"), mapper=MapperWalk()) |
| | 24 | |
| | 25 | self._addComponent(Analog, configs="body", command=self.robot.setBodyExtraPosition, key="analog_00", mapper=MapperSetMultiply('yaw', coef=-15)) |
| | 26 | self._addComponent(Analog, configs="body", command=self.robot.setBodyExtraPosition, key="analog_03", mapper=MapperSetMultiply('pitch', coef=-15)) |
| | 27 | self._addComponent(Analog, configs="body", command=self.robot.setBodyExtraPosition, key="analog_02", mapper=MapperSetMultiply('roll', coef=15)) |
| | 28 | }}} |
| | 29 | |
| | 30 | The first method, '''{{{_createFrontend()}}}''' must return a valid frontend (we just saw in [[Tutorial4AddInputFrontendSupport|previous tutorial]] how to create such frontends). This methods takes as first argument the frontend path in '''{{{/dev}}}'''. An additional argument can be given to override the '''{{{DEFAULT_AXIS_CALIBRATION}}}''' table. |
| | 31 | |
| | 32 | The second method, '''{{{_buildComponents()}}}''' is where interesting things take place. Here, we create the buttons/axis mapping to the robot controls. |
| | 33 | |
| | 34 | == Components == |
| | 35 | |
| | 36 | '''Py4bot''' implements different components to build a custom remote control mapping: |
| | 37 | |
| | 38 | === '''{{{Button}}}''' === |
| | 39 | |
| | 40 | This is a simple push button, whith several ''triggers'', in order to control its behavior: |
| | 41 | |
| | 42 | * click |
| | 43 | * double-click |
| | 44 | * press |
| | 45 | * release |
| | 46 | * hold |
| | 47 | * double-hold |
| | 48 | |
| | 49 | Default trigger is ''click'' (you must press and release the button quickly). |
| | 50 | |
| | 51 | === '''{{{Switch}}}''' === |
| | 52 | |
| | 53 | This is a button toggling between 2 states when you press it. |
| | 54 | |
| | 55 | === '''{{{Analog}}}''' === |
| | 56 | |
| | 57 | This component handles a single analog axis. |
| | 58 | |
| | 59 | === '''{{{Joystick}}}''' === |
| | 60 | |
| | 61 | Combines several '''{{{Analog}}}''' axis. |
| | 62 | |
| | 63 | == Configurations and modifiers == |
| | 64 | |
| | 65 | There are many commands to control the robot, and not enough physical buttons/axis on a gamepad. So, a solution is to multiplex these buttons/axis. There are 2 ways to do that: ''configurations'' and ''modifiers''. ''configurations'' allow us to change the entire mapping; ''modifiers'' only changes a button meaning. |
| | 66 | |
| | 67 | To create several ''configurations'', we use the '''{{{_addConfig()}}}''' method. This method take a string as argument, the name of the config. In our example, we created 2 ''configurations'', one to dynamically control the robot (make it walk), the other one to statically control the robot (move the body). |
| | 68 | |