Week 2- 2R Robotic Arm Challenge
FORWARD KINEMATICS OF A 2R ROBOTIC ARM MANIPULATOR
link1 = l1
link2 = l2
starting point =(0,0)
ending point = (lcostheta,lsintheta)
if theta and theta 2 are given,
what is the final position of theb manipulator
solution=step-1-calculate position of link 1
step-2-calculate position of link 2
for link 1
starting point = (x1,y1)
ending point = (x2,y2)
length of the link2 is =l2
x2 = x1+l2costheta2
y2 = y2+l2sintheta2
solution set = [x0,y0] [x1,y1] [x2,y2]
%forward kinematics of 2r robotic arm manipluator
clear all
close all
clc
%inputs
l1 = 1;
l2 = 0.5;
theta1 = 45;
theta2 = 30;
%coordinates
x0 = 0;
y0 = 0;
x1 = l1*cosd(theta1);
y1 = l1*sin(theta1);
x2 = x1+l2*cosd(theta2);
y2 = y1+l2*sind(theta2);
%plotting
line([x0 x1],[y0 y1],'linewidth',3,'color','b')
line([x1 x2],[y1 y2],'linewidth',3,'color','r')
creating another file
forward_kinematics_with_for_loop
clear all
close all
clc
%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);
%plotting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
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)
REPORT:-
AIM-writing a program to solve forward kinematics of a 2r robotic arm.
OBJECTIVE-plot the forward kinematics of a 2r robotic arm.
- making an animation of two robotic arm.
- using for loop to perform the operation.
- finally creating the movie of a 2R robotic arm.
getting started,

writing a program in matlab,
%forward kinematics of a 2R robotic arm
clear all
close all
clc
%inputs
l1 = 1;
l2 = 0.5;
theta1 = 45;
theta2 = 30;
%coordinates
x0 = 0;
y0 = 0;
x1 = l1cosd(theta1);
y1 = l1sind(theta1);
x2 = x1+l2*cosd(theta2);
y2 = y1+l2*sind(theta2);
%plotting
line([x0 x1],[y0 y1],'linewidth',3,'color','r')
line([x1 x2],[y1 y2],'linewidth',3,'color','r')

now creating the another file with for loop.
OBJECTIVE-the objective here is to have multiples values of theta1 and theta2 and for each value of theta 1 and theta2 we are going to create a plot and stitching all the plots togeother to make an animation,
clear all
close all
clc
%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);
ct = 1
x0 = 0;
y0 = 0;
x1 = l1cosd(theta1);
y1 = l1sind(theta1);
x2 = x1+l2*cosd(theta2);
y2 = y1+l2*sind(theta2);
%plotting
line([x0 x1],[y0 y1],'linewidth',3,'color','r')
line([x1 x2],[y1 y2],'linewidth',3,'color','r')
end
end



