NAME

Device::Dynamixel - Simple control of Robotis Dynamixel servo motors

SYNOPSIS

use Device::Dynamixel;

open my $pipe, '+<', '/dev/ttyUSB0' or die "Couldn't open pipe for reading and writing";
my $motorbus = Device::Dynamixel->new($pipe);

# set motion speed of ALL motors to 200
$motorbus->writeMotor($Device::Dynamixel::BROADCAST_ID,
                      $Device::Dynamixel::addresses{Moving_Speed_L}, [200, 0]);

# move motor 5 to 10 degrees off-center
$motorbus->moveMotorTo_deg(5, 10);

# read the position of motor 5
my $status = $motorbus->readMotor(5,
                                  $Device::Dynamixel::addresses{Present_Position_L}, 2);
my @params = @{$status->{params}};
my $position = $params[1]*255 + $params[0];

DESCRIPTION

This is a simple module to communicate with Robotis Dynamixel servo motors. The Dynamixel AX-12 motors have been tested to work with this module, but the others should work also.

A daisy-chained series string of motors is connected to the host via a simple serial connection. Each motor in the series has an 8-bit ID. This ID is present in every command to address specific motors. One Device::Dynamixel object should be created for a single string of motors connected to one motor port.

These motors communicate using a particular protocol, which is implemented by this module. Commands are sent to the motor. A status reply is sent back after each command. This module handles construction and parsing of Dynamixel packets, as well as the sending and receiving data when needed.

EXPORTED VARIABLES

To communicate with all motor at once, send commands to the broadcast ID:

$Device::Dynamixel::BROADCAST_ID

All the motor control addresses described in the Dynamixel docs are defined in this module, available as

$Device::Dynamixel::addresses{$value}

Defined values are:

ModelNumber_L
ModelNumber_H
Version_of_Firmware
ID
Baud_Rate
Return_Delay_Time
CW_Angle_Limit_L
CW_Angle_Limit_H
CCW_Angle_Limit_L
CCW_Angle_Limit_H
Highest_Limit_Temperature
Lowest_Limit_Voltage
Highest_Limit_Voltage
Max_Torque_L
Max_Torque_H
Status_Return_Level
Alarm_LED
Alarm_Shutdown
Down_Calibration_L
Down_Calibration_H
Up_Calibration_L
Up_Calibration_H
Torque_Enable
LED
CW_Compliance_Margin
CCW_Compliance_Margin
CW_Compliance_Slope
CCW_Compliance_Slope
Goal_Position_L
Goal_Position_H
Moving_Speed_L
Moving_Speed_H
Torque_Limit_L
Torque_Limit_H
Present_Position_L
Present_Position_H
Present_Speed_L
Present_Speed_H
Present_Load_L
Present_Load_H
Present_Voltage
Present_Temperature
Registered_Instruction
Reserved
Moving
Lock
Punch_L
Punch_H

To change the baud rate of the motor, the Baud_Rate address must be written with a value

$Device::Dynamixel::baudrateValues{$baud}

The available baud rates are

1000000
500000
400000
250000
200000
115200
57600
19200
9600

Note that the baud rate generally is cached from the last time the motor was used, defaulting to 1Mbaud at the start

STATUS RETURN

Most of the functions return a status hash that describes the status of the motors and/or returns queried data. This hash is defined as

{ from   => $motorID,
  error  => $error,
  params => \@parameters }

If no valid reply was received, undef is returned. Look at the Dynamixel hardware documentation for the exact meaning of each hash element.

CONSTRUCTOR

new( PIPE )

Creates a new object to talk to a Dynamixel motor. The file handle has to be opened and set-up prior to constructing the object.

METHODS

pingMotor( motorID )

Sends a ping. Status reply is returned

writeMotor( motorID, startingAddress, data )

Sends a command to the motor. Status reply is returned.

readMotor( motorID, startingAddress, howManyBytes )

Reads data from the motor. Status reply is returned.

writeMotor_queue( motorID, startingAddress, data )

Queues a particular command to the motor and returns the received reply. Does not actually execute the command until triggered with triggerMotorQueue( )

triggerMotorQueue( motorID )

Sends a trigger for the queued commands. Status reply is returned.

resetMotor( motorID )

Sends a motor reset. Status reply is returned.

syncWriteMotor( motorID, startingAddress, data )

Sends a synced-write command to the motor. Status reply is returned.

moveMotorTo_deg( motorID, position_degrees )

Convenience function that uses the lower-level routines to move a motor to a particular position

BUGS

An issue is the baud rate of the serial communication. The motors default to 1M baud. This is unsupported by the stock POSIX module in perl5, so the serial port must be configured externally, prior to using to this module.

REPOSITORY

https://github.com/dkogan/dynamixel

AUTHOR

Dima Kogan, <dkogan at cds.caltech.edu>

LICENSE AND COPYRIGHT

Copyright 2011 Dima Kogan.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.