The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

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

VERSION

Version 0.024

SYNOPSIS

 use Device::Dynamixel;

 open my $pipe, '+<', '/dev/ttyUSB0' or die "Couldn't open pipe for reading and writing";

 my $dynamixel = Dynamixel->new($pipe, 5);
 while(<>)
 {
   $dynamixel->moveMotorTo_deg($_);
 }

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 address. This address is present in every command to address specific motors. The current implementation of this module uses an object per motor, NOT an object per string of motors. This may change in the future.

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.

VARIABLES

The dynamixel broadcast address is accessible as $Device::Dynamixel::BROADCAST_ADDR. The addresses of Dynamixel control registers are available as %Device::Dynamixel::addresses. This allows the application to send arbitrary commands to the motor. For example, to set the moving speed of the motor to 100%:

 $dynamixel->writeMotor($Device::Dynamixel::addresses{Moving_Speed_L},
                        [0xFF, 0x03]); # 0x3FF is the top speed for the
                                       # Dynamixel AX-12

CONSTRUCTOR

new(PIPE, MOTORADDRESS)

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( )

Sends a ping. STATUS reply is returned

writeMotor(startingAddress, data)

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

readMotor(startingAddress, howManyBytes)

Reads data from the motor. STATUS reply is returned.

writeMotor_queue(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( )

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

resetMotor( )

Sends a motor reset. STATUS reply is returned.

syncWriteMotor(startingAddress, data)

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

pullMotorReply( )

Performs a blocking read on the input pipe, and returns a parsed packet when it is received.

moveMotorTo_deg(position_degrees)

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

BUGS

There are several aspects of this module that are unideal and may change in the future. The current implementation ties an instance of a Device::Dynamixel object to a particular motor, NOT to a string of motors. This means that talking to multiple motors requires multiple instances. This imposes a requirement that only one motor can be controlled at any given time. Further, multi-motor commands like syncWriteMotor( ) become essentially useless.

Another major 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 external 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.