## 2R Robotic Arm Simulation using MATLAB

Robotic Arm - Forward Kinematic  Motion

Here 2R stands for "Two Rotational" Joints for an two link Kinematic Chain.

Let us consider,

length of link 1, l1=1 unit

length of link 2, l2=0.5 unit

To find the workspace/final position of the above defined Robot, we need to find the positions of link1 and link2 coordinates and positions ietheta1 and theta2

(x0,y0)=(0,0)                                                                  {1}

{2}

{3}

{fig 1}

The simulation code is performed via OCTAVE and enclosed below,

CODE:

% forward kinematics of 2R robotic arm manipulator
clear all
close all
clc

% inputs
l1=1;
l2=0.5;
theta1=linspace(0,70,10);
theta2=linspace(0,110,10);

ct=1
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
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;

end
end


CODE EXPLANATION

The matlab code begins with the clear all, close all, clc to clear the other computed data in the command window as well in workspace to avoid overwriting or manipulating the required values.

%inputs

(l1 &l2) : The Robtic arm which considered here in this problem has two links whose length are taken as 1 & 0.5 respectively.

(theta1 & theta2) :Since these are connected through the Rotational Joints, they can be constrained with an angle, which in my case the lower arm (link1) is limited to 70 degree and upper arm (link2) to 110 degrees wrt. Horizontal plane

linspace is used to define the number of actions to be performed within the limits of defined angle theta, also the simulation smoothness is proportional to linspace value.

ct stands for counter, which here in this program it refers to the 1st iteration of inputs ct=1,

ct=ct+1 at the end supports the next set of iterations untill the last to simulate.

The for loop has defined to support the iterations ie; for every value of theta1 and theta2, there exists a new function THETA1 and THETA2 respectively

Now, THETA1 & THETA2 are new set of values (10 each defined in l"inspace") in the defined limits of 0degree-70degree and 0degree-110degree

for every value of THETA for loop performs simulation and ct provides the source of next iteration upto last value.

%coordinates

The coordinates for the lower arm/link1 is considered as initial position followed by which the coordinates for the @Joint and the @End  is calculated as shown in (fig1.)

The Trignometric functions by default takes the inputs as 'radians', to change it to degrees 'cosd' &'sind' are used.

%plotting

The plot command helps to plot the simulated value in a 2D graph,

The 1st two set of values in plot command defines the link1, whereas the next 2 set of values defines the  link2,

"linewidth" is used to assign the thickness (3) to the links,

axis is used to define the limiting values on both axis of the graph to have a simulation well within the frame, [Xa Xb Ya Yb]

The pause command is used to have a interval between frames (0.03s)

the for loop is terminated using end command.

The program is executed and no errors were found

The values of inputs, coordinates and math are obtained and as follows

But the plot command in the above program has taken the "linewidth" only for the link2, whereas the link1 value has been taken by default (refer fig. below)

This was fixed by editing the plot comand as follows,

CODE CORRECTION

plot([x0 x1],[y0 y1],'linewidth',3,[x1 x2],[y1 y2],'linewidth',3)

This program was also executed for shorter values in "linspace" command and using "sprintf" & "saveas" in OCTAVE, different frames were obtained which were later stiched together to get an .gif file.

...
...continued

%plotting
plot([x0 x1],[y0 y1],'linewidth',3,[x1 x2],[y1 y2],'linewidth',3)
axis([-0.1 1.5 0 1.5])
pause(0.3)
text=sprintf('test%d.png',ct);
saveas(gca,text);
ct=ct+1;
end
end

The .gif file of compiled frames is enclosed below

### Solving Second Order using PYTHON GANESH C J · 2019-10-17 17:37:29

Transient Behaviour of a Simple Pendulum A pendulum is a body suspended from a fixed support which swings freely back and forth under the influence of gravity. When a Pendulum is displaced from its initial position, it is subjected to a restoring force due to grav Read more

### Otto Cycle Simulation using PYTHON GANESH C J · 2019-10-16 15:26:25

AIR STANDARD CYCLE : OTTO CYCLE Otto Cycle is an Constant Volume thermodynamic Cycle typically used in Spark Ignition Engines commonly found in Automobiles. A typical Otto cycle consists of Pair of Isentropic Processes which are reversible Adiabatic. Pair of Isoch Read more

### Flow over a Bicycle using PYTHON GANESH C J · 2019-10-09 12:05:43

FLOW OVER A BICYCLE For a cyclist, when cycling there affects a several factors which decides the velocity and Potential Energy consumed for a cyclist. The Aerodynamic study shows that apart from the thrust force of the cyclist, there exists a opposing force called as Read more

### Forward Kinematics of 2R Robotic Arm using PYTHON GANESH C J · 2019-10-09 12:03:40

2R  Robotic Arm - Forward Kinematic  Motion Here 2R stands for "Two Rotational" Joints for an two link Kinematic Chain. Let us consider, length of link 1, l1=1 unit length of link 2, l2=0.5 unit To find the workspace/final position of the a Read more

### Rankine Cycle Simulation using MATLAB/OCTAVE. GANESH C J · 2019-10-02 08:16:24

RANKINE CYCLE SIMULATION Rankine Cycle is a typical Steam Cycle which continuously converts the energy stored in the fuel, into useful Mechanical work/Shaft work and ultimately into Electricity. The working fluid is Water which is sometimes in a Liquid state and som Read more

### Performing Genetic Algorithm in MATLAB/OCTAVE & Finding Global Maxima of Stalagmite Function GANESH C J · 2019-09-30 11:33:34

GENETIC ALGORITHMS Objective : To write a code in MATLAB to optimise the stalagmite function and find the global maxima of the function. A Genetic algorithm is a search heuristic that is inspired by Charles Darwin’s theory of natural evolution. "S Read more

### FILE PARSING OF NASA's THERMODYNAMIC DATA in MATLAB GANESH C J · 2019-09-29 16:41:33

FILE PARSING OF NASA's THERMODYNAMIC DATA Objective : To extract the thermal coefficients from the NASA's .dat file and to write a MATLAB program to calculate the Sprcific Heat, Enthalpy & Entropy of each Element present in the file. THERMO.dat file to be extrac Read more

### Curve Fitting in MATLAB GANESH C J · 2019-09-26 12:32:05

CURVE FITTING Objective : To write a MATLAB/OCTAVE program in order to perform Curve Fitting Curve fitting is the process of constructing a curve, or mathematical function, that has the best fit to a series of data points, possibly subject to constraints. Curve f Read more

### Solving Second Order ODE in OCTAVE GANESH C J · 2019-09-22 18:42:40

Transient Behaviour of a Simple Pendulum A pendulum is a body suspended from a fixed support which swings freely back and forth under the influence of gravity. When a Pendulum is displaced from its initial position, it is subjected to a restoring force due to grav Read more