0% found this document useful (0 votes)
21 views2 pages

Assignment 5 2021A4PS3065H

Uploaded by

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

Assignment 5 2021A4PS3065H

Uploaded by

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

% Define the trajectory functions

T = 0:0.01:1;

X = 1 – 6*t.^2 + 4*t.^3;

Y = 1.5*ones(size(t));

% Plot X vs t and Y vs t

Figure;

Plot(t, x);

Xlabel(‘t’); ylabel(‘X’); title(‘X vs t’);

Figure;

Plot(t, y);

Xlabel(‘t’); ylabel(‘Y’); title(‘Y vs t’);

% Define the link lengths

L1 = 1; l2 = 1;

% Initialize arrays to store joint angles

Theta1 = zeros(size(t));

Theta2 = zeros(size(t));

% Calculate joint angles using inverse kinematics

For I = 1:length(t)

% Calculate the joint angles using inverse kinematics equations

R = sqrt(x(i)^2 + y(i)^2);

Theta1(i) = atan2(y(i), x(i));

Theta2(i) = acos((r^2 + l1^2 – l2^2) / (2*l1*r));

End
% Plot θ1 vs t and θ2 vs t

Figure;

Plot(t, theta1);

Xlabel(‘t’); ylabel(‘θ1’); title(‘θ1 vs t’);

Figure;

Plot(t, theta2);

Xlabel(‘t’); ylabel(‘θ2’); title(‘θ2 vs t’);

% Animate the 2R manipulator

Figure;

For I = 1:length(t)

Cla;

Plot([0 x(i)], [0 y(i)], ‘k-‘);

Hold on;

Plot([0 l1*cos(theta1(i))], [0 l1*sin(theta1(i))], ‘b-‘);

Plot([l1*cos(theta1(i)) x(i)], [l1*sin(theta1(i)) y(i)], ‘r-‘);

Axis equal;

Pause(0.01);

End

You might also like