Project

To simulate the motion of a 2-R robotic arm with respect to forward kinematics and obtain the integrated motion as a combination of all individual frames of position.

AIM

To simulate the motion of a 2-R robotic arm in forward kinematics through Matlab/Octave programming and obtain the animated plot of the integrated motion.

GOVERNING EQUATIONS

The governing equations for this simulation programming are the ones which are obtained theoretically for the forward kinematics of the robotic arm

Where,

L1 – Length of link 1

L2 – Length of link 2

[T1,T2] – Angles made by the first and second link with respect to the horizontal respectively.

The co-ordinates of the links with respect to their motion is given by

`X1= L1*cos(theta1)`

`Y1=L1*sin(theta1)`

`X2=X1+(L2*cos(theta2))`

`Y2=Y1+(L2*sin(theta2))`

Where,

[x0,y0] – Initial position of the first link which is generally considered [0,0]

[x1,y1] – Co-ordinates of the farther end of the first link which is the same as the co-ordinates of the starting point of the second link

[x2,y2]- Co-ordinates of the farther end of the second link

OBJECTIVES OF THE PROJECT

The major objective of this project is to obtain the various frames of motion of the two links of the 2-R robotic arm and combine them together to provide a simulated motion of the arm in forward kinematics. This is done through Octave or Matlab programming using for loops for repetitive iterations of movement of the arm.

PROGRAMMING

The following program is written in OCTAVE.

The explanation of the used commands and codes in the program are as follows:

  • L1=1;

L2=0.5; - These two are the standard inputs of the length we are assuming in this program. In this program, the animation will be done based on the varying angles of the two links.

  • T1=0:9:90; - This command is used to vary the first joint angle, ie, the angle between the first link and the horizontal. In this program, increments of 9 are given to the joint angle between 0 and 90 degrees.
  • T2=0:9:90; - This command is also used to give similar increments to the second joint and the horizontal, which is the second joint angle.
  • c=1; - ‘c’ is a variable initially assigned the value of 1. The main function of this variable to get the various frames that are obtained while running the program in a progressive order so that the animation can be made in a continuous and progressive manner.
  • for i=(1:length(T1))

T_1=T1(i); - The first ‘for’ loop is used to vary the angle of the first link during each iteration. The for loop runs from 1 till the number of quantities that are represented by T1, which amounts to 10. Another variable,T_1 is assigned to hold the value of ‘i’ with respect to T1 during each iteration for calculation purpose.

  • for j=(1:length(T2))

T_2=T2(j); - The second ‘for’ loop is used to vary the angle of the second link during each iteration at the same time when the first link has a constant value during one iteration. The nested ‘for’ loop is precisely being used for this reason so that the second link motions can be observed at various angles while the first link is set at a particular position. The for loop runs from 1 till the number of quantities that are represented by T2, which amounts to 10. Another variable,T_2 is assigned to hold the value of ‘i’ with respect to T2 during each iteration for calculation purpose.

x0=0;

y0=0;

x1=L1*cosd(T_1);

y1=L1*sind(T_1);

x2=x1+(L2*cosd(T_2));

y2=y1+(L2*sind(T_2)); - the above lines represent the calculation of the co-ordinates of the two links with respect to the theoretical formulae explained in the governing equations part.

  • plot([x0 x1],[y0 y1],[x1 x2],[y1 y2]) – The plot command is used in octave to plot figures. In this case, a plot is obtained between the starting and ending co-ordinates of the two links of the robotic arm.
  • axis([-0.1 1.5 0 1.5]) – This command is used to specify the co-ordinates of the X and Y axes between which the figure must be obtained. It can be varied as per the wish of the programmer. In this case, The X axis ranges from -0.1 to 1.5 and the Y axis ranges from 0 to 1.5
  • textfile=sprintf('animation%05d.png',c) – After the plotting of figures, it is necessary to be able to save and store them so that they can be combined together in order to make a full animation.

1) The sprint command is used so as to obtain the output in the form of a string.

2) ‘animation’ is the name of the figures/images which are to be saved. Any name can be given.

3) %0.5d is used in order to save the images in 5-digit number schemes. This command is not required for small programs but in larger programs where the number of figures obtained is large, this command is really helpful in segregating them. ‘.png’ is an extension format in which the figures are saved ans ‘c’ is mentioned so as to save the figures in a successive sequence.

  • saveas(gca,textfile) – This command is used to save all the figures in one place .’gca’ stands for ‘Get Current Axis’. This command is used to ensure proper axis orientation of all the figures obtained.

pause(0.04) – This command is used to set a time frame in seconds between being able to view two or more successive images.

  • c=c+1; - The value of ‘c’ needs to change after each iteration by a value of 1 so as to progressively save all the figures for the animation.
  • End – Used to close the second ‘for’ loop.
  • End – Used to close the first ‘for’ loop.

ERRORS OBTAINED

1)

The above error is obtained when there is forceful stoppage of the running frames by the programmer. The command window displays the above message and stops further execution. The method to avoid this is to allow all the figures to display once the run command is given.

2)

The above message is obtained when the line c=c+1 is outside the ‘for’ loop. Due to this, all saved images bear the same name. The command window does not show an error and runs all the figures, but while animating them, it will become a tedious process as all files will bear the same name, and so the system fails to recognise the order of attaching figures and animation of simulating the arm will be a failure. The way of rectifying this mistake is to put the line inside the loop so that its value changes after every iteration and the saved images bear successive numbered names.

RESULT

The video animation of the robotic arm simulator can be found by clicking the YouTube link below:

https://youtu.be/kjfcaGPQN3Y

CODE

% Simulation of 2-R robotic arm in forward kinematics 

% Inputs of link lengths
L1=1;
L2=0.5;


% Joint angle inputs

T1=0:9:90;
T2=0:9:90;
c=1;

%For loops for repetitive iterations 
for i=(1:length(T1))
T_1=T1(i);

for j=(1:length(T2))
T_2=T2(j);

% Formulation of the co-ordinates

x0=0;
y0=0;

x1=L1*cosd(T_1);
y1=L1*sind(T_1);

x2=x1+(L2*cosd(T_2));
y2=y1+(L2*sind(T_2));


% Plots of the various frames

plot([x0 x1],[y0 y1],[x1 x2],[y1 y2])
axis([-0.1 1.5 0 1.5])

% Obtaining and saving all frames to create animation
textfile=sprintf('animation%05d.png',c)
saveas(gca,textfile)
pause(0.04)
c=c+1;
end
end
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.