Forward kinematics of a 2R Robotic Arm
AIM: To stimulate the forward kinematics of a 2R Robotic Arm.
Theory:
Forward kinematics refers to process of obtaining position and velocity of end effector, for the given known joint angles and angular velocities. It uses the kinematic equations of a robot to compute the position of the end-effector from specified values for the joint parameters. It is a method in 3D computer graphics for animating models. Here, it is used to create the animation video of the 2R Robotic Arm.
The schematic diagram of the 2R Robotic Arm is shown below:
The above figure is the schematic diagram of the 2R Robotic Arm. The different parts of the 2R Robotic Arm are:
- Base
- Rotational joint
- Link
- Manipulator
In the above figure, we can see the base of the Robot and the first link is attached by rotaional joint.
As the link 1 is attached to the base of the Robot, therefore the starting value of link 1 is
x0 = 0
y0 = 0
Ending value of link 1 and starting value of link 2 are same which are calculated mathematically.
x1 = l1*cosd(THETA1)
y1 = l1*sind(THETA1)
Similarly, ending value of link 2 is also calculated considering geometry of 2R Robot, mathematically.
x2 = x1 + l2*cosd(THETA2)
y2 = y1 + l2*sind(THETA2)
where
l1= length of the first link
l2= length of the second link
The code below is executed in Octave.
%A program to stimulate the forward kinematics of a 2R Robotic Arm.
clear all
close all
clc
%Input
%Length of the links l1, l2
l1 = 1;
l2 = 0.5;
%Angle between links and xaxis
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);
%Starting value of the link 1
x0 = 0
y0 = 0
%Ending value of link 1 and starting value of link 2
x1 = l1*cosd(THETA1)
y1 = l1*sind(THETA1)
%Ending value of link 2
x2 = x1 + l2*cosd(THETA2)
y2 = y1 + l2*sind(THETA2)
%plotting
plot([x0 x1],[y0 y1],'linewidth',3,'color','b')
hold on
plot([x1 x2],[y1 y2],'linewidth',3,'color','g')
hold off
axis([-0.1 1.5 0 1.5])
file_text=sprintf('armanimation%05d.png',ct)
saveas (gca, file_text)
pause(0.03)
ct=ct+1;
end
end
Movie(M)
videofile = VideoWriter('forward_kinematics_of_a_robotic_arm.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Explanation of the code
This program is written in Octave to stimulate the forward kinematics of 2R Robotic Arm. The inputs for this program are lengths of arm 1&2, angle between the links and the x-axis, starting and ending co-ordinates of link 1&2.
To have multiple values of theta1 and theta2 linespace command and for loop are used.
Here, in this program linespace command gives 10 different values between 0 and 90.
The part of this program is illustrated below:
for i= 1:length(theta1)
THETA1 = theta1(i);
for j= 1:length(theta2)
THETA2 = theta2(j);
Here, for each value of theta1 (or each position of link 1) , link 2 can take the multiple position which depends on the value of theta2.
As the link 1 is attached to the base of the Robot, therefore the starting value of link 1 is
x0 = 0
y0 = 0
Ending value of link 1 and starting value of link 2 are same which are calculated mathematically.
x1 = l1*cosd(THETA1)
y1 = l1*sind(THETA1)
Similarly, ending value of link 2 is also calculated considering geometry of 2R robot mathematically.
x2 = x1 + l2*cosd(THETA2)
y2 = y1 + l2*sind(THETA2)
Plot command is used for graphical representation. Hold on command allows for multiple plots on the same figure window whereas hold off will remove this property so that when we get to next loop, the plot for only those specific angles are visible.
In octave saveas command is used to save all the figures. 'gca' inside the parenthesis stands for get current axes and file_text is the variable in which all images will be saved. After that file_text becomes an array of images. 'sprintf' is used to give each file a unique name.
'ct' is a counter variable.
'armanimation%05d' is a file name with which each figure will get saved and %05d represents that the file will get saved with the file name which will be having 5-digits.
.png is the file formate.
The above figures shows the output file of the animation created by the help of command prompt.
Error faced while programming:
While programming , I faced some errors. They are described below:
#
The above figure shows the error occured in the code.
plot([x0 x1],[y0 y1],'linewidth'3'color','b') {ERROR}
The above line has syntax error.
The arguments to any funcrtion should be seperated by a comma. Here linewidth and 3 should be separated by comma.
plot([x0 x1],[y0 y1],'linewidth',3,'color','b') { error CORRECTED}
#
The above figure shows the error occured in the code in OCTAVE.
M(ct) = getframe(gcf); {gives ERROR in OCTAVE}
As I am usinng Octave getframe command cannot be used.
file_text=sprintf('armanimation%05d.png',ct) {error CORRECTED in OCTAVE}
saveas (gca, file_text)
OBJECTIVE
The main objective of the project is to create the animation video of the 2R Robotic Arm to analyze the different joint parameter.s In the above program, the value of theta1 and theta2 are interrelated.The working o the liks of the 2R Robotic Arm can be analysed easily by the help of this program in OCTAVE.
CONCLUSION:
Hence, the above program gives the output of the animation video of the 2R Robotic Arm which helps us to initially analyse the movement of the links of the Robot. This reduces the error in the Robot design.
While programming it is necessary to keep in mind which software we are going to use (Matlab or Octave). The same programming code may thow error if executed in different software. The above program is executed in Octave.
THE LINK OF THE OUTPUT ANIMATION VIDEO OF THE ABOVE PROGRAM IS GIVEN BELOW: