% This is a code for animating the forward motion of the robotic arm for the
% rotation of the arm between 0 to 90 degree
% We will first define the arm lengths and then will create a array for the
% limits of rotaion of the arms i.e. between 0 to 90 degrees.
% We will then be using two for loops, first for loop will be used to
% define the coordinats of the arm 1 of the robot and second for loop will
% used to define the coordinates of arm2 while keeping the first arm fixed
% at one position and then animation of the plot is stored in videofile
% using various commands
arm1 = 1; %length of arm 1
arm2 = 0.5; %length of arm 2
theta = linspace(0,90,15); %limits for the motion of the arms
ct = 1; %counter value for capturing frames of the plot
for i = 1:length(theta) %for loop 1 for obtaining coordinats of arm1
%coodinates of one end of the arm 1
x0 = 0;
y0 = 0;
%coordinates of second end of arm 1 and the first end of the arm2
x1 = arm1*cosd(theta(i));
y1 = arm1*sind(theta(i));
for j = 1:length(theta) %for loop 2 for obtaining coordinats of arm2
%cordinates for the second end of arm2
x2 = x1+(arm2*cosd(theta(j)));
y2 = y1+(arm2*sind(theta(j)));
%plotting arm1 and arm2
plot ([x0 x1],[y0 y1],[x1 x2],[y1 y2],'LineWidth',2)
%defining axis limits for more visible plot
axis([-0.2 1.8 0 1.8])
%pausing for better animation
pause(0.03);
%capturing frames of each plot
M(ct) = getframe(gcf);
%increasing counter value to capture other frame
ct = ct+1;
end
end
%code for creating animation out of the frames captured in variable M
movie(M)
%creating videofile to store animation in it
videofile = VideoWriter('kinematics of robot arm.avi','Uncompressed AVI');
%opening the videofile to add all the frames
open(videofile);
%writing all the frames onto the videofile
writeVideo(videofile,M);
%closing the videofile to store all the added data
close(videofile);