Arduino Forum

Using Arduino => Motors, Mechanics, Power and CNC => Topic started by: Flex on Jul 26, 2012, 06:27 pm

Title: Dynamixel Servo Library
Post by: Flex on Jul 26, 2012, 06:27 pm
Hello All,

I have recently been playing with the new Dynamixel MX-28T Servos http://www.robotis.com/xe/dynamixel_en (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/ (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:

Code: [Select]

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!
Title: Re: Dynamixel Servo Library
Post by: Jujo on Jul 30, 2012, 02:39 pm
The best library for the Dynamixel is http://savageelectronics.blogspot.it/2011/01/arduino-y-dynamixel-ax-12.html (http://savageelectronics.blogspot.it/2011/01/arduino-y-dynamixel-ax-12.html).
It works very very well.
Title: Re: Dynamixel Servo Library
Post by: Flex on Aug 16, 2012, 04:33 pm
The only issue with the Savage Electronics library is that it requires extra hardware to work.
The one I recommended doesn't need anything.
Title: Re: Dynamixel Servo Library
Post by: Amartin2 on Sep 23, 2012, 10:41 am
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

Title: Re: Dynamixel Servo Library
Post by: Amartin2 on Sep 23, 2012, 10:56 pm
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
Title: Re: Dynamixel Servo Library
Post by: Jujo on Sep 28, 2012, 12:13 pm

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.  :smiley-mr-green:
Title: Re: Dynamixel Servo Library
Post by: MohitJindal on Sep 28, 2012, 02:18 pm
Hi,
I am wondering, anyone tried to write the source code firmware in c of Mx28 ?
Title: Re: Dynamixel Servo Library
Post by: Flex on Oct 29, 2012, 03:26 pm

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.
Title: Re: Dynamixel Servo Library
Post by: beepboop on Nov 16, 2012, 07:09 am
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.
Title: Re: Dynamixel Servo Library
Post by: Amartin2 on Nov 16, 2012, 06:40 pm
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 (http://www.pablogindel.com/2010/01/biblioteca-de-arduino-para-ax-12) 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
Title: Re: Dynamixel Servo Library
Post by: beepboop on Nov 19, 2012, 03:32 am
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.
Title: Re: Dynamixel Servo Library
Post by: druckgott on Nov 19, 2012, 06:25 pm
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
Title: Re: Dynamixel Servo Library
Post by: Amartin2 on Nov 19, 2012, 07:22 pm
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
Title: Re: Dynamixel Servo Library
Post by: aus_arduino on Nov 20, 2012, 03:06 am
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
Title: Re: Dynamixel Servo Library
Post by: druckgott on Nov 20, 2012, 06:01 pm

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.zi


thx now its running.
Title: Re: Dynamixel Servo Library
Post by: beepboop on Nov 22, 2012, 01:40 am

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



Does this work for Arduino Uno? Does it work even though I don't have a Driver board?
Title: Re: Dynamixel Servo Library
Post by: druckgott on Nov 22, 2012, 08:40 pm
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:

Code: [Select]

#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
Title: Re: Dynamixel Servo Library
Post by: druckgott on Nov 27, 2012, 08:05 pm
can nobody help me
Title: Re: Dynamixel Servo Library
Post by: druckgott on Dec 17, 2012, 06:59 pm

The best library for the Dynamixel is http://savageelectronics.blogspot.it/2011/01/arduino-y-dynamixel-ax-12.html (http://savageelectronics.blogspot.it/2011/01/arduino-y-dynamixel-ax-12.html).
It works very very well.


Hi I have now connectet it like in this blog, but do not work for me:
http://postimage.org/image/mgryg3i6t/

can anybody help me?

thx
druckgott
Title: Re: Dynamixel Servo Library
Post by: pabloxid on Dec 26, 2012, 06:17 pm
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.
Title: Re: Dynamixel Servo Library
Post by: JF107 on Dec 28, 2012, 02:45 am
Hello,

I downloaded the files (ax12v231.rar) and put it in the library folder and I also modified the HardwareSerial.ccp but i get the message while compiling:

core.a(HardwareSerial.cpp.o): In function `__vector_18':
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/HardwareSerial.cpp:100: multiple definition of `__vector_18'
ax12v231/ax12.cpp.o:/Users/.../Documents/Arduino/libraries/ax12v231/ax12.cpp:108: first defined here

Any idea what I did wrong ?

thanks

Joop
Title: Re: Dynamixel Servo Library
Post by: pabloxid on Dec 28, 2012, 07:14 am
The example that comes with the library, is for the Mega or Mega2560. If your board has a single serial port, comment out all lines that have the word "Serial".
Title: Re: Dynamixel Servo Library
Post by: JF107 on Dec 28, 2012, 09:39 pm
Thanks for your fast reply! Now the compiling worked, but my MX28 isnĀ“t moving. Only a red light is flashing once while
connecting. I might have bricked it before due to wrong wiring, but i will order an usb 2 ttl adapter for testing the servo...
Title: Re: Dynamixel Servo Library
Post by: pabloxid on Dec 29, 2012, 07:50 am
90% of the problems I've seen with Dynamixel are due to the power supply. I use a 12V / 4A power supply, which is, in fact, that comes with the Bioloid kit.
Title: Re: Dynamixel Servo Library(Position command)
Post by: ephesus on Mar 20, 2013, 03:34 am
Hi guys, I'm using a servo dynamixel MX-64T and I'm having a problem in feedback position command or reading position and temperature.So far its not working because I'm getting weird answers.I'm using the library  Dynamixel_Serial - V2.0. I have connected using a Pololu Orangutan B-328 robot controller with connection to TX and RX.Im wondering whether its a software or hardware related issue and how to get proper feedback answers.Do need your help guys,thanks.
Title: Re: Dynamixel Servo Library
Post by: ChrisBindi on Feb 26, 2014, 09:49 am
Hi,

I tried to open the homepage of Pablo Gindel  but there was an error and nothing happend. www.pablogindel.com/

Can u check if it works, because i need the library of this guy.

Thank u very much for your help.
Title: Re: Dynamixel Servo Library
Post by: cesare76m on Feb 10, 2015, 05:31 pm
i'm using an ax12 dynamixel servomotor with Arduino uno

Hi, excuse me for intrusion, i should have feedback about current, so to define a stop for the motor like switch of end tracking. Excuse for my english..