Import the predefined trajectory for Dynamixel XL430

Issue:

I am trying to build a robot leg with two Dynamixel XL430 as hip motor and knee motor. Currently, the motions of two motors have been designed and calculated in matlab and generated as txt file. I was wondering if I can ask the motor to read the files and act?


DYNAMIXEL Servo:

xl430-w250-t


DYNAMIXEL Controller:

open rb 150


Software Interface:

arduino

There isn’t a way to get the DYNAMIXELs to read the motors directly, but you could certainly write a program to read them and have the motors complete the trajectories.

However, I think it would probably be simpler to use the official MATLAB SDK to control the servos.

Dear Jonathon,

Hope this massage finds you well.

I have followed your suggestion to setup the Dynamixel SDK into Matlab. I have followed the instructions to set path for the Dynamixel SDK. However, I am facing the issue with matlab as the picture shown below. Could you please help me to solve this?

image
The path set shown below
image

I am using XL430-W250 motor and Open RB150 to communicate. I am also not sure how to set the ADDR_GOAL_POSITION and ADDR_PRESENT_POSITION
image

Is there anything I need to change?
image

Hi Jonathon,

I have solved the issue. I installed the MinGW-w64 compiler and set the control table. Thank you for your help.

I’m glad you were able to get this working! I hope the rest of your project proceeds well.

Dear Jonathon,

Hope this email finds you well.

I have used the Dynamixel SDK in matlab to control the XL430-W250. The examples work as I expected. Then I tried to develop my own code by referring the example read and write. I have pasted the code below. I used readmatrix to read the xlsx files and used write4ByteTxRx to import the trajectory.

write4ByteTxRx

The code is attached below:

clc;
clear all;

% Library selection based on operating system
lib_name = '';
if strcmp(computer, 'PCWIN')
    lib_name = 'dxl_x86_c';
elseif strcmp(computer, 'PCWIN64')
    lib_name = 'dxl_x64_c';
elseif strcmp(computer, 'GLNX86')
    lib_name = 'libdxl_x86_c';
elseif strcmp(computer, 'GLNXA64')
    lib_name = 'libdxl_x64_c';
elseif strcmp(computer, 'MACI64')
    lib_name = 'libdxl_mac_c';
end

% Load Libraries
if ~libisloaded(lib_name)
    [notfound, warnings] = loadlibrary(lib_name, 'dynamixel_sdk.h', 'addheader', 'port_handler.h', 'addheader', 'packet_handler.h');
end

% Define control table addresses and settings
ADDR_PRO_TORQUE_ENABLE = 64;
ADDR_PRO_GOAL_POSITION = 116;
ADDR_PRO_PRESENT_POSITION = 132;
PROTOCOL_VERSION = 2.0;
DXLRightHip_ID = 1;
DXLRightKnee_ID = 2;
BAUDRATE = 57600;
DEVICENAME = 'COM3';
TORQUE_ENABLE = 1;
TORQUE_DISABLE = 0;
DXL_ZERO_POSITION_VALUE = 2048;    % 180 Degree
DXLRightHip_INITIAL_POSITION_VALUE = 2446;  % 215 Degree
DXL_MOVING_STATUS_THRESHOLD = 10;

% Initialize PortHandler and PacketHandler
port_num = portHandler(DEVICENAME);
packetHandler();

% Open port
if ~openPort(port_num)
    fprintf('Failed to open the port!\n');
    return;
end

% Set port baud rate
if ~setBaudRate(port_num, BAUDRATE)
    fprintf('Failed to set the baud rate!\n');
    closePort(port_num);
    return;
end

% Enable torque for both motors
write1ByteTxRx(port_num, PROTOCOL_VERSION, DXLRightHip_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE);
write1ByteTxRx(port_num, PROTOCOL_VERSION, DXLRightKnee_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE);

% Set initial position and wait 2 seconds
write4ByteTxRx(port_num, PROTOCOL_VERSION, DXLRightHip_ID, ADDR_PRO_GOAL_POSITION, DXL_ZERO_POSITION_VALUE);
write4ByteTxRx(port_num, PROTOCOL_VERSION, DXLRightKnee_ID, ADDR_PRO_GOAL_POSITION, DXL_ZERO_POSITION_VALUE);
pause(2);  % Wait for 2 seconds

% Move DXLRightHip_ID to its initial position
write4ByteTxRx(port_num, PROTOCOL_VERSION, DXLRightHip_ID, ADDR_PRO_GOAL_POSITION, DXLRightHip_INITIAL_POSITION_VALUE);

% Record start time
start_time = tic;

% Prepare the figures for real-time plotting
figure1 = figure;
hold on;
grid on;
xlabel('Time (s)');
ylabel('Position (Degrees)');
title('Real-Time Right Hip Position Trajectory');
h1 = animatedline('Color', 'b', 'Marker', 'o');

figure2 = figure;
hold on;
grid on;
xlabel('Time (s)');
ylabel('Position (Degrees)');
title('Real-Time Right Knee Position Trajectory');
h2 = animatedline('Color', 'r', 'Marker', 'o');

% Load trajectories from files
right_hip_traj = readmatrix('Matlab\TRAJECTORY\Trajectory Data\9.15\txt\DXL\Left_theta_h dxl.txt');
right_knee_traj = readmatrix('Matlab\TRAJECTORY\Trajectory Data\9.15\txt\DXL\Left_theta_k dxl.txt');


disp('Right Hip Trajectory:');
disp(right_hip_traj);
disp('Right Knee Trajectory:');
disp(right_knee_traj);

% Perform motion as per the trajectory files
for i = 1:length(right_hip_traj)
    current_time = toc(start_time);  % Calculate elapsed time since start
    write4ByteTxRx(port_num, PROTOCOL_VERSION, DXLRightHip_ID, ADDR_PRO_GOAL_POSITION, right_hip_traj(i));
    write4ByteTxRx(port_num, PROTOCOL_VERSION, DXLRightKnee_ID, ADDR_PRO_GOAL_POSITION, right_knee_traj(i));
    dxl1_present_position = read4ByteTxRx(port_num, PROTOCOL_VERSION, DXLRightHip_ID, ADDR_PRO_PRESENT_POSITION);
    dxl2_present_position = read4ByteTxRx(port_num, PROTOCOL_VERSION, DXLRightKnee_ID, ADDR_PRO_PRESENT_POSITION);
    addpoints(h1, current_time, dxl1_present_position);
    addpoints(h2, current_time, dxl2_present_position);
    drawnow;
    pause(0.1); % Adjust timing based on your needs
end

% Disable torque for safety
write1ByteTxRx(port_num, PROTOCOL_VERSION, DXLRightHip_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE);
write1ByteTxRx(port_num, PROTOCOL_VERSION, DXLRightKnee_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE);

% Close port and clean up
closePort(port_num);
unloadlibrary(lib_name);
clear; % Clear MATLAB workspace to clean up

However, the motors can not read the files properly. The xlsx datas from 0 second to 15 second and the command below shows the time starts from 0s to 0.015seconds.

disp('Right Hip Trajectory:');
disp(right_hip_traj);
disp('Right Knee Trajectory:');
disp(right_knee_traj);

I am not sure if that is a matlab issue or it is a motor issue. Could you please help me to check?

I have also attached the trajectories here.

Right_theta_h dxl.xlsx (82.9 KB)
Right_theta_k dxl.xlsx (74.8 KB)