View Full Version : Need matlab code for negative rotation of Dynamixel AX-12+

03-10-2010, 05:13 AM
Hello everyone,

I'm currently working on PID control of Dynamixel AX-12+ servos. Things are going fairly well at the moment except that I seem to only be able to command the servos to rotate in ONE DIRECTION ONLY.

I'm programming the servos using Matlab and interfaced using USB2Dynamixel. The matlab code for controlling the speed of the servos are as follows:

calllib('dynamixel','dxl_write_word', id, address, required_speed)

where address = 32 (from control table, note that this refers to the lower byte only?)

I try to set the required speed to be of maximum magnitude i.e. 1023; The problem now is setting it to -1023 doesn't get it to rotate in the opposite direction.
(Note: setting the speed to -1023 using Dynamixel Configurator (a separate program) does make it turn in the opposite direction).

Thanks in advance

03-10-2010, 06:39 AM
That's because -1023 is not a valid value. Any negative goal position value entered in the configurator will cause the motor to move to goal position zero.

Check out the following link. DualDynamixel180Phase allows you to control 2 AX-12s in opposite directions offset by phase. For example to control 2 dynamixels moving in opposite directions use. DualDynamixel180Phase(id, theta, speed)

Simply type the following in the command window after adding the files to Matlab.

DualDynamixel180Phase(id, sin(30), 512)Where id is an array of ids, sine(30) is the degrees to move the Dyanmixels from center (512) and speed is how fast (0 to 1023).

To move one you could actually do this...


DualDynamixel180Phase(id, sin(30), 512) There's another other SyncWrite file in the download provided that demos hows to build a SyncWrite command in Matlab.

I'm not sure how you plan to implement PID control, I need more information. The AX-12 already has a control system and the ability to query the control table registers. Error is controlled by the compliance properties.

03-10-2010, 07:21 AM
The AX-12 manual isn't very clear on that specific entry. Use the sign convention as documented in the "Present Load" entry:

bits 0 - 9 : 10 bit value
bit 10 : 0 for CCW, 1 for CW

- Jon

03-10-2010, 07:35 AM
Sorry, read your post wrong. I was thinking goal position. I was helping someone else... and got confused.. old age.

Jon is right, that part of the manual is unclear. You want the section on Goal Speed setting. It's on page 17-18. But that only comes into play in endless turn mode.

03-10-2010, 05:30 PM
Thanks for the replies. I discussed the problem with my project supervisor and from the entry in the manual regarding the goal speed direction, we replaced -1023 with 1023+4*256 = 2047; that seemed to do the trick.

03-11-2010, 06:10 AM
Create a mask 1024 (0x400) and XOR the mask with the speed magnitude. You can change direction while keeping the speed the same. It just flips the 10th bit.

03-12-2010, 01:13 PM
Is it correct to say that a value greater than 2^10 signifies a negative rotation?

03-12-2010, 01:50 PM
No. Only if bit 10 is set which it is not for all values greater than 2^10.

YouTube- Binary Numbers in 60 Seconds