Simple Operation of the Dynamixel AX-12A Servo

Hello Everyone!

I'm very new to this world of arduinos, but am very excited their potential...even if I don't quite understand everything I'm doing. For the project I'm working on right now, I want to rotate the Dynamixel AX-12A Servo either between various set positions or in a smooth 180 degree sweep. I chose this servo because it has 1024 discrete locations it can be in (giving me the precision I need) as well as having active feedback so that it knows that it's in the position it needs to be in.

My experience with servos thus far has only been with very basic devices, such as the HXT900 where you plug the anode and ground into either the arduino's power supply or an external power source and the yellow data wire into one of the arduino's pwm ports. Add simple code and the servo will move around as desired.

I was hoping to do the same sort of thing with the AX-12A, but it turns out it isn't so simple. According to various sources that I’ve found, “you must convert the full-duplex signal coming from the Arduino RX/TX pins to the half-duplex required by the Dynamixel servos”. By the same sources, it seems that I can do this via the Tri-state Buffer 74LS241N. Is this true?

Also, another problem may be that I’m using the Arduino UNO, which only has one serial port, meaning “we can send data out to the servos, but then we lose our serial port. Typically we need that to at least send debugging info back to our computer”. How big of an issue is this for the simple operation I want out of the servo? Does it mean I lose the ability of the servo checking to make sure it’s in the correct spot? This video seems to be operating two servos using just the Tri-state buffer and the MEGA, which has more serial ports. Is that necessary?

In short, will I be able to move the servo around using an Arduino UNO and the 74LS241N following a wiring scheme outlined here or here? Will I need to get myself a MEGA to get more serial ports? In case it’s relevant, I’m also planning on running five LEDs on the board (that won’t be on at the same time), a simple servo (that’ll have an external power supply and can operate form one pwm port), and a photodetector connected to an analog in.

I’d be grateful for even the smallest bit of help :slight_smile:

Use the forum search box in the upper right of this page and search for Dynamixel for previous discussions.

You could use a software serial with the Dynamixel servos but a software serial presents additional problems.

The Dynamixel protocol is a nice one to learn to use. As with many non-ASCII protocols, the length of the message is part of the message header. This extra complication comes with the bonus of being able to send data with a fewer number of bytes than would be required with an ASCII based protocol.

If you were to use a software serial, you might be able to get around the need for a tri-state buffer. You could manually change the I/O pin from an output to an input. This would likely require modifying the soft serial library. I'd be surprised if someone hasn't already made a half-duplex software serial.

Heck the Meccanoid library includes a 1200bps half duplex serial. I doubt you'd want to use the Meccanoid library but I bet there's a decent half-duplex library somewhere.

Edit: A Google search of "Arduino half-duplex software serial" brought up a lot of interesting links.

Thank you both for your responses.

The tri-state buffer is arriving tomorrow, so I'll try that out and report the results. If that doesn't work, I'll look into using either this or this solution, both of which seem to be able to get over the half-duplex, full-duplex problem.

I suppose at this point my biggest problem is not knowing what questions to ask. For example, my previous research was limited by looking only into the AX-12a servo, and not the Dynamixel motors in general. Hopefully one of the above methods will work out.

Well, I tried it with the tri-state buffer and had mixed results.

I followed the instructions outlined in Savage Electronics, with the wiring below:


I used a 12V external power input to the UNO instead of a 9.6 V since I didn't have access to the latter.

I added the libraries I needed to the appropriate Arduino folder, and tried running the code below:

#include <DynamixelSerial.h>

void setup(){
Dynamixel.begin(1000000,2);  // Inicialize the servo at 1Mbps and Pin Control 2
}

void loop(){
Dynamixel.move(1,0);
delay(2000);
Dynamixel.move(1,500);
delay(2000);
Dynamixel.move(1,1000);
delay(2000);
}

My expectation is that it would move to position 0, wait two seconds, move to position 500, wait two seconds, move to position 1000, wait two seconds, then repeat. However, the servo will move to a position, wait there for an unpredictable amount of time, then move to a different position, wait there for a bit, then move again. Minutes can pass between any action happening. Most frustratingly, the specific action of the servo is unrepeatable. The LED next to the "L" is always on, and the TX LED flashes occasionally.

Is it possible that the delay somehow makes the LED off sync with the move functions? I thought that the delay just paused the program and allowed the servo to get to its position before being asked to move somewhere else. In short, I have no idea what is causing the issue.

For your convenience, I've attached the Library Description for the Savage code.

Edit:
To simplify matters, I tried troubleshooting not with the rotation of the motor but instead with the LED on the back. Code is as follows:

#include <DynamixelSerial.h>

void setup(){
Dynamixel.begin(1000000,2);  // Inicialize the servo at 1Mbps and Pin Control 2
}

void loop(){
Dynamixel.ledStatus(1,ON);
delay(100);
Dynamixel.ledStatus(1,OFF);
delay(100);
}

The LED will occasionally turn on and off very regularly, but will also stay on or off for extended lengths of time (~15 seconds). Even when it is regular the switching is closer to 1 sec than 0.1 sec. Could this be a result of a complex library being too computationally heavy for the arduino to keep up? Or maybe the result of the switching performed by the buffer?

Is it impossible to get accurate timings with such a setup?

DynamixelLibrary (English).pdf (389 KB)

1 Mbps seems awfully fast but reading through older forum posts is appears this should be possible.

It's really not a good idea to power the servo from the Arduino's Vin pin. Use a separate power line to the servos so the power doesn't pass through the Arduino. The same goes for the ground. You want the Arduino's ground connected with the servo's ground but you don't want the returning current to pass through the Arduino.

If you've using one power supply for both the Arduino and the servo, branch both the positive voltage and the ground before it enters the Arduino.

I don't know if you have a power supply issue or a communication problem.

I swapped out the 12V external power through the arduino for a 9V external battery power. The battery only feeds the servo, and the ground is connected to the arduino. The arduino itself is now just powered via a USB connection to my computer.

The above changes didn't seem to help anything. Both the LED blinking code and the rotating code give erratic results. For clarity, I decided to time a small section of the LED behavior, marking when it turns on and off. Result is below and units are in seconds.

Start OFF
[4.49, 2.26, 0.33, 1.96, 2.27, 0.26, 7.65]

Obviously, testing like that is limited by my reflexes, but I think it gives a reasonable idea of the LED behavior.

BlackBoxTechnologies:
I swapped out the 12V external power through the arduino for a 9V external battery power.

This isn't a smoke alarm battery is it? If so, NO!

Dynamixels pull a lot of current. You need a battery pack capable of supplying MUCH more current than a 9V battery is capable of supplying.

Don't just tell us the voltage of the supply. It's often more important to know how much current the supply can provide so make sure and include information about the current capability of your power supplies.

Well, I got it to work. I hadn't connected the V_ACC in the tri-state buffer. I feel pretty silly for not realizing that, but those feelings are overwhelmed by the relief that it's working.

Thank you zoomkat and DuaneDegn for helping me out!

Hi,

I recently wrote a dedicated library to drive Dynamixel Servo, with no extra hardware requirement.
Take a look at this post :

http://forum.arduino.cc/index.php?topic=384104.0

Hope it will help

Dear all,

I need to operate 5 dynamixel Ax 12-A servo serially. Can any one share the code for it using dinamixel library?

I implemented the recommended half-duplex circuit using a 74HC04 and 74HC126 as shown in the AX-12 documentation. I'm able to successfully control my AX-12 servos (with full 2-way communication) using the hardware serial port and the standard Arduino Serial library.

I've been running the serial port at the default 1M baud and have error free transmission and reply. I have not seen a single transmission or receive error in several days of testing (and yes I do check the packet checksum to detect any errors). Looks like the Arduino can handle 1M baud with no trouble.