How do you change the velocity of the Dynamixel XL-320 Motors using DynamixelSDK?

13 views (last 30 days)
On the ROBOTIS e-manual, they provide examples of how to change the motor position by writing a raw position value to the goal position register. They did not provide any examples of changing the velocity of the motors but my thoughts were that it would be a similar process to changing the goal position by writing a velocity value to the moving speed address (32), causing the speed to change. Below I have provided the write command I used:
write4ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_MOVING_VELOCITY, typecast(uint32(dxl_goal_velocity), 'uint32'));
Port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_MOVING_VELOCITY, and dxl_goal_velocity were all initialized before this command and before torque enable. I set dxl_goal_velocity to 100 as it can take on values 0-2047. I wrote this command before I changed the motor position, but the motor moved at the same speed it originally moved. I also tried reading the present position of the motor by using:
dxl_present_speed = read4ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_PRESENT_VELOCITY)
where the ADDR_PRO_PRESENT_VELOCITY was initialized to 39(the present speed address). It produced read data, but all of the values were out of range. If someone could help me figure out how to achieve a change in velocity using MATLAB, I would greatly appreciate it.
  1 Comment
Muhammad Bin Shamsudin
Muhammad Bin Shamsudin on 18 Oct 2022
Hi Danny, I am also trying to figure out on how to change the velocity for dynamixel motor but for AX12A. Do you happen to solve this problem? Could you share with me the code lines for velocity control? Thank you in advance!

Sign in to comment.

Answers (1)

Abhishek Chakram
Abhishek Chakram on 14 Feb 2024
Hi Danny Bartlett,
To change the velocity of a Dynamixel motor using the “Dynamixel SDK” in MATLAB, it is essential to ensure that you are using the correct address and data length for the velocity register according to your specific Dynamixel model. Since you mentioned using a 4-byte write command, I'm assuming you are working with a model that uses the Dynamixel Protocol 2.0, such as the Dynamixel X-series or the Dynamixel PRO series.
Here is an example of how to change the velocity:
% Set the goal velocity
dxl_goal_velocity = 100; % Example goal velocity value
write4ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_GOAL_VELOCITY, typecast(int32(dxl_goal_velocity), 'uint32'));
% Check for communication errors
dxl_comm_result = getLastTxRxResult(port_num, PROTOCOL_VERSION);
dxl_error = getLastRxPacketError(port_num, PROTOCOL_VERSION);
if dxl_comm_result ~= COMM_SUCCESS
fprintf('%s\n', getTxRxResult(PROTOCOL_VERSION, dxl_comm_result));
elseif dxl_error ~= 0
fprintf('%s\n', getRxPacketError(PROTOCOL_VERSION, dxl_error));
end
% Read present velocity
dxl_present_speed = read4ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_PRESENT_VELOCITY);
% Check for communication errors after reading
dxl_comm_result = getLastTxRxResult(port_num, PROTOCOL_VERSION);
dxl_error = getLastRxPacketError(port_num, PROTOCOL_VERSION);
if dxl_comm_result ~= COMM_SUCCESS
fprintf('%s\n', getTxRxResult(PROTOCOL_VERSION, dxl_comm_result));
elseif dxl_error ~= 0
fprintf('%s\n', getRxPacketError(PROTOCOL_VERSION, dxl_error));
else
% Assuming the present speed is a 4-byte value
fprintf('Present Speed: %d\n', typecast(uint32(dxl_present_speed), 'int32'));
end
Please replace “ADDR_PRO_GOAL_VELOCITY” and “ADDR_PRO_PRESENT_VELOCITY” with the correct addresses for your specific Dynamixel model.
Best Regards,
Abhishek Chakram

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!