Monday, 7 March 2011

Simple Dynamixel / Matlab Example Code

Recently I started working with a some Dynamixel RX-28 servos from Robotis. Unlike standard hobby servos, these actuators can provide position, current and velocity feedback and also have various modes of control, including compliance. They also work on a RX485 network, meaning that they can be chained together. These features make the servos a popular choice for building small humanoids, such as the Bioloid (also from Robotis).

Though a MATLAB API is available, I found the on-line examples lacking somewhat, especially when all I wanted to do was drive the servo and log its position. The following code does just that, moving the servo 90 degrees clockwise and anti-clockwise, then displaying a log of the 'present position' and 'moving' registers from the servo EEPROM.
The 'Moving' register is set to '1' when the servo is in motion. This is a bit buggy though as you need a delay in the code for it to read anything other than '1' and it doesn't exactly stop on time. Matlab isn't hard real-time so this pause seems to affect the data logging somewhat (the motion is actually really smooth, unlike what is shown above). Take the 'pause(0.01) out of the code below and you'll see what I mean

Note that you'll need to download and register the dynamixel API with Matlab before using this code.
Here are the instruction from ROBOTIS:
These instructions from Agave Robotics are also useful
Note that I had to change the 'open  device' code from the examples given above. They just wouldn't work!

I hope this is useful to someone, I spent some time searching for an example like this but couldn't find one. Of course the dynamixel servos can do much more than this but this is a nice place to start.

The source code can be downloaded from Google Docs here.


Lazza said...

This is a great example of the capability of the Dynamixel actuators. I am currently doing an undergraduate dissertation with the use of these actuators for a haptic control system of a robotic arm.

Ad Spiers said...

Sounds interesting. You're not based in Reading are you? I hear they are doing similar work there.