Simulating Forward Kinematics of a 2R Robotic Arm using MATLAB program.
AIM:
Simulating Forward Kinematics of a 2R Robotic Arm using MATLAB program.
GOVERNING EQUATION:
For link 1(arm1)
Start Point
x=0
y=0
End point:
x1=l1×cos(θ1)
y1=l1×sin(θ1)
For link 2 (arm2)
Start Point
x1=l1×cos(θ1)
y1=l1×sin(θ1)
End point
x2=x1+(l2×cos(θ2))
y2=y1+(l2×sin(θ2))
OBJECTIVES:
- Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm.
- Creating an animation from the plots obtained in the program.
THEORY:
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.
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 or translational 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.
The link-1 is attached to the base and end of link one is connected to link-2. And end of link-2 is connected to the end effector which performs the desired operation.
PROGRAM:
Programming language used is MATLAB.
clear all
close all
clc
% Inputs
% Length of robotic arms
l1 = 1;
l2 = 0.5;
% Set of angles for the movement of robotic arms
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
ct=1; % Counter with starting value assigned as 1
for i = 1:length(theta1) % Iterating i from 1 to 10 as theta1 has 10 values
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
% Coordinates of start point of first arm
x0 = 0;
y0 = 0;
% Coordinates of end point of 1st arm / start point of 2nd arm
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
% Coordinates of end point of 2nd arm
x2 = x1 + l2*cosd(THETA2);
y2 = y1 + l2*sind(THETA2);
% Plotting
% Coordinates of arms assigned over a set of theta1 and theta2
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3,'marker','*');
% The limits of x-axis and y-axis
axis([-0.1 1.5 0 1.5]);
% To cease the animation from jumping between subsequent figures
pause(0.03)
% Collecting frames of figures to comprise a movie/animation
M(ct) = getframe(gcf);
ct=ct+1;
end
end
% To make a movie of the collected frames
movie(M)
% Saving the movies in '.avi' format
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
% Writing the movie in the videofile created
writeVideo(videofile,M)
close(videofile)
EXPLANATION OF THE PROGRAM:
1) Lengths of both the links are taken as input. Length of link-1 (L1) is taken as 1m and length of link-2 (L2) is taken as 0.5m.
2) Angles traced by both the links, for link-1 and for link-2 is taken as input. The angles traced are varied over a range to simulate the movement of the robotic arm.
3) Base position of link-1 (x0,y0) is considered as origin (0,0).
4) Then two for loops are used to iterate over the range of angles traced by both the links. For each particular angle of link-1 , link-2 is moved over its entire range , to obtain different positions of end effector at that angle of link-1
5) For a particular value of θ1 and θ2 , the end position of link-1 is calculated by these equations.
x1=x0+L1⋅cos(θ1)
y1=y0+L1⋅sin(θ1)
The end position of link-1 is also the start position of link two. The end position for link-2 is calculated by these equations.
x2=x1+L2⋅cos(θ2)
y2=y1+L2⋅sin(θ2)
6) Then for each particular position of link-1 and link-2 , a plot is made which is then captured frame by frame to make a movie.
7) A video file of '.avi' format is made to save the movie.
8) The movie is then written into the videofile and the final animation is thus created.
OUTPUT:
The output is obtained in form of an animated video clip. This animation can be viewed by visiting the link mentioned below.
or
https://drive.google.com/file/d/1vWoCwEuUMuMpx2KKpUAHV7yXL9Z4NAj4/view?usp=sharing
CONCLUSION:
A simulation of the forward kinematics of a 2R Robotic Arm in 2D workspace was created using MATLAB program.