Week 2- 2R Robotic Arm Challenge
AIM
To create a matlab program to simulate the forwad kinematics of a 2R robotic arm
THEORY
The program we create using matlab is used mainly to find out the operationable area of a 2R robotic arm for this we require the angle between two links we assume it as theta 1 , theta 2.
theta1(angle b/w base and the first link)
theta2(angle b/w first link and second link)
we assume x1,y1 be the co-ordinates of ending point of first link
x1=l1*cos(theta1)
y1=l1*sin(theta1)
we assume x2,y2 be the ending point of second link
x2=x1+l2*cos(theta2)
y2= y1+l2*sin(theta2)
we can use this theory in a matlab program to find the workspcae of a 2R robot.
PROGRAM
% forwad kinematics of a 2 R robotic arm
% inputs
l1=2;
l2=1;
% Angles between linkages
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);
% plotting
plot([x0,x1],[y0,y1],[x1,x2],[y1,y2],'LineWidth',3);
axis([-0.1 3 0 3])
pause(0.01)
M(ct)= getframe(gcf);
ct=ct+1;
end
end
% conersion of plot into video
movie(M)
videofile= VideoWriter('forwad_kinematics.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
EXPLANATION OF CODE
- The inputs are defined .
- l1 = length of first arm is taken as 2 m.
- l2= length of second arm is taken as 1m.
- the values of theta 1 and theta 2 are taken between a range of 0and 90 .
- since we need to find the different co-ordinates of arm a for loop is defined .
- the corresponding value of for loop is assinged to THETA 1&THETA 2.
- the second for loop is defined becuase for every value of theta 1 the 2 arm can have different positions it is calculated using second for loop .
- after writing the equations for calculating x1,y1,x2,y2 we use plot command to plot the output data .
- axis are defined for plotting .
- ct function is used to make all frames together.
- for loop is closed.
- to convert the plot into a movie we use movie (M) command
- a video file is created with the name forwad_kinematics
- video file is opened and written
ERRORS FACED
- error while coding for loop

STEPS TAKEN TO CORRECT
the value of theta 1 was entered wrongly in the loop .It was replaced by THETA 1 and the problem was solved .
RESULT
The plot was made for forwad kinematics and the plot is converted into an animation using movie
https://youtu.be/hjD-bVF0SoI