Forward kinematics of 2R Robo_Arm
AIM: TO SIMULATE THE FORWARD KINEMATICS OF A ‘2R ROBOTIC ARM’ USING MATLAB/OCTAVE.
OBJECTIVE:
- Write a program to get the positions of manipulator at different set of angles in matlab/octave.
- Creating plots for various conditions.
- Animating the gif file of all plots.
GOVERNING EQUATIONS AND OVERVIEW:
A robotic arm is a type of mechanical arm, usually programmable. The links of such a manipulator are connected by joints allowing either rotational motion or translational displacement.
L1=length of link1 Ө1=angle of link1 with base (in degree)
L2=length of link2 Ө2=angle of link2 with base (in degree)
For finding the position of manipulator:
Step-1> calculate the position of link1-
Start at- (0,0)
End at- (L1cosӨ1, L1sinӨ1) let assume as (x1, y1)
Step-2> calculate the position of link2-
Start at- (L1cosӨ1, L1sinӨ1) or (x1, y1)
End at- (x1+L2cosӨ2, y1+L2sinӨ2)
BODY OF CONTENT:
Firstly, write the program with the content as shown above for a fixed position of Ө1 and Ө2.
% A program for Forward kinematics of 2R robotic arm manipulator
close all
clear all
clc
% Inputs
l1=1;
l2=0.5;
theta1=45;
theta2=30;
%cooedinates
x0=0;
y0=0;
x1=l1*cosd(theta1);
y1=l1*sind(theta1);
x2=x1+l2*cosd(theta2);
y2=y1+l2*sind(theta2);
%plotting
line([x0 x1],[y0 y1],'linewidth',3,'color','b')
line([x1 x2],[y1 y2],'linewidth',3,'color','r')
Here, Ө1=45, Ө2=30 (all angles are in degree)
‘b’ is for blue color line for link1
‘r’ is for red color line for link2
As we write the program as shown above then we get the plot as:
The above program is for 2R robotic arm manipulated with fixed values of Ө1 and Ө2.
To write the program for various values of angles we have to use “For_loop”.
% A program for Forward kinematics of 2R robotic arm manipulator with for loop
close all
clear all
clc
% Inputs
l1=1;
l2=0.5;
theta1=linspace(0,90,6);
theta2=linspace(0,90,6);
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([-0.1 1.5 0 1.5])
pause(0.3)
ct=ct+1;
M(ct)=getframe(gcf);
Text=sprintf("Roboarm%d.png",ct);
saveas(1,Text)
end
endfor
Movie(M)
videofile=VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
write(videofile,M)
close(videofile)
EXPLANATION OF PROGRAM:
- Firstly, assign the values of L1 and L2.
- With the use of linspace, we are writing an array of angles between 0 to 90 degrees. (here 6 values are assigned)
- With the use of for loop we are able to get the results for different angles.
- Here, I used ‘octave’ so to save the file as Animated GIF, we have to save all plots as image file by the command shown in the program.
- To create the GIF file use ‘Imagemagick’ application.
OUTPUT: Go through the link for output of the program as a mp4 file-
ERRORS:
There are various types of error in the program that I faced through that are as-
1.Got the plot as straight line
2. forgot to define THETA1
3.got multiple plots in a single graph
CONCLUSION:
- Got the various positions of link2 at different values of the angles Ө1 and Ө2.
- The Animated motion clears the picture of all the plots at the same time.