I chose to incorporate Dynamixel AX-12A motors in a project and had to create a library for them, prompting me to share my findings.
Even though it is pricier, this motor offers a few benefits compared to the TowerPro motors that are more frequently seen.
Primarily, the Dynamixel motors are more powerful, can be connected in a daisy chain, and feature a sturdy control system that provides feedback on factors like position, temperature, and torque.
Step 1: Manuals
There are two distinct guides available for the AX-12A motors online. This 2006 guide is slightly out of date: certain spec values like operating voltage range are outdated, and initial values in the Control Table may be incorrect, but it provides comprehensive information on sending instructions to the motor and interpreting its feedback.
This alternative guide provides precise data on specifications and starting points but does not include all the specifics of the communication protocol.
It was useful to have both of them.
Step 2: Other Resources
These were invaluable while learning about these motors:
Step 3: The Joy of UART Communication
Unlike other servo motors, the Dynamixel does not react to PWM signals. Instead, it requires a more complex protocol for sending and receiving data to and from its memory. The communication takes place through a half-duplex UART port, with a single wire used for both transmitting and receiving.
This indicates the requirement of constructing a compact circuit that transforms full-duplex to half-duplex, in case we intend to utilize a Raspberry Pi or an Arduino (or any other microcontroller with a full-duplex serial interface) for managing these motors.
The AX-12 manual from 2006 recommends this circuit:
It is essentially a tri-state buffering process for managing bus arbitration; it guarantees that the bus is not linked to the Rx pin while the controller is sending data and that it is not controlled by the Tx pin while awaiting data reception.
I decided to switch to a 74LS241, following the suggestion provided, in order to take advantage of its internal feature to enable half of its buffers with either high or low signals, eliminating the need for a 74HC126 and a 74HC04.
The schematic for the circuit I ended up using, and a simple PCB design are up in 123D.circuits.
Step 4: Configure Raspberry Pi
From oppedijk blog:
Set configuration parameters in /boot/config.txt:
init_uart_clock=16000000
sudo stty -F /dev/ttyAMA0 1000000
Edit /boot/cmdline.txt and remove all options mentioning ttyAMA0.
Edit /etc/inittab and comment out any lines mentioning ttyAMA0, especially the getty one.
Reboot
UPDATE for Raspbian Jessy:
Follow this thread on SO for disabling tty terminal and getting control of ttyAMA.
Step 5: Libs and Libs
I first tested the circuit using an Arduino and the library found here.
But, because I eventually needed to connect my project to the internet, and keep track of its state between reboots, I decided to use a Raspberry Pi as the controller instead.
I started testing this library for controlling the motors, but then decide to re-write it to make it more object-oriented, and to have some of the same capabilities as the Arduino library.
The resulting AX-12A Python library for Raspberry Pi is on github.
Turns out the timing between sending a command and getting its response is pretty critical and sensitive.
I dedicated time to adjusting delay values in order to reduce dropped commands, but I believe there may still be issues with this part of the library. I am uncertain about why certain commands do not reach the motors, possibly due to the timing of the Rx/Tx signal. However, I can reduce missed commands by detecting a timeout exception in the Python serial library and resending the command.
Step 6: More Links
Some more information about the overall project, and a list of references.
Source: How to drive Dynamixel AX-12A servos (with a RaspberryPi)