To simulate the forward kinematics of a 2R Robotic Arm through MATLAB programming.
AIM - Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm.
Theory -
A robotic arm (not robotic hand) is a type of mechanical arm, usually programmable, with similar functions to a human arm; the arm may be the sum total of the mechanism or may be part of a more complex robot. The links of such a manipulator are connected by joints allowing either rotational motion (such as in an articulated robot) or translational (linear) displacement. The links of the manipulator can be considered to form a kinematic chain. The terminus of the kinematic chain of the manipulator is called the End effector and it is analogous to the human hand.
Figure : Robotic arm
We can see that it is the Robotic arm with 2 links and 2 degree of freedom. From the figure we can see assume the following-
`l1` is the Link 1, `l2` is the Link 2
(`x0,y0`) are the starting coordinates for link 1
(`x1,y1`) are the ending coordinates of link 1/starting coordinates of link 2
(`x2,y2`) are the ending coordinates of link 2
(`theta 1`) is the angle subtended by the link 1 with reference to the horizontal axis of the base
(`theta2`) is the angle subtended by the attached link 2 with reference to the horizontal axis of the end of link 1
Governing Equations -
Starting Coordinates of Link 1
(`x0,y0`) is set to be (0,0)
Ending Coordintes of Link 1 / Starting Coordinates of Link 2
`x1 = l1*cos(theta1)`
`y1 = l1*sin(theta1)`
Ending Coordinates of Link 2
`x2 = x1+l2*cos(theta2)`
`y2 = y1+l2*sin(theta2)`
Programming Software Used in simulating Robotics Arm- MATLAB R2018b
Procedure -
Inputs:
MATLAB code for simulating the forward kinematics of the 2R Robotic Arm:
clear all
close all
clc
% Forward kinematics simultion of 2R Robotic Arm
%Inputs
l1 = 1;
l2 = 0.5;
theta1 = linspace(0,90,10); %to create the array of theta1
theta2 = linspace(0,90,10); %to create the array of theta2
ct=1;
for i = 1:length(theta1)
THETA1 = theta1(i); %THETA1 value is changing w.r.t. theta1
for j = 1:length(theta2)
THETA2 = theta2(j); %THETA2 value is changing w.r.t. theta2
x0 = 0;
y0= 0;
x1 = l1*cosd(THETA1); % d refers to degree
y1 = l1*sind(THETA1); % As MATLAB , the angle is set to be in radians
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.1)
M(ct)= getframe(gcf); %getframe is used to capture the current axes
ct = ct+1;
end
end
movie(M)
videofile=VideoWriter('forward_kinematics.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Explanation-
M = refers to the matrix to store the frames of the animation.
getframe = It is use capture the current axes as it appears on the screen as a frame movie.
gcf = get current frame.
ct = with the help of ct the M matrix is getting input and ct gets increment.
videowriter = it stores the movie with given file name and given format.
Result -
Output :
The plot for the executed MATLAB code.
Animation file:
https://www.youtube.com/watch?v=QhbQLYpWZYE
The animation file uploaded in youtube.
Error,if any :
As MATLAB is case-sensitive ,so it should be 'VideoWriter' in place of 'Videowriter'.
Conclusion-
The forward kinematics of 2R Robotic arm has been simulated successfully through MATLAB programming. So, now we can try with 3-D simulations and more no.of links.