Forward kinetics of a 2R robotic arm manipulator using MATLAB
The following MATLAB is code is written to find the final positions and workspace of a 2R robotic arm manipulator.
Therefore using the equations:
x1= l1*cosd(theta1)
y1= l1*sind(theta1)
x2= x1 + l2*cosd(theta2)
y2= y1 + l2*sind(theta2)
where,
theta1 = the angle the first link of the robotic arm makes with the ground
theta2= the angle the second link of the robotic arm makes with the ground
l1 = length of the first linkage
l2 = length of the second linkage
We can find the final positions of the rorbotic arm and it's corresponding workspace.
%Forward kinetics of a 2R robotic arm manipulator
clear all
close all
clc
%Inputs
l1 = 1;
l2 = 0.5;
theta1 = linspace(0,90,20);
theta2 = linspace(0,90,20);
%Coordinates
x0=0;
y0=0;
ct=1; %counter
%the for loop used below, is required so that a plot of the robotic arm manipulator at each instant/coordiante can be displayed in a continous video like fashion
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
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 ([-0.1 1.5 0 1.5])
pause(0.001)
M(ct)= getframe(gcf);
ct=ct+1;
end
end
% The commands below are used to create an .avi video file of the robotic arms motion
movie(M)
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Errors faced:
Apart from a few typos, no significant errors were faced.
In the error above was fixed by changing the 'Movie" command to 'movie'
Result: