Thursday, August 16, 2018

How to Read Multiple (or single) Dynamixel AX12 Position value using Dynamixel SDK (Python)

Why is reading status important?


Every Robotis Dynamixel servo motors has feedback feature. We can read its status data such as current angle, speed or temperature. When you make a robot and teach them how to move, we have to give them a number of sets of angle data for each motors. In order to make the motion set, we have to know current angle value for each. What if there is no way to read their angle? We may have to calculate or measure many times. It is not efficient.
On the other hand, Robotis Dynamixel returns when they are asked to return their status. All we have to do is to save all the angle values to a proper storage. In this way, we can capture the motion set. Normally, small humanoid robot moves based on the motions on the timely based. It is really similar to a way to make an animation. A lot of scenes are changed in a specific time period. Like this method, we can teach our robots how to move.

Let's Try!

Preparation

sample code

Download the file here "read_AX12.ph"
I modified the sample code for Dynamixel AX12.  put the file into the folder .\python\tests\protocol1_0\

part list 

2 * AX12 (ID: 1, 2 | Baudrate 1)
1 * USB2DYNAMIXEL
1 * SMPS2Dynamixel

ID Setting

You need to prepare 2 * AX12, Change their ID as '1' for one, '2' for the other. 
The simplest way to change ID is to use Dynamixel Wizard with USB2Dynamixel. 

How I did it (strategy)

Open a proper example

I opened SDK example named "read_write.py". The file was for MX series. In order to use AX series, I needed to change some detail. 

Change Serial Com Port Information

Of course I need to change Com Port number and the baudrate number. I already set up the AX12's baudrate as 1000000. My pc allocated the USB2Dynamixel to COM4.




Check the instruction table

Because I want to read "present position" of the motors, I checked which number is for the present position. The address is 36. So, I am going to request the AX12 to return value from address 36. If everything is good, the AX12 will dispatch value from its address 36 and return them to me. Ass you can see, the size of value is 2 byte. So, consequently, we need to request AX12 to dispatch 2 bytes from address 36. 



The request look like this.
"Hey AX12 ID number 1, read 2 bytes of data from your address table 36. "
Then AX12 ID number 1 will return present position. When the packet received well, I will request the other AX12 (ID number 2) to dispatch the data in the same way.
"Hey AX12 ID number 2, read 2 bytes of data from your address table 36."
The, the AX12 will return present position value.

In this way, there must be time difference between motors because the reading moment time must be different. Robotis gives a synchronized method named Bulk Read. Unfortunately, AX12 doesn't have Bulk Read feature.

Result 

I am able to read motor's position more than 2 motors at the same time (actually, there is time difference though). 



Faced a problem

I faced a big problem. There are so big time delay. It takes at least 15 ms for reading. Because I will make a robot with 21 motors, it will take 15 * 21 = 315 ms for every single frame which means 3 fps (frames per second). That is too low. I need at least 24 fps. I tried to figure out and found a solution at last. I will post it later.
https://eunchanpark.blogspot.com/2018/08/how-to-reduce-serial-communication.html

No comments:

Post a Comment

URDF Link origin test