Team C - Implementation of PID Control Using Inverted Pendulum
Team C - Implementation of PID Control Using Inverted Pendulum
Here in this task we had to analyze the Inverted pendulum in Laplace domain and
comment on it’s stability based upon the responses using OCTAVE.
• The Pendulum should be stabilized using PID such that it would stay in inverted
position even after some disturbance.
• The Pendulum should become stable at any other angle given as new position.
Challenges :
• Analyzing the Simple Pendulum & the INVERTED Pendulum using physical analysis (
Conservation of Momentum, Free Body Diagrams, Energy conservation, Work-
Energy theorem, Calculus, etc.)
• Initial conditions, Reference for THETA(angle), Sign Convention for Torque & angle.
These were the factors where a single sign change due to confusion would lead to
Unexpected Outputs & Unbounded responses.
• To have PID working was easier, but understanding what happens inside took
efforts.
WORKFLOW :
• Installing Octave :
• System Analysis :
The Pendulum seems to be a simple toy, but analyzing this toy mathematically can
take you to some highly Fascinating topics . This work led us through so many
webpages, articles, books and forums which showed the beauty of classical physics.
If the torque applies in the direction same as the theta then, it’s positive, else
negative. In case of Inverted Pendulum , theta is referred from topmost position.
U=mg(2L)
U=0
3
considering here :
τ is external torque
θ is angle of pendulum
˙ ¨
τ ( t ) −mgl sinθ ( t )−b θ ( t )=m l2 θ ( t )
˙
τ ( t ) =m l 2 θ̈ ( t ) +mgl sinθ ( t ) +b θ ( t )
d2θ dθ
τ ( t )=ml 2 +mgl sin θ ( t )+b
dt
2
dt
For approximating transfer function we consider initial conditions tending to zero here,
2 2
⇒ τ ( S ) =θ ( S ) (ml ( S )+b S +mgl )
(θ ( S )) 1
⇒ = 2 2
(τ ( S ) ) (m l S + b S +mgl)
We can see that in undamped case the system has poles on imaginary axis only i.e. it is
Marginally stable, so any deviation would cause it to sinusoidally oscillate upto infinite
time. Now,
Here we can observe that the system is still oscillating sinusoidally but the oscillations
tend to decrease under the effect of damping torque as the time passes. This suggests
that the damping causes the poles to slightly deviate towards left half plane.
Errors :
We would also like to show some of the errors that we faced during our learning process,
but after we solve them, they seem to be fun !!! Yet they teach you things that you don’t
find easily.
• When the direction of torque was confused, an opposite sign would cause a pole
pair on real axis with a pole on RHP. So the response would increase unboundedly.
• Another error would occur when we confuse with the sign of damping force, then
instead of damping, it will AMPLIFY the oscillations with time=>Unbounded.
We can see that a pole pair is parallaly displaced from the imaginary axis to the
RHF.
7
• Another Problem was occured when we set the damping coefficient higher than
needed, then it would not let the pendulum to oscillate so the response would be
like...
for b=0.01 ( even if the number is small, its large for the system )
• Understanding PID :
And this was the thing where we had to start from zero...
“ PID is a system that reduces error in the output of any other system. ”
It takes the error of output with respect to desired set value and works to minimize that
error. To do that in a required manner, PIDs need to be tuned i.e. by setting the GAINs of
PID . Overall they are used in a system to maintain errorless and stable output.
8
• The Proportional block senses the error and it linearly increases/decreases the
system response proportional to error multiplied by a constant- called its Gain.
• The Integral Block is used to minimize steady state error . It constantly adds up
the error fed into it (multiplied by its gain), but even if the error decreases
afterwards, it continues to increase response until error is negative which causes
OVERSHOOT in output. So it needs to be controlled by derivative block.
• The Derivative block senses the change in error , so for small change in error it
affects less but when there is a fast change in error ( i.e. OVERSHOOT ) the
derivative is highly effective and according to it’s gain it controls that overshoot.
where,
Ki
Transfer function of PID : K (s)=Kp + +kd . s
s
9
There are so many methods to tune a PID block and not any fixed method
so it is sometimes called to an art. But we prefered to tune it manually by observing the
effect of change in each particular gain on the system, so that we could understand more
how each of these blocks behave and also some practical issues that couldn’t be described
theoritically.
As per above table, setting of PID parameters can lead to nearly ideal responce if
perfectly tuned.
i/p o/p
K(s) G(s)
feedback= output
(condition : after approximations applied and initial conditions ignored for derivation )
how it works ?
• initially , refference is taken as input to system for which it will perform ideally.
• Then PID comes into picture , it will take error as input and modifiy that signal
according to proportional , intergral & derivative and addded togther becomes U(t).
• output of PID is given to original system to act accordignly that control input to get
minimum error.
• process continues upto error will be zero , but by considering practicality it will
never be zero.
Kp=1 , Kd = 1, Ki = 0.1
13
We can see by the above results that the Poles of the system are deep on LHP which says
that the response is highly stable. But for the first observation, the system had some
overshoots and poles are less deep in LHP so the roots reflected that too. In the second
response there was only a small change in Kp and Ki but there was a change of multiply
by 10 in derivative gain , which affects the output so that the Overshoots die out and a
nearly square edge response is there.
i/p o/p
G(s)
K(s)
d (θs)
τ ( s)=Kp . θ( s)+ Kd . + Ki . θ( s)
dt
G ( s)
H ( s)=
1+ K ( S) . G (s )
In the Feedback PID configuration, the Derivative term dominates, it controls the impulse
amplitude significantly and single-handedly. Which can be seen practically by changing
values.
15
• For the case when we use integral gain in this configuration , it causes output of
step response to decrease after reaching the steady state once. Which you can see
in figure below. This was the reason to not use it in this configuration.
(Kp = 10 , Ki = 1 , Kd = 10)
16
Woo..... finally, the Elephant passed the tunnel but the tail got stuck ....!!!
The task seemed to be finished, but there was no indication by which we could
know that at what angle it is getting stabilized and how do we change it ??
All we know was that it is the set point. A Constant angle, at which we want pendulum to
stay. A constant that we want to change whenever needed.
Laplace of a Constant is ( Constant / S ). So, one idea was to insert this function into the
LOOP. But, Failed...
Other one was to Insert In Feedback path too so that only output gets into pid. That too
failed....
Sometimes thought of using feedack pid only with above approach, but not work.
• “ The solution “ :
First Lifeline became this Laplace function of theta which was much similar in order and
dimensions to our ( CONSTANt / S ) idea.
τ =mgl sin θ
since sinθ≈θ
τ =mgl θ ( t )
I α =mgl θ
(d ( ω ))
I ω( )=mgl ( θ )
(d ( θ ))
2 2
(ω ) (θ )
I =mgl +0
2 2
2
since I =ml here
g
ω =± (
√ l
)θ
g
(d ( θ ))
(d (t )) √
=± (
l
) θ (t)
g
s ( θ )( s)− θ (0)=± (
√ l
) θ ( s)
Considering only positive sign because negative sign would cause unbounded response.
( θ (0))
θ (s)=
g
(s + (
√ l
))
We can say that the function is valid because the dimensions of sqrt(g/L) and “s” matches.
_____________________________________________________________________________________________
SetPoint
o/p
PID main Pendulum system
subtractor
adder
Feedback PID
setpoint
• As the diagram says, we decided to give this set point in both forward and feedback
loops. Here we found that as the angle is changed , the PID gains need to be
modified a little bit to get similar output for all angles. So, to avoid that we used
here the feedback PID( actually just PD) so it will stabilize the main PID.
here,
T(s)= θ ( s) (setpoint)
---------------------------------------------------------------------------------------
theta = π
20
theta = π/2
21
theta = π/4
22
theta = π/12
These responses can get even better if we slightly increase main PID gains. Overall it
can work for almost any angle without require to tune gains again. FINALLY..!!!!
23
CONTRIBUTORS :
Kartavya Barodiya
Kathan Shah
Kaushal Parmar
Krutarth Trivedi
References :
“ pkg load packagename “ command for each package or write this loop code in
OCTAVERC file (startup file) in
/usr/share/octave/site/m/startup/octaverc OR
/usr/share/octave/5.2.0/m/startup/octaverc
code:
packs = pkg('list');
for jj = 1:numel(packs),
pkg('load', packs{jj}.name);
end