Forward Kinematics of a 2R Robotic Arm using Matlab
Aim - Write a program in Matlab showing the Forward Kinematics of a 2R Robotic Arm
Description -
2R Robotic Arm- A robotic arm is a type of mechanical arm, usually programmable. The arm may be the sum total of the mechanisms or may be part of a more comple robot. The links of such a manipulator are connected by joints allowing either rotational motion or linear displacement. the links of the manipulator can be considered to form a kinematic chain. the terminus of the kinematic chain of the manipukator is called the end effector. An end effectror is the device at the end of a robotic arm, designed to interact with the environment.
The Kinematic analysis is the relationships between the positions, velocities and accelerations of the link manipulator. The kinmenatics separate in two types, direct kinematic and inverse kinematics. In Forward kinematics, the length of each link and the angle of each joint is given & we have to calculate the position of any point in the work volume of the robot. In Inverse Kinematics, the length of each link & position of the point in work volume is given & we have to calculate the angle of each joint.
In this project, we consider a 2R robotic arm with two rotations i.e. it has two links which rotate or work over a 2-D planee with each of link having a single degree of freedom.
As shown in figure a 2R robotic arm with its dimensions and coordinates shown here.
where,
Xo=0,Yo=0">Xo=0,Yo=0Xo=0,Yo=0
X1 =L1.cos(θ1) Y1=L1.sin(θ1)">X1 =L1.cos(θ1) Y1=L1.sin(θ1)X1 =L1.cos(θ1) Y1=L1.sin(θ1)
X2=X1+L2.cos(θ2) Y2=Y1+L2.sin(θ2)">X2=X1+L2.cos(θ2) Y2=Y1+L2.sin(θ2)X2=X1+L2.cos(θ2) Y2=Y1+L2.sin(θ2)
Explanation to the Code
- Initially the required input variables such as lengths of the links, angles and coordinates are declared alongwith a counter variable ct.
- Once the variables are declared, values are being assigned to the variables. The angles are assigned values with help of linspace commad as we consider 30 positions of link between 0-360.
- As we require the link at multiple positions i.e. rotate it. A for loop is written for link 1 and similar for loop is written for link 2 under the first for loop.
- Now under the for loop we define the coordinates (X1 , Y1) & (X2, Y2) using the below equations
X1 =L1.cos(θ1) Y1=L1.sin(θ1)">X1 =L1.cos(θ1) Y1=L1.sin(θ1)X1 =L1.cos(θ1) Y1=L1.sin(θ1)
X2=X1+L2.cos(θ2) Y2=Y1+L2.sin(θ2)">X2=X1+L2.cos(θ2) Y2=Y1+L2.sin(θ2)X2=X1+L2.cos(θ2) Y2=Y1+L2.sin(θ2)
- The plot command is used to plot the links on the graph. And to animate the plot, getframe command is used (getframe returns a movie frame. The frame is a snapshot of the current axes or figure). And the counter variable is incremented.
- Both for loops are than ended and the syntax for movie was written.
Syntax for Movie-
movie(M) # it plays the movie in matrix M
videofile=VideoWriter('Forward_Kinematics_2R_Robotic_Arm.avi','Uncompressed AVI') #assigns the filename and file formatopen
(videofile) #opens the videofilewritevedio(videofile,M) #writes the vedio with plot frames in the array M
close(videofile) #closes the vediofile
MATLAB CODE
% Forward kinematics of a 2R Robotic Arm
clear all
close all
clc
l1 = 1;
l2 = 0.3;
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
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);
% Plotting
plot([x0 x1], [y0 y1], [x1 x2], [y1, y2], 'LineWidth', 3)
axis ([-2 2 -2 2])
pause(0.01)
M(ct) = getframe(gcf);
ct = ct+1;
end
end
movie(M)
videofile = VideoWriter('Forward_Kinematics_2R_Robotic_Arm.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
SNAPSHOTS OF THE OUTPUT ARE SHOWN
Conclusion- The link given below gives the animation of the 2R robotic arm.
https://drive.google.com/open?id=1tUamAKq_HD6ZpYgSb2GhzlCFekJFzPwT