Forward Kinematics Manipulation Of A 2R Robotic Arm Using MATLAB
AIM: To simulate the forward kinematics of a 2R robotic arm using MATLAB.
|
GOVERNING EQUATION: The equation to determine the position of end-effector is as follows: `X_2 = X_1 + L_2.costheta_2` , `Y_2 = Y_1 + L_2.sintheta_2` `X_1 = L_1.costheta_1` , `Y_1 = L_1.sintheta_1` `X_0 = Y_0 = 0` where; `(X_0 ,Y_0 )` = coordinates of origin i.e. base `(X_1 ,Y_1 )` = end coordinates of Link 1 `(X_2,Y_2)` = end coordinates of Link 2 i.e. end-effector `L_1,L_2` = length of Link 1 and 2 (m) `theta_1,theta_2` = angle of Link 1 and 2 (degree) |
|
OBJECTIVE: 1. To write a program for a 2R robotic arm. 2. To plot the animation of the end-effector position according to forward kinematics. THEORY: A robotic arm 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. Forward Kinematics: Forward kinematics refers to the use of the kinematic equations of a robot to compute the position of the end-effector from specified values for the joint parameters. |
SOLUTION:
Programming Language: MATLAB
Procedure/Steps:
1. Assign suitable variables to store length and angle for the links.
2. Create a for loop for generation of frames and declare a variable named counter (ct) to start with.
3. The first loop (i) will be ranging from 1 to the maximum value of θ1 (theta1) whereas the second one (j) will be ranging from 1 to the maximum value of θ2 (theta2).
4. For one count of loop i, loop j would finish complete rotation and compute the values as shown in the code.
5. The images are plotted with the help of plot function.
6. Finally, the counter will increment by 1 (ct+1) until loop i is finished and step #4 and #5 are repeated.
7. getframe() captures the individual frame and stores it in an array M.
8. To create an animation of all the frames generated,
a. assign the frame movie in array M
b. assign appropriate file name and extension in videofile()
c. open() begins to extract the files
d. writeVideo writes data from an array to the video file
e. close() terminates the operation
Code: The MATLAB program to plot the simulation for forward kinematics of a 2R robotic arm is shown below.
% Program for forward kinematics of a 2R robotic arm manipulator.
% Inputs:
% (NOTE: 1 - First Link, 2 - Second Link)
% Length of links (m)
l1 = 1;
l2 = 0.4;
% Angle with the horizontal (degrees)
a1 = linspace(0,90,10);
a2 = linspace(0,135,30);
% Solution:
% Counter and loop initialization
ct = 1;
for i = 1:length(a1)
theta1 = a1(i);
for j = 1:length(a2)
theta2 = a2(j);
% Coordinates:
% Initial point of link 1
x0 = 0;
y0 = 0;
% Final point of link 1 i.e. Initial point of link 2
x1 = l1*cosd(theta1);
y1 = l1*sind(theta1);
% Final point of link 2
x2 = x1 + l2*cosd(theta2);
y2 = y1 + l2*sind(theta2);
% Assigning the parameters
txt1 = ['θ1 = ' , num2str(theta1) , ' deg'];
txt2 = ['θ2 = ' , num2str(theta2) , ' deg'];
txtend = ['x2 = ' , num2str(x2) , ' , ' , 'y2 = ' , num2str(y2)];
% Plot:
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',5)
xlabel('X-axis (m)')
ylabel('Y-axis (m)')
title('Forward Kinematics of 2R robotic arm')
text(x0,y0,txt1,'VerticalAlignment','top')
text(x1,y1,txt2,'VerticalAlignment','top')
text(x2,y2,txtend,'HorizontalAlignment','left','VerticalAlignment','bottom')
text(0.5*(x0+x1),0.5*(y0+y1),' Link 1')
text(0.5*(x1+x2),0.5*(y1+y2),' Link 2')
grid on
axis([-1 2 -0.5 2])
pause(0.3)
M(ct) = getframe(gcf);
ct = ct+1;
end
end
% Creating the animation:
movie(M);
videofile = VideoWriter('Forward Kinematics of a 2R Robotic arm.avi','Uncompressed AVI');
open(videofile);
writeVideo(videofile,M);
close(videofile);
Output: The simulation of the robotic arm is coded successfully as shown below.
Animation:
Errors occurred:
Error #1: Failure in the generation of frames.
Solution #1: Counter increment (ct = ct+1) was not included so the loops were getting executed only for the 1st iteration.
Error #2: Problem in recognizing the file extension due to its absence.
Solution #2: File extension was included (.avi) in VideoWriter to download an animation film in the current folder.
CONCLUSION: Thus, the program for a 2R robotic arm forward kinematics was coded and the position of end-effector was simulated in MATLAB plot as a video.
REFERENCES: Image Source