Week 2- 2R Robotic Arm Challenge
% VIDEO LINK
CODE WITH EXPLANATION
% 2R ROBOTIC ARM CHALENGE
% explanation:- I need to make animation and programming for 2r Robotic arm
% and i have some intital values given in lecture, so i have two arm which
% lenght denoted by l1 and l2 with some angle thetha1 and theta2 from origin point at x & y =0,0
%inputs
l1=1;
l2=0.5;
% linspace use for 10 values of theta1 & theta2 when it goes 0 to 90.
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
ct=1;
% Need to use for loop for every different value of theta1 & theta2
for i= 1:length(theta1);
b= theta1(i);
for j= 1:length(theta2);
c= theta2(j);
%Coordinates
x=0;
y=0;
% if i need to calculate coodindate of both arm which is x1,y1 & x2,y2 i
% need to use this formula
x1= l1*cosd(b);
y1=l1*sind(b);
x2= x1+l2*cosd(c);
y2= y1+l2*sind(c);
% to plot the value of x,x1,x2,y,y1,y2
plot([x x1],[y y1],[x1 x2],[y1 y2],'linewidth',3)
% this command used to make our own limits for x & y axis
axis([-0.1 1.5 0 1.5])
pause(0.03)
% this command M is represent array and ct represent frame
M(ct)= getframe(gcf);
ct=ct+1;
end
end
% to generate movie with data of M
movie(M)
% we need a file to put every frame in it so, videfile is created
videofile = VideoWriter('2R_RBOTIC_ARM.avi','Uncompressed AVI');
% it is to open the file
open(videofile)
% now we have to write the file
writeVideo(videofile,M)
% now need to clese the file
close(videofile)
% ERROR I HAVE FACED DURING PROGRAMMING;
when i was writting this command videofile = VideoWriter('2R_RBOTIC_ARM.avi','Uncompressed AVI');, so i used small lette w in videowriter because of that i was facing error.