Week 2- 2R Robotic Arm Challenge
AIM:to write program for forward kinematics of 2R robotic arm
CODE EXPLANATION:
- here we are giving inputs .
- we are writing the values for x0 and y0.
- next we are writing the formulas for the x1 and y1.
- then we are writing for x2 and y2.
- atlast we are plotting the graph.
METHOD1:
l1=1; link1 %input
l2=0; link2
x0=0; %the starting of first link
y0=0;
x1=l1.*cosd(theta1); % the end of the first link and starting of the second link
y1=l1.*sind(theta1);
x2=x1+l2.*cosd(theta2);
y2=y1+l2.*sind(theta2); %the ending of the second link
%plotting
line([x0 x1],[y0 y1],'Linewidth',3,'color','b');
line([x1 x2],[y1 y2],'Linewidth',3,'color','r');
METHOD 2:
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); %we use for loop to iterate different values of theta1 and theta2
THETA2=theta2(j)
x0=0; %the starting of first link
y0=0;
x1=l1.*cosd(theta1); % the end of the first link and starting of the second link
y1=l1.*sind(theta1);
x2=x1+l2.*cosd(theta2);
y2=y1+l2.*sind(theta2); % the ending of second link
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'Linewidth',3)
axis([-1 1 0 1.5])
M(ct)=getframe(gcf);
ct=ct+1;
end
end
movie(M);
videofile=videowriter('forward_kinematics.avi','uncompressed.AVI');
open(videofile)
videowriter(videofile,M);
close(videofile)
CODE EXPLANATION:
- first we are assigning the values of link1 and link2.
- then we are assigning the count=1.
- then we are assigning the values of theta1 and 2 by using linspace().
- then we are assigning i to the variable THETA1 and THETA2.
- then we use for loop for different positions of robot at different theta values.
- then we are giving the starting and ending point of link 1 and link2.
- we are keeping the initial value for link1 as x0=0,y0=0.
- then we are plotting the graph of the robotic arm.
- we are then setting the values of x and y axis.
- then we get all the frames of the robotic arm and we craete a movie.
- we are then saving the videofile to the AVI files.
- we are then writing the videofile
ERRORS FACED DURING CODING:
- while assigning the theta1 to the x2 I instead assigned theta.
- then I corrected it using editor window.
- then I forgot to leave space in each line while writing the for loop so I got the graph like a line
- then I corrected it by leaving space for the variable THETA1 and THETA2.
- then I forgot to give the axis values for x and y in axis().
THE SCREENSHOTS FOR ERRORS I FACED ARE POSTED WITH OTHER SCREENSHOTS:









https://youtu.be/N-P8guQYfZAhttps://youtu.be/4GQeynXC_kQ