Hello, I am using three AX-12A servo motors in my project. However, I am not sure how to control it by using Dynamixel shield and the example code. I can confirm that Dynamixel Wizard 2.0 can scan and find all three motors. And I can control each of them by using the example code (Examples—>DYNAMIXELShield—>Basic—>Position Mode). However, I am not sure how to control them together. Could you please give me some advice?
Thank you for your help. But I am still confused about the sync_read_write_position example code.
This example is designed for DYNAMIXEL X series and I am not sure that if I can use for AX series.
For example, from the attached screenshot, I am not sure how to change the highlighted code suite for the AX-12A. Also, can I ask what is the difference between the BROADCAST_ID and DXL_ID_CNT? Why the DXL_ID_CNT is used in the dxl.torqueOff and dxl.setOperatingMode but BROADCAST_ID is used in the dxl.torqueOn?
BROADCAST_ID is a special DXL ID which applies to ALL DXLs in your robot at once. So dxl.torqueOn(254) is equivalent to 3 commands dxl.torqueOn(1); dxl.torqueOn(2); dxl.torqueOn(3); (when applied to your case).
DXL_ID_CNT is the number of DXLs in your robot which is 3 in your case, and you already got that correctly. Your array DXL_ID_LIST[] is also set correctly.
For the actual addresses of Parameters Goal Position and Present Position, you need to read up on the ROBOTIS e-manual information specifically for the AX-12A:
Where you can see that Goal Position is at address 30, and its data length is only 2 bytes (not 4 bytes like for X series). For Present Position, its address is 36, data length is 2 bytes.
The possible Goal Position values for the AX-12A can only be between 0 and 1023.
The details of the actual Sync Read/Write packet set up should not have to be modified.
So I will have a try that change the int32_t goal_position[2] = {1024, 2048}; to int32_t goal_position[2] = {0,1023}; and leave other details as the original. See if that works.
Thank you for the help. I have tried the code you provided. I opened a blank sketch and copied the code. It did not work at the beginning. And I tried to change the library from Dynamixel2Arduino to DynamixelShield. Then the code works. But the code is to sync the servo motors to move in same angle, what if I need to request different angles for each motor, how should I change the code?
That code was for my own board so that it has a different DXL_DIR_PIN than yours, I am sure. Which controller are you using? You can try this free Kindle sample to learn more about Arduino and ROBOTIS hardware:
Right now, the DXLs Goal Positions are defined by the array goal_position[2] = {450, 550}; . Whereas, goal_position[0] is the first and common GP of both DXLs (=450) and goal_position[1] is the second and common GP of both DXLs (=550). So you will have to “rethink” the design of this goal_position array, and to make goal_position[0] points to DXL 1 only and goal_position[1] points to DXL 2 only, etc…
See the following post, where I used a different kind of Sync Read Write packet (deprecated by ROBOTIS, but I like it better) where every time that Function loop() iterates, it chooses a random GP value for each DXL.
goal_position[i] = (uint16_t) random(0,1023); // when applied to your set up with AX12s
You should be able to modify that approach for your needs.