PyUSB2AX pre-release documentation

API reference for usb2ax

«  Detailed instructions   ::   Contents

API reference for usb2ax

class usb2ax.Controller([device_id=0][, fix_sync_delay_time=False])

Initialize the connection to the USB2AX.

This will set up the serial port and scan for servo devices attached to the bus. You should have all the servos you want to use attached and switched on before calling this.

Suggested usage:

with Controller(device_id=0,fix_sync_read_delay=True) as dxl:
  do stuff...
Parameters:
  • device_id (integer) – Where the device is located. E.g. the default (0) represents /dev/ttyACM0
  • fix_sync_read_delay (boolean) – Set to True if you plan to use sync_read(). See Sync read delay timing for more information.
write(servo_id, parameter, value, register=False)

Write to control table of a single servo.

For example, to move servo with ID 1 to its central point:

with Controller() as dxl:
  dxl.write( 1, "goal_position", 512 )

If register is set to True, will not make the servo perform the command right away, rather, the command is buffered on the servo and will be executed when you call action()

Parameters:
  • servo_id (integer) – The bus ID of the servo to be written to.
  • parameter (string) – The control table point to write - a value allowed for the attached servo as listed in Control tables.
  • value (integer) – The value to write.
  • register (boolean) – Whether to do a registered write (default False, i.e. execute command straight away).
Raises:
  • ServoNotAttachedError – The servo with the given ID was not found on the bus when the object was created.
  • UnknownParameterError – The servo with the given ID does not support the parameter.
  • InvalidWriteParameterError – The parameter cannot be written because it is read-only.
read(servo_id, parameter)

Read a control table entry from a single servo.

Parameters:
  • servo_id (integer) – The bus ID of the servo to read from.
  • parameter (string) – The control table point to write - a value allowed for the attached servo as listed in Control tables.
Returns:

The value in the control table at the specified point

Return type:

integer

Raises:
  • ServoNotAttachedError – The servo with the given ID was not found on the bus when the object was created.
  • UnknownParameterError – The servo with the given ID does not support the parameter.
sync_write(servo_ids, parameter, values)

Write to the control tables of several servos.

Supply a list of servo ids, which parameter you want to change, and a list of new values.

For example, to move servo 1 to position 600 and servo 2 to position 400:

with Controller() as dxl:
  dxl.sync_write( [1,2], "goal_position", [600,400] )
Parameters:
  • servo_ids (iterable) – The bus IDs of the servos to modify.
  • parameter (string) – The control table point to write - a value allowed for the attached servo as listed in Control tables.
  • values (iterable) – The values to write.
Raises:
  • ServoNotAttachedError – At least one of the servos specified was not found on the bus when the object was created.
  • UnknownParameterError – At least one of the servos specified does not support the parameter.
  • InvalidWriteParameterError – The parameter cannot be written because it is read-only.
sync_read(servo_id, parameter, value)

Read from the control tables of several servos.

Supply a list of servo ids, which parameter you want to get.

with Controller(fix_sync_read_delay=True) as dxl:
  usb2ax.sync_read( [1,2], "id" ) # Returns [1,2]
Parameters:
  • servo_ids (iterable) – The bus IDs of the servos to read from.
  • parameter (string) – The control table point to write - a value allowed for the attached servo as listed in Control tables.
Returns:

A list of values from the servos specified.

Return type:

list

Raises:
  • ServoNotAttachedError – At least one of the servos specified was not found on the bus when the object was created.
  • UnknownParameterError – At least one of the servos specified does not support the parameter.
action()

Executes any actions registered on the servos by previously calling write() with the register argument set to True. This allows actions to be performed synchronously on many servos.

usb2ax.reset_usb2ax([device_id=0])

Reset the USB2AX device itself (rather than the attached servos). If this is successful the LED on the USB2AX will turn off for a few seconds then turn back on.

«  Detailed instructions   ::   Contents