Dynamixel Servo Library

Hello All,

I have recently been playing with the new Dynamixel MX-28T Servos http://www.robotis.com/xe/dynamixel_en.
Unfortunately because they are fairly new there isn't much information online about them, and more importantly how to use them with an Arduino!

It took a bit of research and a little hacking to get them working, so I thought I would save others the trouble of going through the same and provide some instructions.
The first thing that made things alot easier was that a developer by the name of Pablo Gindel had already written a library for Dynamixel's previous line of servos, the AX-12's.
Here is a link to his page which contains the download and some simple instructions - http://www.pablogindel.com/informacion/the-arduinodynamixel-resource-page/.

However all is not as simple as it may first seem. This library is almost 2 years old, and the instructions are now incorrect and require a little bit extra effort to get working.

So the first thing to do is download the file and place the ax12 folder in the /libraries directory in your Arduino IDE install directory.
Now we need to update it.
The change is rather simple, open the ax12 folder you have just copied and open the ax12.cpp file using a text editor.
Find the "wiring.h" include, and change it to "Arduino.h".
Save the file, and close it.

The next alteration must be made to core Arduino IDE files. I must point out that this change allows this library to work, but I don't know what effect it has outside the use of these servos.
You need to find the HardwareSerial.cpp file, you should find it in /hardware/arduino/cores/arduino folder of you Arduino IDE install directory.
This change is documented in the original instructions but unfortunately the file has changed since and the code you are meant to comment out no longer exists.
The code you need to comment out looks like this:

SIGNAL(USART1_RX_vect)
{
  unsigned char c = UDR1;
  store_char(c, &rx_buffer1);
}

This modification is necessary as the ax12 library rewrites how the serial port is used. I should mention that obviously you are going to be controlling the Dynamixel servos using the serial port (TX1 and RX1 on the Mega, TX and RX on anything else), I would therefore strongly suggest you use an Arduino Mega for your project as it has multiple serial ports and still allows you to debug through the USB serial port. I have got this working on a Duemilanove though so it's not a problem, just remember to unplug the tx and rx wires connecting the Arduino to the servo when downloading a new program, don't use any serial communications (take a look at SoftwareSerial), and you will also need to comment out more lines in the HardwareSerial.cpp file - everything after the store_char function up to the serialEventRun function. For the current version this is lines 88 - 160.

OK and finally remember to common your grounds! The ground on the Arduino must be connected to the servo ground otherwise you will find that communication is very intermittent (if at all).

I hope this very quick guide has helped a few of you, because I failed to find anything on the internet that was recent enough to work easily. This should work with all Dynamixel servos - AX MX RX and EX. Although if you choose to use the RS485 models (4 wire) rather than the TTL models (3 wire) you will have to use the adapter which can be found in Pablo Gindel's original link above.

Good luck!

The best library for the Dynamixel is Arduino y Dynamixel AX-12.
It works very very well.

The only issue with the Savage Electronics library is that it requires extra hardware to work.
The one I recommended doesn't need anything.

Hi Flex,

I am also trying to connect a MX-28T servo to an Arduino, but have had no luck. I followed the instructions carefully about changing the "Arduino.h" includes and commenting out the lines in the HardwareSerial.cpp, but I think my wiring is the problem.

When I load the program into my Arduino Mega 1280 using the Arduino 1.0.1 IDE, my serial monitor says the following:
deteccion: 0
ID detectado: 1
delay: 0
error lectura: 1920

posicion: 0
velocidad: 0
carga: 0

This is the same output as if I were to run the sketch with absolutely nothing connected. Here is how my wiring is set-up:

I chained 5 batteries in series to raise the voltage up to 12.71 since the recommended voltage of the MX-28 is 10-14.8 volts and the Arduino could only supply 9v.

The Arduino is being powered by the USB.

Ground is connected between the Arduino ground pin, the battery's ground, and the servo ground pin. I heard the ground between the Arduino needs to be connected the ground of the servo's.

The Tx1 and Rx1 are connected in the same row of the breadboard as the data pin for the servo.

Any help would be very useful!

Thanks!

-Alonso Martinez

I also tried the following things:

changing my baud rate to 57600 since I read that it's the default for a brand new the MX-28.

AX12::init (57600);

Instead of using Pablo's autoDetect function, hard coding the servo ID to 1, but no luck =(

motor.id = 1;

Thanks!

-Alonso

Flex:
The only issue with the Savage Electronics library is that it requires extra hardware to work.
The one I recommended doesn't need anything.

I are right. But the MX28 costs about 200$, the extra hardware required by Savageelectronics library costs about 1$. I think it is not too much. :grin:

Hi,
I am wondering, anyone tried to write the source code firmware in c of Mx28 ?

Amartin2:
changing my baud rate to 57600 since I read that it's the default for a brand new the MX-28.
AX12::init (57600);

Hi Amartin2,

Sorry for the late reply, I don't check this forum very often.
Sorry I didn't make it clear in the instructions, you need to use AX12::init(1000000) because the library is designed to work at that speed.
This means that you need to change the baud rate of the dynamixels to 1Mbps. The only way I was able to do this was using their Dynamixel2USB adapter.
I know its annoying that you have to buy yet another piece of kit, but at least you only have to buy one.

Does this library work for Arduino Uno? Because I tried to this but in my hardware/arduino/core/arduino, there is no HardwareSerial.cpp file. I only have HardwareSerial.h file and I don't know what to do with that. Please help. Thanks.

Hello BeepBoop,

The Arduino Uno only has one serial output (Tx and Rx) and I believe that this library needs to have at least two.

I would read all of the comments in Pablo Gindel's website and look for comments using Arduinos with one serial port. I remember seeing plenty.

What Dynamixel are you using? if you are using the MX-28 then you need a library that Pablo hasn't released yet that I can pass along.

-Alonso

Hi Amartin2,

Ah yes, I am using the Dynamixel MX-28T. I would greatly appreciate it if you could share that library with me. Please and thank you! And I will comb through the comments now....although since I'm a complete noob to Arduinos, I might not really understand it. Could you by any chance explain what the Tx and Rx are and perhaps why it matters? Thank you once more.

Hallo, I have testet it, but my MX-28 do not run.

I have an arduino Uno and then the
http://www.dfrobot.com/index.php?route=product/product&product_id=579#.UKprORJ5PJP
Driver Board, but nothing happen wenn I start he sketch (serial Monitor).

I have pluged in 7.2V to the Driver Board.

Can anybody help me?

thx
druckgott

Hey druckgott,

The current release of the library doesn't work with MX-28, however he does have a new version that works that he hasn't released.

I would email Pablo Gindel and ask him if he could send you a newer version.

When I find time, I will translate the code into english and make a video tutorial so the learning curve for manipulating Dynamixels with Arduino is less steep.

Goodluck!

-Alonso

Hi Flex

Here's a project that seems to have a library for the MX-28

http://code.google.com/p/slide-33/downloads/list

See the file list for: Dynamixel_Serial - V2.0.zip

aus_arduino:
Hi Flex

Here's a project that seems to have a library for the MX-28

Google Code Archive - Long-term storage for Google Code Project Hosting.

See the file list for: Dynamixel_Serial - V2.0.zi

thx now its running.

aus_arduino:
Hi Flex

Here's a project that seems to have a library for the MX-28

Google Code Archive - Long-term storage for Google Code Project Hosting.

See the file list for: Dynamixel_Serial - V2.0.zip

Does this work for Arduino Uno? Does it work even though I don't have a Driver board?

Hallo, as I told I work with the Arduino Uno and the controller Board.

Now I want to Read out the Position:
Position = Dynamixel.readPosition(SERVO_ID);

But this do not work.

And what I also get not working a Serial Output over the serial monitor.

I always geht Chars from the Servo comands I think and between this I get some Serial Informations.

But if I use Serial Print the Servo do not move anymore:

#include <Dynamixel_Serial.h>       // Library needed to control Dynamixal servo


int Temperature,Voltage,Position;  

#define SERVO_ID 0x01               // ID of which we will set Dynamixel too 
#define SERVO_ControlPin 0x10       // Control pin of buffer chip, NOTE: this does not matter becasue we are not using a half to full contorl buffer.
#define SERVO_SET_Baudrate 57600    // Baud rate speed which the Dynamixel will be set too (57600)
#define LED13 0x0D                  // Pin of Visual indication for runing "heart beat" using onboard LED
#define TX_DEALY 2000               // in uSec
#define CW_LIMIT_ANGLE 0x001        // lowest clockwise angle is 1, as when set to 0 it set servo to wheel mode
#define CCW_LIMIT_ANGLE 0xFFF  // Highest anit-clockwise angle is 0XFFF, as when set to 0 it set servo to wheel mode

void setup(){

 delay(1000);                                                           // Give time for Dynamixel to start on power-up

/*Dynamixel.setTempLimit(1,80); // Set Max Temperature to 80 Celcius
Dynamixel.setVoltageLimit(1,65,160); // Set Operating Voltage from 6.5v to 16v
Dynamixel.setMaxTorque(1,1023); // 50% of Torque
Dynamixel.setSRL(1,2); // Set the SRL to Return All
Dynamixel.setTempLimit(2,80); // Set Max Temperature to 80 Celcius
Dynamixel.setVoltageLimit(2,65,160); // Set Operating Voltage from 6.5v to 16v
Dynamixel.setMaxTorque(2,1023); // 50% of Torque
Dynamixel.setSRL(2,2); // Set the SRL to Return All
*/
Dynamixel.begin(SERVO_SET_Baudrate, SERVO_ControlPin, TX_DEALY);        // We now need to set Ardiuno to the new Baudrate speed 
Dynamixel.setMode(SERVO_ID, SERVO, CW_LIMIT_ANGLE, CCW_LIMIT_ANGLE);    // set mode to SERVO and set angle limits

Serial.begin(9600); // Serial speed for PC
mySerial.println("Finish Servo");
//Dynamixel.setPID(Servo_ID, P_Gain, I_Gain, D_Gain)
}


void loop(){
  
Temperature = Dynamixel.readTemperature(SERVO_ID); // Request and Print the Temperature
Serial.print("AX2 *** Temperature: "); // Print the variables in the Serial Monitor
Serial.println(Temperature);
Position = Dynamixel.readPosition(SERVO_ID); // Request and Print the Posit
Serial.println(Position);

Dynamixel.ledState(SERVO_ID, OFF);


  Dynamixel.servo(SERVO_ID,0,0x100);   // Move servo to angle 1(0.088 degree) at speed 100

  delay(1000); 
 
 Dynamixel.ledState(SERVO_ID, ON);
 
   Dynamixel.servo(SERVO_ID,4000,0x3FF);  //  Move servo to max angle at max spe
  delay(1000);

}

thx
druckgott

can nobody help me

alegiaco:
The best library for the Dynamixel is Arduino y Dynamixel AX-12.
It works very very well.

Hi I have now connectet it like in this blog, but do not work for me:

can anybody help me?

thx
druckgott

Hi people.

All you have to do to use the MX-28T is to download this:

http://www.pablogindel.com/images/ax12v231.rar

Regards,
P.G.