Week 3.2 - 2R Robotic Arm Challenge
% To simulate the forward kinematics of a 2R Robotic Arm
% starting the program with basic commands
clear all
close all
clc
% let the length of linkages be l1 and l2
l1 = 1;
l2 = 0.5;
% let the angle made by 2 lengths be theta1 and theta2
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
ct=1;
% for loop for theta1 and theta 2
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
% the three coordinates are (x0,y0);(x1,y1) and (x2,y2)
x0 = 0;
y0 = 0;
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
x2 = x1+l2*cosd(THETA2);
y2 = y1+l2*sind(THETA2);
% plotting
plot ([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
% axis command is used to show x and y axis on graph
axis([-0.1 1.5 0 1.6])
% tthe time interval between one frame to another frame
pause(0.1)
% M represents array , ct represents separate frame ,
% getframe is a command
M(ct) = getframe(gcf);
% increment of frame
ct=ct+1;
end
end
% generating movie with frames
movie(M)
% name = command ('file name','profile name')
videofile = VideoWriter('forward_kinematic.avi','Uncompressed AVI');
% open > write > close the video file
open(videofile)
writeVideo(videofile,M)
close(videofile)
REPORT