Forward kinematics of a 2R robotic arm.
The above diagram illustrates a 2R Robotic arm. A 2R robotic arm consists of two links. Both the links are connected to each other as shown in the figure. One end is connected to a base and the other is connected to a manipulator.
The following program is used to simulate the forward kinematics of a 2R robotic arm. As described in the program, the first five lines of the code is used for predefined values.
A 'for' loop is used to simulate the kinematics of a robotic arm across the 90 degrees and assess the manipulator. Also, the code for the animation of plot is also written in the 'for' loop.
% A program to simulate the forward kinematics of a 2R Robotic Arm and an animation plot.
% inputs
l1=1; % length of link 1
l2=0.5; % length of link 2
theta1=linspace(0,90,10); % Angle made by link 1 with the horizontal
theta2=linspace(0,90,10); % Angle made by link 2 with the horizontal
ct=1;
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);
% Animation plot
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
axis([-0.1 1.5 0 1.5])
pause(0.03)
M(ct) = getframe(gcf);
ct=ct+1;
end
end
To convert the animation of the above plot in to a movie with .avi extension can be done using the code below.
movie(M)
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
During the programming, the below occured once because 'ct' is a variable in this program which has to be defined before the 'for' loop. Not defining a variable will result in such an error.