Week 3.2 - 2R Robotic Arm Challenge
clear all
close all
clc
%parameters of the robotic arm
X0= [0 , 0]; %base or origin of the robotic arm
l1=1; %length of arm 1
l2=0.5; %length of arm 2
theta1= [0 : 1 : 90]; %values for theta for which plotting will be done
theta2= [0 : 1 : 90];
ct=1; % counter so that we can save each frame of the video later on
for i= 1 : length(theta1)
X1=[l1*cosd(theta1(i)) , l1*sind(theta1(i))]; %coordinates of end of arm 1 for corresponding theta1
for j = 1 : length(theta2)
X2=[(X1(1) + l2*cosd(theta2(j))) , (X1(2) + l2*sind(theta2(j)))]; %coordiantes of end of arm 2 for corresponding theta2
plot([X0(1) X1(1)], [X0(2) X1(2)], [X1(1) X2(1)], [X1(2) X2(2)],"LineWidth",3) %Plots the instance for each theta1 and theta2 values
axis([-0.1 1.5 -0.1 1.5]) %to keep a fixed axis, so that the plot looks same throughout animation
M(ct)=getframe(gcf); %saves the frames into M which is a structure which stores each and every instance
ct=ct+1; %increases counter by 1
end
end
movie(M) %plays in the movie frames in the structure M
videofile = VideoWriter('forward_kinematics.avi','MPEG-4'); %VideoWriter creates a file to write video into
open(videofile)
writeVideo(videofile,M) %writes the frames in structure M into the file named videofile
close(videofile)
Errors faced and steps taken to overcome them:
One of the errors or difficulty faced was in the code of VideoWriter, where I forgot to Captialize 'V' and 'W'. Also the first time I compiled the video into an UncompressedAVI file, the file turned out to be 8.5 gb with the same duration as of the current video. Thus, MPEG-4 format was used which reduced the size significantly, so that it can be uploaded and shared via Google Drive link.
LINK FOR THE VIDEO:
https://drive.google.com/file/d/1p7lUGU88met-uQ-Onkuyh_lmmngYP1y3/view?usp=sharing