wiki:Tutorial5AdvancedRemoteControlUsage

Version 3 (modified by fma, 8 years ago) ( diff )

--

Tutorial 5: Advanced remote control usage

Introduction

As we've seen in tutorial 1, we created a Gamepad class in order to control our robot. This class inherits from RemoteControl, and implements a few virtual methods:

class Gamepad(RemoteControl):
    def _createFrontend(self):
        return Thrustmaster(settings.THRUSTMASTER_PATH)

    def _buildComponents(self):
        self._addConfig("walk")
        self._addConfig("body")

        self._addComponent(Button, command=self.selectNextConfig, key="button_008", trigger="hold")
        self._addComponent(Button, command=self.selectPreviousConfig, key="button_009", trigger="hold")

        self._addComponent(Button, command=self.robot.incBodyPosition, key="button_004", mapper=MapperSetValue(dz=+5))
        self._addComponent(Button, command=self.robot.incBodyPosition, key="button_005", mapper=MapperSetValue(dz=-5))
        self._addComponent(Joystick, configs="walk", command=GaitSequencer().walk, keys=("analog_02", "analog_03", "analog_00"), mapper=MapperWalk())

        self._addComponent(Analog, configs="body", command=self.robot.setBodyExtraPosition, key="analog_00", mapper=MapperSetMultiply('yaw', coef=-15))
        self._addComponent(Analog, configs="body", command=self.robot.setBodyExtraPosition, key="analog_03", mapper=MapperSetMultiply('pitch', coef=-15))
        self._addComponent(Analog, configs="body", command=self.robot.setBodyExtraPosition, key="analog_02", mapper=MapperSetMultiply('roll', coef=15))

The first method, _createFrontend() must return a valid frontend (we just saw in 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.

The second method, _buildComponents() is where interesting things take place. Here, we create the buttons/axis mapping to the robot controls.

Components

Py4bot implements different components to build a custom remote control mapping:

Button

This is a simple push button, whith several triggers, in order to control its behavior:

  • click
  • double-click
  • press
  • release
  • hold
  • double-hold

Default trigger is click (you must press and release the button quickly).

Switch

This is a button toggling between 2 states when you press it.

Analog

This component handles a single analog axis.

Joystick

Combines several Analog axis.

Configurations and modifiers

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.

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).

Note: See TracWiki for help on using the wiki.