FORWARD KINEMATICS OF ROBOTIC ARM
AIM - To simulate the forward kinematics of a Robotic Arm using MATLAB
OBJECTIVE :-
- Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm
- Create an animation file of the plot.
- Upload an animation on You tube
THEORY :-
- A 2R Robotic Arm includes two arms connected by two revolute pairs as shown below:-
- The end of the arm may be connected to a machining tool in case of Machining works or to a suction cup in case of assembly works or to a welding tool for welding.
- However, such applications generally includes spherical pairs rather than revolute pairs. A 2R robotic arm is the simplest of all the robotic arms.
- When, we have angles of both the links known, and we need final position or orientation of end effector, it is termed as FORWARD KINEMATICS.
- End effector is basically the part which is connected to the end of the robotic arm, where machining tool or welding tool are connected.
- As shown in the above figure, when angles are known and we need final position of point P, it is known as Forward Kinematics.
- Simulation of Forward Kinematics generally means to find the workspace of the Robot, which is the limit where the end effector of the robotic arm can reach as shown below.
- The workspace can be obtained by tracing the path of end effector of the robotic arm for all the possible configurations of the arm.
CODES :-
%Forward Kinematics of 2R Robotic Arm
clear all
close all
clc
%Inputs
%Lengths of links
l1 = 2;
l2 = 3;
%Angles made by the links
theta1 = linspace(0,90,15);
theta2 = linspace(0,90,15);
ct = 1;
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
%Inputs required to initiate 'for' loop
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',30)
axis([-1 6 0 6])
pause(0.000005)
%Getting frames of current figure
M(ct) = getframe(gcf);
ct = ct+1;
end
end
%Creating Movie
movie(M)
Videofile = VideoWriter('forward_kinematics.avi','Uncompressed avi');
open(Videofile)
writeVideo(Videofile,M)
close(Videofile)
CODE EXPLANATION :-
- In MATLAB, first we provided inputs as lengths of links, because these were the inputs which are going to be fixed for the whole process.
- To simulate the forward kinematics of the robotic arm, we need a number of angles for both the links. Hence, angles 'theta1' and 'theta2' are taken in terms of 'linspace' command. 15 values are taken between 0 to 90 for both the links.
- Now, to perform forward kinematics, for each specific orientation of link 1, different orientations of link 2 are required. Such orientations of link 2 are also required for other orientations of link 1. Hence, 'for' loop is used.
- Angles of link 1 and link 2 are called and stored in other variables 'THETA1' and 'THETA2'. These variables are used to undergo 'for' loop.
- Inputs (x0,y0), (x1,y1) & (x2,y2) are defined in terms of variables, 'THETA1' and 'THETA2'. (x0,y0) is the origin; x1,y1 are cosine and sine of 'theta1' of link1; x2 & y2 are increments of x1,y1, in terms of cosine and sine of 'theta2' of link 2.
- Then, (x0,y0), (x1,y1) & (x2,y2) are plotted, by taking x and y coordinates seperately and taking linewidth of 30. Here, (x1,y1) is the end point of link 1 as well as starting point of link 2. After taking limits along x and y axes of -1 to 6 and 0 to 6, a pause of 0.000005 seconds is taken for a specific configuration of both the links.It helped in performing animation with the plot.
- After getting frames from the animation made by the plot, movie creation is performed. A movie is basically a recording of the animation.
- ct is the increment provided to the 'for' loop. Previously, it is assigned a value of 1 & then it is incremented inside the loop.
- With some codes, the movie is assigned file name and a suitable format.
- https://youtu.be/tNU4eB7UH-c is the result obtained after execution of the program.
ERRORS ENCOUNTERED :-
1)
- In this error, y1 in line 30 is recognized seperately by MATLAB, as compared to line 27. So, it considered y1 as unrecognized variable, even though it is defined in line 27.
- To solve this, I just deleted y1 in line 30 and written it again and waited until MATLAB considered y1 same in line 30 and line 27.
2)
- In this error, x & y coordinates has to be written seperately, which is not done, hence it showed error.
- Correct code is plot([x0 x1], [y0 y1], [x1 x2], [y1 y2], 'linewidth', 3).
3)
- This is just a case sensitive error. It is written as 'videowriter'
- The correct code for this is 'VideoWriter'
CONCLUSION - Thus, in MATLAB, we created an animation with the help of a plot and created a movie with it.