2R ROBOTIC ARM STIMULATION USING OCTAVE
AIM:
A PROGRAM IN OCTAVE TO STIMULATE THE FORWARD KINEMATICS OF A 2R ROBOTIC ARM AND CREATE AN ANIMATION GIF OF THE PLOT
INTRODUCTION:
The manipulator in this kinematic linkage helps to define the workspace of robotic arm where it can reach and complete its specified job assigned to it. This type simple kinematics is a part of the industries using full automation which is obtained with the help of programming languages such as MATLAB, OCTAVE, PYTHON, etc.
GOVERNING EQUATIONS:
Fig.1. Two Joints Robotic Arm
where,
Inputs are:
theta1 = Angle made by arm1 with horizontal
theta2 = Angle made by arm2 with horizontal
L1 = Length of arm1
L2 = Length of arm2
(x0, y0) = Initial points for link1
(x1, y1) = Initial points for link2 and ending points for link1
(x2, y2) = Ending points for link2
Thus, the values of these points generate equations like -
Basically, the co-ordinates are:
(x0, y0) = 0 (starting position at base, i.e. origin)
x1 = L1*cosd(theta1)
y1 = L2*sind(theta1)
x2 = x1 + L2*cosd(theta2)
y2 = y1 + L2*sind(theta2)
Here, ‘d’ is used to tell the programme that the theta values are in ‘degree’ otherwise it will take those values in ‘radians’.
OBJECTIVES:
1) WRITE A PROGRAMME TO STIMULATE THE 2R ROBOTIC ARM
2) TO CREATE ANIMATION GIF OF THE ROBOTIC ARM
Let us assume the values of those links,
L1 = 1m
L2 = 0.5m
theta1 and theta2 values can lie between from 0 to 90
Common commands used in starting of every program-
Clear all command for clearing workspace
Close all command for closing plots and figures in background
Clc command for clearing the command window
Figure1.1. Flowchart for animation
PROGRAMS:
1) OCTAVE PROGRAM1- TO STIMULATE 2R ROBOTIC ARM
clear all
close all
clc
%Inputs
L1 = 1;
L2 = 0.5;
%Angles for the movement of the arm
theta1 = linspace(0,90,4);
theta2 = linspace(0,90,4);
ct = 1
%Iteration for i and j each having 10 values
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
%Coordinates
x0 = 0;
y0 = 0;
x1 = L1*cosd(THETA1);
y1 = L1*sind(THETA1);
x2 = x1 + L2*cosd(THETA2);
y2 = y1 + L2*sind(THETA2);
%Plotting
hold on
plot([x0 x1],[y0 y1],'linewidth',3,'color','b')
plot([x1 x2],[y1 y2],'linewidth',3,'color','r')
pause(0.3)
ct = ct+1;
endfor
endfor
Fig.1.2. Plot1 showing change in theta2 for each value of theta 1
RESULT- This shows for each value of theta1, theta2 changes.
Here we can see the movement of both the links for their different values.
The above program gives us the idea about the change in values of theta affects the movement of robotic arm but this doesn't give us the proper stimulation of robotic arm.
Thus, we need to make some changes in the above program to create the stimulation of the robotic arm.
Most of the command will remain same, we will see changes under ‘%Plotting’ where,
‘ plot([x1 x2],[y1 y2],'linewidth',3,'color','r') ‘will be deleted
instead we create a new command i.e.
‘ plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3) ‘
‘ hold on ‘command is also deleted to get the movement of two links otherwise it will show the same result as above with random colors given to both the links.
OCTAVE PROGRAM2- ANIMATION OF 2R ROBOTIC ARM
clear all
close all
clc
%Inputs
L1 = 1;
L2 = 0.5;
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
ct = 1
%Iteration for i and j each having 10 values
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1: length (theta2)
THETA2 = theta2(j);
%Coordinates of arm1 and arm2
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.03)
ct = ct+1;
endfor
endfor
Explanation:
Line1- Defining the length of arm1 i.e. L1 = 1m
Line2- Defining the length of arm2 i.e. L2 = 0.5m
As we need multiple values for theta1 and theta2 for animation, we use ‘linspace’ command. This command gives equal spacing between two values.
Line3- Set of values is given to theta1 as an array having 10 values between 0 to 90
Line4- Set of values is given to theta2 as an array having 10 values between 0 to 90
Line5- Counter with starting value assigned as 1
Line6- We use ‘for-loop’ command for iteration of ‘i' from 1 to 10, ‘i' represents the number of values in theta1 which is 10.
Line7- We use loop counter for accessing the value of theta1 and theta2, as each value of arm1, arm2 can have multiple positions. THETA1 = theta1(i)
Line8- We use ‘for-loop’ command for iteration of ‘j' from 1 to 10, ‘j' represents the number of values in theta2 which is 10.
Line9- We use loop counter for accessing the value of theta1 and theta2, as each value of arm1, arm2 can have multiple positions. THETA2 = theta2(j)
Line10- Coordinates at start of arm1 where, x0 = 0
Line11- Coordinates at start of arm1 where, y0 = 0
Line12- Coordinates at end of arm1 and starting of arm2 where,
x1 = L1*cosd(THETA1)
Line13- Coordinates at end of arm1 and starting of arm2 where,
y1 = L1*sind(THETA1)
Line14- Coordinates at end of arm2 where, x2 = x1 + L2*cosd(THETA2)
Line15- Coordinates at end of arm2 where, y2 = y1 + L2*sind(THETA2)
Line16- Plotting all the coordinates and giving it linewidth of ‘3’
Line17- Giving location of x-axis and y-axis
Line18- Pause command is used to cease the animation from jumping between the figures
Line19- For incrementing the counter with +1 value
Line20- End ‘for-loop’ command for ‘j’
Line21- End ‘for-loop’ command for ‘i’
OCTAVE PROGRAM3- CREATING GIF ANIMATION OF ROBOTIC ARM
clear all
close all
clc
%Inputs
L1 = 1;
L2 = 0.5;
%Angles for the movement of the arm
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
ct = 1
%Iteration for i and j each having 10 values
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
%Coordinates of arm1 and arm2
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.03)
%Creating gif animation
t_span = 0.01
printf('creating GIF-Progress...%d/%d\n',i,length(t_span));
img = print ('-RGBImage');
imwrite(img,'animation.gif','DelayTime',0.005,'Compression','bzip','Writemode','Append');
ct = ct+1;
endfor
endfor
Explanation:
All the commands remain same but for creating gif animation in octave, following commands are used-
printf('creating GIF-Progress...%d/%d\n',i,length(t_span));
img = print ('-RGBImage');
imwrite(img,'animation.gif','DelayTime',0.005,'Compression','bzip','Writemode','Append');
In '%Creating gif animation'
Line1- A new plot is obtained for each value of t_span, i.e. 0.01
Line2- The statement helps us to keep the track of GIF creation progress
Here, printf is used to print particular string in command window
%d is format specifier
\n creates a new line every time it gets executed
i is a loop variable
length() returns total number of elements inside an array
Line3- The print command saves the most recent plot generated.We are storing the image inside the variable 'img'
Here, ' RGBImage' this returns the plot image in the RGB format. The image is represented by a matrix M by N by 3 where each of the 3-vectors corresponds to the
red, green, and blue intensities of each pixel.
Line4- Here, imwrite()- This is used to write images in various file format
img- The image to be written into the gif file is stored inside img
animation.gif- Name of the output gif file
DelayTime- This is used to specify the delay between each frame
Compression- The raw image is a big file hence we need to compress to bring each image into minimum size as it is attached to gif file
Writemode- Specifies if img is appended to the file
Append- Used to attach images one by one into gif file
Fig.1.3. GIF creation progress
ANIMATION LINK: https://drive.google.com/file/d/1LdqUlDJZUwLKWA50yNDChFIbUU02z6n5/view?usp=sharing
CONCLUSION: A PRACTICAL UNDERSTANDING ABOUT THE FUNCTIONING AND PROGRAMMING OF FORWARD KINEMATICS OF ROBOTIC ARM IS GAINED BY STIMULATION ON OCTAVE.