Forward kinematics of a 2R Robotic Arm using MATLAB.
Aim: To simulate the forward kinematics of a 2R Robotic Arm
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. The kinematics equations of the robot are used in robotics, computer games, and animation. The reverse process that computes the joint parameters that achieve a specified position of the end-effector is known as inverse kinematics.
- 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.
MATLAB Program:
%Program to simulate working space of 2R robotic arm
clear all
close all
clc
%inputs
l1 = 1;
l2 = 0.5;
angle1 = linspace(0,90,10);
angle2 = linspace(0,90,10);
x0 = 0;
y0 = 0;
temp = 1;
%Simulation
for i = 1:length(angle1)
theta1 = angle1(i);
for j = 1:length(angle2)
theta2 = angle2(j);
x1 = x0+l1*cosd(theta1);
y1 = y0+l1*sind(theta1);
x2 = x1+l2*cosd(theta2);
y2 = y1+l2*sind(theta2);
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',4)
axis([0 1.5 0 1.5])
pause(0.3);
M(temp) = getframe(gcf);
temp = temp+1;
end
end
movie(M)
simulation = VideoWriter('Robotic_Arm_Simulation','Uncompressed AVI');
open(simulation)
writeVideo(simulation,M)
close(simulation)
Steps:
1) Define all the inputs
- The values of l1 & l2 are assumed to be 1m & 0.5m respectively.
- The angle made by the 2 links is in between 0 deg & 90 deg with an increment of 10 deg to obtain smooth simulation.
- The values of x0 & y0 are considered as 0, and the values of x1, y1, x2, y2 are calculated using the trigonometric relations.
2) To run the same MATLAB program desired number of times, 'nested for loop' was used
3) Using MATLAB plot graphs all the positions of links that we have obtained for each angle was plotted.
4) The 'pause' command is used to get better animation speed.
5) The 'getframe' command was used to capture the motion of lines stored in variable 'M'.
7) To make a movie of all plots 'movie' command was used, it has to be stored in a variable 'M' and it has to be indexed. While defining inputs, a temporary variable must also be defined to index the plot.
8) To save this movie, the ‘videofile’ command is used which has the option to store the video in an Uncompressed ‘avi’ format along with the file name.
9) Then the video avi file is opened after the plot.
Errors:
- Undefined function 'writevideo'
Solution: The function must have uppercase 'V', and it is written as 'writeVideo'
- Invalid relation used
Solution: In the relation '*' was not given, the correct relation is 'x1=x0+l1*cosd(theta1);'
Results: