You are on page 1of 23

CONTROL THEORY

SIMULATION OF A LINEARLY INVERTED PENDULUM MODEL FOR


THE STABILIZATION OF A SEGWAY

AUTHORS:

ADRIÁN BUESTÁN
KEVIN CARPIO
LUIS ERRAEZ
LEANDRO ILLESCAS
PEDRO MONCAYO
 
Objectives

General objective
Simulate an inverted pendulum controller with the Matlab program for a segway
putting into practice the topics learned in the lecture.

Specific objectives
Understand the behavior of an inverted pendulum system and translate it into simulation
Obtain a mathematical modeling that allows us to know the behavior of the inverted pendulum
Use Matlab as a simulation program to check the mathematical analysis carried out.
Obtain the different graces through simulation to verify their behavior

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Project phases

Obtaining a
Study of the behavior Use Matlab as a Obtaining the
mathematical
of an inverted simulation program different graphics
modeling that allows
pendulum system to check the through simulation
us to know the
and translate it into mathematical to verify their
behavior of the
simulation analysis performed. behavior
inverted pendulum

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Methodology and system analysis
Main equations
 1.
2.

Matching equations.
𝑥𝑑2 𝑀𝑑2 𝑥
= ൫𝑥1𝑠𝑖𝑛ሺ𝜃ሻ൯= 𝜇 − 2
𝑑𝑡 2 𝑑𝑡
𝑑2 𝑀𝑑2 𝑥
𝑚 ∗ sin⁡(𝜃) ሺ1 cosሺ𝜃 ሻሻ = 𝜇cos⁡(𝜃) − 2 cos⁡(𝜃) − 𝑚𝑔sin⁡(𝜃)
𝑑𝑡 𝑑𝑡
𝑚𝑑2 𝑀𝑑2 𝑥
ሺ𝑥 + 1 sinሺ𝜃ሻሻ = 𝜇 −
𝑑𝑡 2 𝑑𝑡
𝑑2 𝑀𝑑2 𝑥
𝑚 ∗ sin⁡(𝜃) 2 ሺ1 cosሺ𝜃ሻሻ= 𝜇cos⁡(𝜃) − cos⁡(𝜃) − 𝑚𝑔sin⁡(𝜃)
𝑑𝑡 𝑑𝑡

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Methodology and system analysis

BY DERIVING WE GET.
𝑚𝑥ሷ− m1 sinሺθሻθ2ሶ+ m1 cosሺθሻθሷ= 𝜇 − 𝑀𝑥ሷ

−m1 sinሺθሻcosሺ𝜃ሻθ2ሶ− m1 sin2 ሺθሻθሷ= 𝜇 cosሺ𝜃ሻ− 𝑚𝑔𝑠𝑖𝑛(𝜃)

As you can see it is a 2nd degree system so it has 4 state variables


these could be “θ, θ ̇,x, x ̇”, then I must eliminate θ´´ and x ̈

−𝜇 cosሺ𝜃ሻ+ ሺ𝑚 + 𝑀ሻ𝑔𝑠𝑖𝑛ሺ𝜃ሻ− 𝑚1 sinሺ𝜃ሻcos⁡(𝜃)θ2ሶ


𝜃ሷ=
𝑀1 + 𝑚1𝑠𝑖𝑛2 (𝜃)

𝑚1𝑠𝑖𝑛ሺ𝜃ሻθ2ሶ− 𝑚𝑔𝑠𝑖𝑛ሺ𝜃ሻcosሺ𝜃 ሻ+ 𝜇
𝑥ሷ=
𝑀 + 𝑚𝑠𝑖𝑛2 (𝜃)

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Methodology and system analysis
Forming the state variables
𝐿൫𝑀 + 𝑚𝑠𝑖𝑛2 ሺ𝜃ሻ൯𝜃ሷ= 𝜇 cosሺ𝜃 ሻ+ ሺ𝑚 + 𝑀ሻ𝑔𝑠𝑖𝑛ሺ𝜃ሻ− 𝑚1 sinሺ𝜃ሻcos⁡(𝜃)θ2ሶ

൫𝑀 + 𝑚𝑠𝑖𝑛2 ሺ𝜃ሻ൯𝑥ሷ= 𝑚1𝑠𝑖𝑛ሺ𝜃ሻθ2ሶ− 𝑚𝑔𝑠𝑖𝑛ሺ𝜃ሻcosሺ𝜃ሻ+ 𝜇

𝑥1 = 𝑥 𝑥1ሶ= 𝑥ሶ
𝑥2 = 𝑥ሶ 𝑥2ሶ= 𝑥ሷ

𝑥3 = 𝜃 𝑥3ሶ= 𝜃ሶ

𝑥4 = 𝜃ሶ 𝑥4ሶ= 𝜃ሷ

THEN WE GET
𝑥1ሶ= 𝑥2
𝑚1𝑠𝑖𝑛ሺ𝑥3 ሻ𝑥4 2 − 𝑚𝑔𝑠𝑖𝑛ሺ𝑥3 ሻcosሺ𝑥3 ሻ+ 𝜇
𝑥2ሶ=
𝑀 + 𝑚𝑠𝑖𝑛2 (𝑥3 )
𝑥3ሶ= 𝑥4
−𝜇 cosሺ𝑥3 ሻ+ ሺ𝑚 + 𝑀ሻ𝑔𝑠𝑖𝑛ሺ𝑥3 ሻ− 𝑚1 sinሺ𝑥3 ሻcos⁡(𝑥3 )𝑥4 2
𝑥4ሶ=
𝑀1 + 𝑚1𝑠𝑖𝑛2 (𝑥3 )

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Methodology and system analysis
We determine some conditions of angles
𝑥1 = 𝑥2 = 𝑥3 = 𝑥4 = 𝑜
−𝑚𝑔𝑥3 𝜇
𝑥2ሶ= +
𝑀 𝑀
ሺ𝑀 + 𝑚ሻ𝑔𝑥3 𝜇
𝑥4ሶ= +
𝑙𝑀 𝐿𝑀

 
Approximation when the value is
very small.
𝑋1ሶ 0 1 0 0 𝑋1 0
ሶ 0 0 −𝑚𝑔/𝑀 0 𝑋2 1/𝑀‫ې ۍ‬
൦𝑋2൪ = ൦ ൪= ൦ ൪+ 0‫ ێ‬µ ‫ۑ‬
𝑋3ሶ 0 0 0 1 𝑋3 ‫ێ‬1 ‫ۑ‬
𝑋4ሶ 0 0 ሺ𝑀 + 𝑚ሻ𝑔/𝑀 0 𝑋4 −‫ے 𝑀𝐿ۏ‬

Replace X1 = 0, X2 = 0, X3 = 0, X4 = 0, because
we are going to work at the equilibrium point.
X3 ≈ sin (X3) when x3  0
𝑋1
𝑥 1 0 0 0 𝑋2
ቂ ቃ= ቂ ቃ= ൦ ൪
 0 0 1 0 𝑋3
𝑋4

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Controllability of the system.
Q = ሾ𝐵 𝐴𝐵ሿ
Transfer functions.
0 1 0 0 0 1/𝑀 µ(S) = 𝐶(𝑆𝐼 − 𝐴)−1 𝐵 + 𝐷
‫ۍ‬ ‫ې ۍ ې‬
0 0 −𝑚𝑔/𝑀 0 1/𝑀‫ێ‬ 0
𝐴𝐵 = ൦ ൪ =‫ێ ۑ‬1 ‫ۑ‬
0 0 0 1 0‫ێ‬ ‫ ۑ‬− 𝐿𝑀‫ۑ ێ‬ 𝑆 −1 0 0 0
1 ‫ې ۍ‬
0 0 ሺ𝑀 + 𝑚ሻ𝑔/𝑀 0 −‫𝑀𝐿ۏ‬ ‫ۏ ے‬0 ‫ے‬ 1 0 0 0 0 𝑆 𝑚𝑔/𝑀 0 1/𝑀‫ۑ ێ‬
µ(S) = ቂ ቃ൦ ൪
0 0 1 0 0 0 𝑆´ −1 0‫ۑ ێ‬
1
0 0 −ሺ𝑀 + 𝑚ሻ𝑔/𝑀 𝑆 −‫ے 𝑀𝐿ۏ‬
0 1
1‫𝑀ۍ‬ ‫ې‬
𝑀‫ ێ‬0 ‫ۑ‬
Q=
0‫ ێ‬− 1 ‫ۑ‬    =
‫ێ‬1 ‫ۑ‬
−‫ ۏ‬0𝐿𝑀 ‫ے‬
𝐿𝑀
 
It is a 2x4 system; the determinant cannot be determined, it =
is determined that it cannot be controllable.
 

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Code Matlab

After the investigation carried out, on the inverted pendulum, it was possible to establish the different equations of
motion, both of the base, and thus be able to determine the angle of inclination that the pendulum will obtain.
Therefore, the simulation is carried out in Matlab, establishing the initial parameters previously established and the
data that will be used in this exercise.

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Code Matlab

Once you have established the limits for the simulation, such as the mass of the pendulum, the mass of the base,
the length of the pendulum and the inertia on the wheels, the different state matrices can be established for the
respective simulation.
As can be seen in the graph, the dynamics of the System has been improved since better control is obtained.

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Code Matlab

For the next one, we proceed to carry out the analysis on the locus of the roots

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Code Matlab

For a better analysis, the initiative is taken to make the comparison of the three images that
we visualize, on the response of the different state variables for open loop and closed loop,
and in the same way with the response of the transfer function, where the axes to be
compared are between the angle of the pendulum and the position of the base.

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Simulation, Controller animation
Simulink

In the part of the simulation and Simulink, the procedure carried out previously where the transfer function is used to
obtain the Angle and the position of the system is reduced, also with the help of the PID control to obtain the 2 graphs.

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Simulation, Controller animation
Parameters, Simulink

Here we have the pid block and the main parameters to


consider are these three: the proportional, integral and the
derivative of the gains, each of them has an effect on the
response of the system
Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices
Simulation, Controller animation
Total simulation, Simulink

Here we have the total structure, the joint of revolution that gives us the
angle of inclination provided by the rotary joint, also the force in the
prismatic joint that will be provided by input and the movement will be
carried out automatically.

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Simulation, Controller animation
Structure Chasis, Simulink

Here we have the structure of the chassis made up of 3 parts that are part
of the chassis and the 4 supports in the corners of our segway, these are
joined with rigid joints since it allows us to put the location of each piece
and with which it is going to be joined.

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Simulation, Controller animation
Structure Wheel, Simulink

In the image we have both the left and right rim and that is joined with a rigid joint and our axis that allows
it to rotate.

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Simulation, Controller animation
Animation, Simulink

In the image we see our animation finished with rigid structures and each one fixed in its
position, if we want to change colors we must enter in each part and we can do both the
colors and the location

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Simulation, Controller animation
Results.

In the following image we can see the auto-adjustment option in our animation, we can
establish the desirable attributes of our response and auto tune will generate the appropriate
pid gains that gives us more control of the segway and it would be a balanced one.

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Now the adjustment of the pid parameters that must be fine-tuned
to give us the desired behavior in the established timeThese three
parameters, the proportional, the integral and the derivative of the
gains, each one of them has an effect on the observed response of
the system.We set the pro-ratio gain to two and the others to zero,
but the oscillation continues to increase and the segway will fallWe
can reduce the oscillation a little by increasing the derived gain 0.01
but the oscillations are reduced and the system is stable but the
measurements of the inclination angle indicate. However, the
segway still moves to the leftThis constant stage error can be
managed by increasing the integral gain but also in simulink we have
an option that is known as self-adjusting and it will give us more
control in our segway

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Conclusions.

• The angle of inclination had to be limited, because at the time of carrying out the
mathematical modeling of the system the equations were linearized, which means
that the angle of inclination had to be done, it always approaches zero, therefore
this Angle must always be zero.
• We conclude that the most direct application of the inverted pendulum is a segway
since it shares the principle of operation exactly, for which we go to simulate and
perform the corresponding calculations of operation of the segway.
• It was demonstrated that the application of a method that is based on principles
for optimizing the gain values of a PID controller makes it possible to present a new
form of unconventional solution to control problems; in addition to finding a
variety of optimal values for these parameters, giving the option of choosing the
one that best suits your design requirements.

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Recomendations.

• It is recommended that the system have the least number of oscillations, if the
system has many oscillations when trying to stabilize the segway, it may not be
achieved and the system falls into instability
• In order to work with sensors, it is recommended to work with their
characteristic curves and take experimental data, which will help us to have
accurate calculations, and thus obtain an angle of inclination on which the
balance of the vehicle depends.

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices


Thank you for your attention.

Universidad Politécnica Salesiana Ingeniería Automotriz Claustro Sistemas Automotrices

You might also like