Week 2- 2R Robotic Arm Challenge
https://drive.google.com/file/d/13mIeUxMU_VkvyJ4heoorccKhDVZ5elvc/view?usp=sharing
% program to simulate the forward kinematics of a 2R robotic arm
close all
clear all
clc
% Inputs
% Length of arm links
l1 = 1;
l2 = 0.5;
% Angle of links
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
Ct=1;
% Following for loop is used to generate animate the forward kinematics of a 2R robotic arm
for i =1:length(theta1)
THETA1 = theta1(i);
for j =1:length(theta2)
THETA2 = theta2(j);
X0 = 0;
Y0 = 0;
X1 = l1*cosd(THETA1);
Y1 = l1*sind(THETA1);
X2 = X1+l2*cosd(THETA2);
Y2 = Y1+l2*sind(THETA2);
plot([X0 X1],[Y0 Y1],[X1 X2],[Y1 Y2], 'LineWidth' ,3)
axis([-0.1 1.5 0.1 1.5])
pause(0.3);
% here following command(getframe) is used to store the each frame as an array
M(Ct) = getframe(gcf);
Ct = Ct+1;
end
end
% (following codes is used to create and run the animation clip of forward
%kinematics of 2R robotic arm)
% (Here movie command create the video file of the animation based on each
% frame)
movie(M)
videofile = VideoWriter('Forword_Kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)