Week 2- 2R Robotic Arm Challenge
links:
https://drive.google.com/drive/u/0/folders/1VB6Wwj0SsU3SuuC1_qGuHyYYgAl8DH3I
AIM:
Animation of Forward Kinematics of 2R-Robotic Arm.
EQUATIONS:
x0=0
y0=1
x1=l1*cosθ1
y1=l1*sinθ1
x2=l1*cosθ1+l2*cos(θ1+θ2)
y2=l1*sinθ1+l2*sin(θ1+θ2)

Program:
% inputs
%{length of the 1st link}
l1=10;
%{length of the 2nd link}
l2=15;
ct=1;
% angel of 1st link with base from 0 to 90 total 4 parts {0,30,60,0}
thita1=linspace(0,90,4);
% angel of 1st link with reference base from 0 to 90 total 4 parts {0,30,60,0}
thita2=linspace(0,90,4);
% 1st for loop for range of angel of link 1 with reference o base.and thita values changes for every step.
for i=1:length(thita1)
Tta1=thita1(i);
% 2nd for loop for range of angel of link 2 with reference o base.and thita values changes for every step.
for j=1:length(thita2)
Tta2=thita2(j);
x0=0;
y0=0;
% coordinate of the links. ct value increases 1 for every step to repeate the loop upto condition is ture.
figure(ct)
hold on
x1=l1*cosd(Tta1)
y1=l1*sind(Tta1)
x2=l1*cosd(Tta1)+l2*cosd(Tta1+Tta2)
y2=l1*sind(Tta1)+l2*sind(Tta1+Tta2)
axis([-15 20 0 20])
plot([x0 x1],[y0 y1],'color','r')
plot([x1 x2],[y1 y2],'color','b')
pause(0.3)
M(ct)=getframe(gcf);
ct=ct+1;
end
end
% Animation of the Arms.
movie(M)
videofile=videowriter('ani_2r_arm.avi','animated_file.avi');
open("videofile")
writevideo(videofile,M)
close(videofile)
RESULT:

