Week 2- 2R Robotic Arm Challenge
clc
close all
% Inputs
l1 = 1;
l2 = 0.5;
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
ct=1;
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
x0 = 0;
y0 = 0;
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
x2 = x1 + l2*cosd(THETA2);
y2 = y1 + l2*sind(THETA2);
plot([x0 x1],[y0 y1],[x1 x2], [y1 y2], "linewidth",4)
axis([-0.1 1.5 0 1.5])
pause(0.1)
M(ct) = getframe(gcf);
ct = ct+1;
end
end
Movie(M)
videofile = videowriter('forward_kinematics.avi''Uncompressed AVI');
open(videofile)
writevideo(videofile,M)
close(videofile)
Aim:-
To write a program in MATLAB to simulate the forward kinematics of a 2R robotic arm.
Procedure:-
If theta 1 and theta 2 are the angle made by link 1 and link 2 respectively.
So, (starting point of link1) X0,Y0= (0,0)
(End point of link1) X1,Y1 = [l1*cos(theta1), l1*sin(theta1)]
where, length of link 1 = l1 and lenth of link 2 = l2
(Starting point of link2) X1,Y1 = [l1*cos(theta1), l1*sin(theta1)]
(End point of link2) X2,Y2 = [x1 + l2*cosd(theta2), y1 + l2*sind(theta2)]
So, we will be ploting graph for 3 coordinates i.e (x0,y0) (x1,y1) (x3,y3) for varying theta 1 and theta2
For varying theta values in program we will use linspace command
We will use for loop to get 10 values of theta 1 and theta 2