Plug'n Play robotics

Autodection of dynamixel based robot

In pypot you can use a specific function - autodetect_robot - to automatically scan each usb2serial ports and creates a robot will all attached dynamixel motors. This is a convenient way to quickly plug a few motors and used them as a Robot.

You can create a robot for any configurations of robot (e.g. using multiple dynamixel buses) using:


In [1]:
from pypot.dynamixel import autodetect_robot

robot = autodetect_robot()

This will create a robot with all motors found attached:


In [2]:
[m.name for m in robot.motors]


Out[2]:
['motor_11', 'motor_12', 'motor_13', 'motor_14', 'motor_15', 'motor_16']

As you can see, motor's names are defined as motor_{id}.

Note that obviously, pypot can't guess the motors offset and limits so default value will be used:

  • offset = 0
  • angle_limit = current ones

You can then use you robot as any other kind of robot:


In [3]:
robot.start_sync()

for m in robot.motors:
    m.compliant = False
    m.goal_position = 0.0

Exporting the configuration

As scanning all ports can be time consumming, it's recommended to use autodetect_robot only once, and then to export the robot's configuration.


In [4]:
config = robot.to_config()
config


Out[4]:
{'controllers': {'dxl_controller_0': {'attached_motors': ['motor_11',
    'motor_12',
    'motor_13',
    'motor_14',
    'motor_15',
    'motor_16'],
   'port': '/dev/tty.usbserial-A4012ACT',
   'sync_read': False}},
 'motorgroups': {},
 'motors': {'motor_11': {'angle_limit': (-67.6, 112.46),
   'id': 11,
   'offset': 0.0,
   'orientation': 'direct',
   'type': 'RX-64'},
  'motor_12': {'angle_limit': (-89.88, 89.88),
   'id': 12,
   'offset': 0.0,
   'orientation': 'direct',
   'type': 'RX-64'},
  'motor_13': {'angle_limit': (-89.88, 89.88),
   'id': 13,
   'offset': 0.0,
   'orientation': 'direct',
   'type': 'RX-64'},
  'motor_14': {'angle_limit': (-67.6, 112.46),
   'id': 14,
   'offset': 0.0,
   'orientation': 'direct',
   'type': 'RX-28'},
  'motor_15': {'angle_limit': (-89.88, 89.88),
   'id': 15,
   'offset': 0.0,
   'orientation': 'direct',
   'type': 'RX-28'},
  'motor_16': {'angle_limit': (-89.88, 89.88),
   'id': 16,
   'offset': 0.0,
   'orientation': 'direct',
   'type': 'RX-28'}}}

The config can directly be edited: e.g. to change motor's names or set the correct offsets:


In [5]:
config['motors']['motor_13']['offset'] = 22.5

You can save it to a json file which can then easily be reloaded.


In [6]:
import json

with open('my-config.json', 'w') as f:
    json.dump(robot.to_config(), f, indent=2)

In [7]:
robot.close()

In [8]:
from pypot.robot import from_json

robot = from_json('my-config.json')