https://github.com/dkogan/dynamixel
Perl driver for dynamixel servo motors. This is the repo for Device::Dynamixel at CPAN
https://github.com/dkogan/dynamixel
Last synced: 11 months ago
JSON representation
Perl driver for dynamixel servo motors. This is the repo for Device::Dynamixel at CPAN
- Host: GitHub
- URL: https://github.com/dkogan/dynamixel
- Owner: dkogan
- Created: 2011-01-16T01:51:24.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2011-06-12T06:00:30.000Z (about 15 years ago)
- Last Synced: 2025-02-28T16:09:19.537Z (over 1 year ago)
- Language: Perl
- Homepage:
- Size: 117 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.pod
- Changelog: Changes
Awesome Lists containing this project
README
=head1 OVERVIEW
This is a simple driver for control of Robotis Dynamixel servo
motors. This repository stores the history for the Device::Dynamixel
module on CPAN. Install the module via CPAN. CPAN page at
L
=cut
=head1 NAME
Device::Dynamixel - Simple control of Robotis Dynamixel servo motors
=cut
=head1 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];
=head1 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.
=head2 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 B 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
=head2 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.
=cut
=head1 CONSTRUCTOR
=head2 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.
=cut
=head1 METHODS
=head2 pingMotor( motorID )
Sends a ping. Status reply is returned
=cut
=head2 writeMotor( motorID, startingAddress, data )
Sends a command to the motor. Status reply is returned.
=cut
=head2 readMotor( motorID, startingAddress, howManyBytes )
Reads data from the motor. Status reply is returned.
=cut
=head2 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( )
=cut
=head2 triggerMotorQueue( motorID )
Sends a trigger for the queued commands. Status reply is returned.
=cut
=head2 resetMotor( motorID )
Sends a motor reset. Status reply is returned.
=cut
=head2 syncWriteMotor( motorID, startingAddress, data )
Sends a synced-write command to the motor. Status reply is returned.
=cut
=head2 moveMotorTo_deg( motorID, position_degrees )
Convenience function that uses the lower-level routines to move a motor to a
particular position
=cut
=head1 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.
=head1 REPOSITORY
L
=head1 AUTHOR
Dima Kogan, C<< >>
=head1 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.
=cut