| 28 | | from py4bot.api import Logger |
| 29 | | from py4bot.api import GaitFactory, GaitManager, GaitSequencer |
| 30 | | from py4bot.api import Robot, Body |
| 31 | | from py4bot.api import ActuatorPool, ServoPool, Veyron |
| 32 | | from py4bot.api import Leg3DofIk, Leg3Dof, Coxa, Femur, Tibia |
| 33 | | from py4bot.api import RemoteControl, FrontendFactory |
| 34 | | from py4bot.api import MapperSet, MapperSetValue, MapperWalk |
| 35 | | }}} |
| 36 | | |
| 37 | | Now, let's create the robot! A multi-legs robot is mainly build from a body, and several legs. In most cases, the defaut body provided by Py4bot is OK, but in any case, we need to create legs. The second thing we also need to create is the ''actuator pool'', which contain all legs joints. In our example, joints are standard servos. So, here is what the main robot class looks like: |
| | 30 | from py4bot import api as api4bot |
| | 31 | }}} |
| | 32 | |
| | 33 | Now, let's create the robot! A multi-legs robot is mainly build from a body, and several legs. In most cases, the defaut body provided by Py4bot is OK, but in any case, we need to create legs. |
| | 34 | |
| | 35 | The second thing we also need to create is the ''actuator pool'', which contain all legs joints. In our example, joints are standard servos. So, here is what the main robot class looks like: |
| 154 | | |
| 155 | | # Servos calibration |
| 156 | | SERVOS_CALIBRATION = { |
| 157 | | 0: {'pulse90': 1500, 'ratio': 1000./90.}, # tibia leg RF |
| 158 | | 1: {'pulse90': 1500, 'ratio': 1000./90.}, # femur leg RF |
| 159 | | 2: {'pulse90': 1500, 'ratio': 1000./90.}, # coxa leg RF |
| 160 | | 3: {'pulse90': 1500, 'ratio': 1000./90.}, # free |
| 161 | | |
| 162 | | 4: {'pulse90': 1500, 'ratio': 1000./90.}, # tibia leg RM |
| 163 | | 5: {'pulse90': 1500, 'ratio': 1000./90.}, # femur leg RM |
| 164 | | 6: {'pulse90': 1500, 'ratio': 1000./90.}, # coxa leg RM |
| 165 | | 7: {'pulse90': 1500, 'ratio': 1000./90.}, # free |
| 166 | | |
| 167 | | 8: {'pulse90': 1500, 'ratio': 1000./90.}, # tibia leg RR |
| 168 | | 9: {'pulse90': 1500, 'ratio': 1000./90.}, # femur leg RR |
| 169 | | 10: {'pulse90': 1500, 'ratio': 1000./90.}, # coxa leg RR |
| 170 | | 11: {'pulse90': 1500, 'ratio': 1000./90.}, # free |
| 171 | | |
| 172 | | 12: {'pulse90': 1500, 'ratio': 1000./90.}, # free |
| 173 | | 13: {'pulse90': 1500, 'ratio': 1000./90.}, # tibia leg LR |
| 174 | | 14: {'pulse90': 1500, 'ratio': 1000./90.}, # femur leg LR |
| 175 | | 15: {'pulse90': 1500, 'ratio': 1000./90.}, # coxa leg LR |
| 176 | | |
| 177 | | 16: {'pulse90': 1500, 'ratio': 1000./90.}, # free |
| 178 | | 17: {'pulse90': 1500, 'ratio': 1000./90.}, # tibia leg LM |
| 179 | | 18: {'pulse90': 1500, 'ratio': 1000./90.}, # femur leg LM |
| 180 | | 19: {'pulse90': 1500, 'ratio': 1000./90.}, # coxa leg LM |
| 181 | | |
| 182 | | 20: {'pulse90': 1500, 'ratio': 1000./90.}, # free |
| 183 | | 21: {'pulse90': 1500, 'ratio': 1000./90.}, # tibia leg RM |
| 184 | | 22: {'pulse90': 1500, 'ratio': 1000./90.}, # femur leg RM |
| 185 | | 23: {'pulse90': 1500, 'ratio': 1000./90.}, # coxa leg RM |
| 186 | | } |
| 187 | | }}} |
| | 151 | }}} |
| | 152 | |
| | 153 | Some of these values seem obvious, some don't; we'll discuss all this later. |
| | 154 | |
| | 155 | Now, let's create our robot. In '''{{{hexapod.py}}}''', add: |
| | 156 | |
| | 157 | {{{ |
| | 158 | #!python |
| | 159 | |
| | 160 | def main(): |
| | 161 | robot = Hexapod() |
| | 162 | }}} |
| | 163 | |
| | 164 | The main interrest of a multi-legs robot is to make it walk! But by default, the '''{{{Robot}}}''' class does not know any '''gait''', so, we have to teach it how to actually walk. |
| | 165 | |
| | 166 | Again, as Py4bot is a framework, it comes with some pre-defined gaits. So, all we have to do is to tell our robot which gaits to use (at least one), and give some params: |
| | 167 | |
| | 168 | {{{ |
| | 169 | #!python |
| | 170 | |
| | 171 | for gaitName in settings.GAITS: |
| | 172 | legsIndexGroups = settings.GAIT_LEGS_GROUPS[gaitName] |
| | 173 | gaitParams = settings.GAIT_PARAMS[gaitName] |
| | 174 | gait = api4bot.GaitFactory().create(gaitName, legsIndexGroups, gaitParams) |
| | 175 | api4bot.GaitManager().add(gait) |
| | 176 | }}} |
| | 177 | |
| | 178 | Let's see what wee need to add in the '''{{{settings.py}}}''' module: |
| | 179 | |
| | 180 | {{{ |
| | 181 | #!python |
| | 182 | |
| | 183 | # Gaits definitions |
| | 184 | GAITS = ("tripod", "tetrapod", "riple", "metachronal", "wave") |
| | 185 | |
| | 186 | GAIT_LEGS_GROUPS = { |
| | 187 | 'tripod': (('RM', 'LF', 'LR'), ('RF', 'LM', 'RR')), |
| | 188 | 'tetrapod': (('RR', 'LM'), ('RF', 'LR'), ('RM', 'LF')), |
| | 189 | 'riple': (('RR',), ('LM',), ('RF',), ('LR',), ('RM',), ('LF',)), |
| | 190 | 'metachronal': (('RR',), ('LM',), ('RF',), ('LR',), ('RM',), ('LF',)), |
| | 191 | 'wave': (('RR',), ('RM',), ('RF',), ('LR',), ('LM',), ('LF',)) |
| | 192 | } |
| | 193 | |
| | 194 | GAIT_PARAMS = { |
| | 195 | 'tripod': {'length': 40., 'angle': 10., 'height': 40., 'minLength': 4., 'minAngle': 2., 'speedMin': 50., 'speedMax': 200.}, |
| | 196 | 'tetrapod': {'length': 40., 'angle': 10., 'height': 30., 'minLength': 4., 'minAngle': 2., 'speedMin': 50., 'speedMax': 200.}, |
| | 197 | 'riple': {'length': 40., 'angle': 10., 'height': 30., 'minLength': 4., 'minAngle': 2., 'speedMin': 50., 'speedMax': 300.}, |
| | 198 | 'metachronal': {'length': 40., 'angle': 10., 'height': 30., 'minLength': 4., 'minAngle': 2., 'speedMin': 50., 'speedMax': 200.}, |
| | 199 | 'wave': {'length': 40., 'angle': 10., 'height': 30., 'minLength': 4., 'minAngle': 2., 'speedMin': 50., 'speedMax': 200.} |
| | 200 | } |
| | 201 | }}} |
| | 202 | |
| | 203 | |
| | 204 | |
| | 205 | |
| | 206 | |
| | 207 | |
| | 208 | |