Changes between Version 4 and Version 5 of Tutorials


Ignore:
Timestamp:
Mar 7, 2016, 2:50:48 PM (10 years ago)
Author:
fma
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Tutorials

    v4 v5  
    1616
    1717As Py4bot has a nice 3D simulation engine, based on [http://vpython.org VPython], for this example, we are going to setup an application for a simulated 3DoF hexapod.
    18 
    19 To control the simulation, we are going to use a [http://www.thrustmaster.com/en_IN/products/firestorm-dual-analog-3 Thrustmaster Firestorm Dual Analog 3] gamepad.
    2018
    2119All usefull classes are available from the '''{{{api.py}}}''' module. So, we just have to import things from here. Let's create a '''{{{hexapod.py}}}''' file to put our code, and import what we are going to use in this tutorial:
     
    151149Some of these values seem obvious, some don't; we'll discuss all this later.
    152150
    153 Now, let's create our robot. In '''{{{hexapod.py}}}''', add:
     151We need to create our remote control, in order to drive our simulated robot. for this example, let's use an old gamepad, a [http://www.thrustmaster.com/en_IN/products/firestorm-dual-analog-3 Thrustmaster Firestorm Dual Analog 3]. As I own such gamepad, I already added support in Py4bot.
     152
     153Back in '''{{{hexapod.py}}}''':
     154
     155{{{
     156#!python
     157
     158class Gamepad(api4bot.RemoteControl):
     159    def _createFrontend(self):
     160        return FrontendFactory().create("thrustmaster", path=THRUSTMASTER_PATH)
     161
     162    def _buildComponents(self):
     163        self._addButton(command=api4bot.GaitSequencer().walkStop, key="button_000")
     164        self._addButton(command=api4bot.GaitSequencer().walkStep, key="button_003")
     165
     166        self._addButton(command=api4bot.GaitSequencer().selectPrevGait, key="button_009", trigger="hold")
     167        self._addButton(command=api4bot.GaitSequencer().selectNextGait, key="button_008", trigger="hold")
     168
     169        self._addJoystick(command=api4bot.GaitSequencer().walk, keys=("analog_02", "analog_03", "analog_00"), mapper=api4bot.MapperWalk())
     170
     171        self._addButton(command=self.robot.incBodyPosition, key="button_004", mapper=api4bot.MapperSetValue(dz=+5))
     172        self._addButton(command=self.robot.incBodyPosition, key="button_005", mapper=api4bot.MapperSetValue(dz=-5))
     173
     174        self._addAnalog(command=self.robot.setBodyExtraPosition, key="analog_01", modifier="button_006", mapper=api4bot.MapperSet('z'))
     175}}}
     176
     177Now, let's create our robot. Still in '''{{{hexapod.py}}}''', add:
    154178
    155179{{{
     
    199223}}}
    200224
     225Final steps are: instanciate the gamepad, launch the gait sequencer, and run the robot!
     226
     227{{{
     228#!python
     229
     230    remote = Gamepad(robot)
     231
     232    GaitSequencer().start()
     233    remote.start()
     234
     235    robot.setBodyPosition(z=-100)
     236    GaitManager().select("riple")
     237
     238    robot.mainLoop()
     239
     240    remote.stop()
     241    remote.join()
     242    GaitSequencer().stop()
     243    GaitSequencer().join()
     244}}}
    201245
    202246