0% found this document useful (0 votes)
5 views4 pages

Attachment GGG

The document outlines a simulation for a Cartesian gantry robot using PID control to move from an initial position to a desired position in 3D space. It defines PID gains, model coefficients, and initializes variables for error calculation and position updates. The simulation visualizes the robot's movement over time, updating its position based on control signals derived from PID calculations.

Uploaded by

ademasfaw222
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Attachment GGG

The document outlines a simulation for a Cartesian gantry robot using PID control to move from an initial position to a desired position in 3D space. It defines PID gains, model coefficients, and initializes variables for error calculation and position updates. The simulation visualizes the robot's movement over time, updating its position based on control signals derived from PID calculations.

Uploaded by

ademasfaw222
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

% Define PID gains for each axis

kp1 = 1;

kp2 = 1;

kp3 = 1;

kd1 = 0.1;

kd2 = 0.1;

kd3 = 0.1;

ki1 = 0.01;

ki2 = 0.01;

ki3 = 0.01;

% Define model coefficients

m1 = 1; % Mass of axis 1

m2 = 1; % Mass of axis 2

m3 = 1; % Mass of axis 3

% Define initial and desired positions

initial_position = [0, 0, 0]; % Initial position of the robot

desired_position = [5, 5, 5]; % Desired position of the robot

% Define timing parameters

dt = 0.01; % Time step

total_time = 10; % Total simulation time

num_steps = total_time / dt; % Number of simulation steps


% Initialize variables

error = zeros(num_steps, 3);

current_position = initial_position; % Start at the initial position

desired_position_matrix = repmat(desired_position, num_steps, 1);

% Initialize PID controller variables

error_sum1 = 0;

error_sum2 = 0;

error_sum3 = 0;

prev_error1 = 0;

prev_error2 = 0;

prev_error3 = 0;

% Create a figure for the 3D animation

figure;

hold on;

title('3D Motion of the Cartesian Gantry Robot');

xlabel('X');

ylabel('Y');

zlabel('Z');

grid on;

axis equal;

view(3); % Set the view to 3D

% Simulate the robot movement using PID control and visualize the motion
for i = 1:num_steps

% Calculate error

error(i, :) = desired_position - current_position;

% Calculate PID control signal for each axis

control_signal1 = kp1*error(i,1) + kd1*(error(i,1)-prev_error1) + ki1*error_sum1;

control_signal2 = kp2*error(i,2) + kd2*(error(i,2)-prev_error2) + ki2*error_sum2;

control_signal3 = kp3*error(i,3) + kd3*(error(i,3)-prev_error3) + ki3*error_sum3;

% Update position using the control signals and model coefficients

acceleration = [control_signal1/m1, control_signal2/m2, control_signal3/m3];

velocity = acceleration * dt;

current_position = current_position + velocity;

% Update PID controller variables

error_sum1 = error_sum1 + error(i,1);

error_sum2 = error_sum2 + error(i,2);

error_sum3 = error_sum3 + error(i,3);

prev_error1 = error(i,1);

prev_error2 = error(i,2);

prev_error3 = error(i,3);

% Update the 3D animation

cla;

plot3(initial_position(1), initial_position(2), initial_position(3), 'ro', 'MarkerSize', 10,


'MarkerFaceColor', 'r');
plot3(desired_position(1), desired_position(2), desired_position(3), 'go', 'MarkerSize', 10,
'MarkerFaceColor', 'g');

plot3(current_position(1), current_position(2), current_position(3), 'b-', 'LineWidth', 2);

% Add stick-like structure

plot3([initial_position(1), current_position(1)], [initial_position(2), current_position(2)],


[initial_position(3), current_position(3)], 'k-', 'LineWidth', 2);

plot3([current_position(1), desired_position(1)], [current_position(2), desired_position(2)],


[current_position(3), desired_position(3)], 'k-', 'LineWidth', 2);

legend('Initial Position', 'Desired Position', 'Robot Path');

drawnow;

end

You might also like