% To write a code to create forward kinamatics of 2R robotic arm
% Creating plot with multiple values of theta1 & theta2
% Create Animation of the arm movement at different angles
% Make a movie of the animation
clear all
close all
clc
% inputs
l1 = 1 ;
l2 = 0.5;
theta1 = linspace(0,90,10); % arrays
theta2 = linspace(0,90,10) ; % arrays
% for each value of theta1 & theta2 we need to plot and angle has
% to change automatically, for that we are using concept of FOR loop
ct=1;
for i= 1:length(theta1); %lenght(theta1)means it has upto 10 values & i will store one value for each value of theta1
beta1=theta1(i); % assigning each value of i to beta1 everytime
for j=1:length(theta2); % since arm 2 takes multiple values, we use
% another FOR loop to acces particular value and perform calculation
beta2=theta2(j); % assigning each value of j to beta2
x0 = 0 ;
y0 = 0 ;
x1 = l1*cosd(beta1);
y1 = l1*sind(beta1);
x2 = x1 + l2*cosd(beta2);
y2 = x1 + l2*sind(beta2);
%plotting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
axis([-0 1.5 0 1.5 ]) % fixing x&y axis
pause(0.01) % we have set up speed with trial and error
m(ct)=getframe(gcf); % getting figure window saved in an array called 'm'
ct=ct+1; % incrementing each value
end
end
% generating a movie of 'm'
movie(m)
% creating a video file with the name forward kinematics which is uncompressed avi
videofile = VideoWriter('forward_kinematics.avi','uncompressed AVI') ;
open(videofile);
writeVideo(videofile,m); % we will write the frames that we captured
close(videofile);