Week 2- 2R Robotic Arm Challenge
% program in Matlab to simulate the forward kinematics of a 2R Robotic Arm, as shown in the video
clear all
close all
clc
%inputs - length of the first link & second link
l1=1;
l2=0.5;
% thetas is going to be array by linspace command
theta1=linspace(0,45,10);
theta2=linspace(0,45,10);
%for loop to calculate positions of theta 1&2 (here each and every time for loop is executed its say counter=ct+1)
ct=1;
for i = 1:length(theta1)
angle1= theta1(i);
for j = 1:length(theta2)
angle2= theta2(j);
% initial position coordinates
x0 = 0;
y0 = 0;
% end position coordinates of link 1
x1=l1*cosd(angle1);
y1=l1*sind(angle1);
%link2
x2=x1+l2*cosd(angle2);
y2=y1+l2*sind(angle2);
% graph the positions in one single figure by plot command , for each value of theta1 theta2 changes
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',5)
% fixing the axis changing x-limits and y limits
axis([-0.1 1.5 0 1.5])
%pause command to pause the code
pause(0.3)
%getting the figure as a figure and storing in the form of array m(induvidual frame saved in array called as m.
m(ct) = getframe(gcf);
ct = ct+1;
end
end
%generating movie
movie(m)
videofile=VideoWriter('forward_kinematics 2r robo arm','uncompressed AVI');
open(videofile)
writeVideo(videofile,m)
close(videofile)
(Q)ERRORS HAPPENED WHILE CODING IS THAT I DIDNOT ABLE TO GET THE FIGURE SAVED AS A VIDEO AFTER EXECUTE
(A)AFTER I USED CAPITAL FIRSTLETTER FOR THE Video and write in small
