Week 2- 2R Robotic Arm Challenge
the program bellow gives graphical representation and movement of robotic arms in which the arm 1 rotates in 120 degrees and arm 2 90 degrees while programing and creating the animation i faced difficulty in saving the movie. after which i changed uncompresed to mpeg-4 format and created the animation the link for the animatiion : https://drive.google.com/file/d/1rvcmp7VpZqTx1umrn_Sztp_nnaOSyquP/view?usp=sharing
clear all
close all
clc
%inputs
link1= 2 %length of arm 1
link2= 1 %length of arm 2
theta= linspace(0,120,20); %angle between x axis and arm 1
alpha= linspace(0,90,20); %angle between x axis and arm 2
a=1
for i= 1:length(theta) % loop for movement in arm 1
theta1 = theta(i); % theta1 stores each value of angle in arm 1
for j= 1:length(alpha) % loop for movement in arm 2
alpha1 = alpha(j); % alpha1 stores each value of angle in arm 2
x=0; % x-axis cordinate for start of arm 1 which is at origin
y=0; % y-axis cordinate for start of arm 1 which is at origin
x1=link1*cosd(theta1); % x-axis cordinate for end of arm 1 which is joint between arm1 and arm2
y1=link1*sind(theta1); % y-axis cordinate for end of arm 1 which is joint between arm1 and arm2
% cosd and sind are used as the angle is in degrees if the
% angle is in radians cos and sin are used
x2=x1+link2*cosd(alpha1); % x-axis cordinate for end of arm 2 which is joint between arm2 and manuplator
y2=y1+link2*sind(alpha1); % y-axis cordinate for end of arm 2 which is joint between arm2 and manuplator
plot([x,x1],[y,y1],[x1,x2],[y1,y2],LineWidth=3)
%the above line of command is used to plot the line for each value os theta and alpha
axis([-2 4 0 4.5]) % axis command is used to set limits of the xaxis and y axis respectively
pause(0.05) %pause command is used for pausing the figure such that it can be animated
b(a)=getframe(gcf); % getframe command used to store the each figure in 'b'
a=a+1;
end %loop for alpha
end %loop for theta
% the commands below are for creation of movie off the movement of the arm
movie(b)
videofile= VideoWriter('robotic_arm1.avi','MPEG-4');
open(videofile)
writeVideo(videofile,b)
close(videofile)