0% found this document useful (0 votes)
69 views23 pages

Team C - Implementation of PID Control Using Inverted Pendulum

1) The document describes Team C's implementation of PID control to stabilize an inverted pendulum using OCTAVE. 2) Some of the challenges included getting familiar with OCTAVE, analyzing the pendulum dynamics, determining the transfer function, and understanding PID control. 3) The workflow involved installing OCTAVE, analyzing the pendulum system to derive the transfer function, observing the behavior under different conditions, understanding errors, and implementing PID control using OCTAVE.

Uploaded by

HH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views23 pages

Team C - Implementation of PID Control Using Inverted Pendulum

1) The document describes Team C's implementation of PID control to stabilize an inverted pendulum using OCTAVE. 2) Some of the challenges included getting familiar with OCTAVE, analyzing the pendulum dynamics, determining the transfer function, and understanding PID control. 3) The workflow involved installing OCTAVE, analyzing the pendulum system to derive the transfer function, observing the behavior under different conditions, understanding errors, and implementing PID control using OCTAVE.

Uploaded by

HH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

1

Team C - Implementation of PID


control using Inverted Pendulum
Task description :

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 :

• Getting familiar with OCTAVE.

• Analyzing the Simple Pendulum & the INVERTED Pendulum using physical analysis (
Conservation of Momentum, Free Body Diagrams, Energy conservation, Work-
Energy theorem, Calculus, etc.)

• Finding TRANSFER FUNCTION ! ! ! - Deciding which approximations to consider &


which to ignore was confusing.

• 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.

• PID was a largely highlighted yet unknown thing.

• To have PID working was easier, but understanding what happens inside took
efforts.

• How the changle of angle needs to be reflected on OCTAVE response ?!

• Changing of PID gain for the new angle position.


2

WORKFLOW :

• Installing Octave :

Octave is maintained by GNU so it is available ANYWHERE !!!

Installation is a child’s play. Additional Packages can be installed by commands. We


needed “control” package and needed to load it everytime we used it. But it can be
done automatically by writing the command in startup file of 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.

We would hereby include only the calculation required as a minimal background


for the further work.

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

m is mass of pendulum considering rod massless

θ is angle of pendulum

b is damping coefficient for the pendulum

Summation of torques = Resulting Angular acceleration*Moment of Inertia

˙ ¨
τ ( 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

But here , θ is very less . so ,sin θ ≈θ .


d 2θ dθ
τ ( t ) =m l 2 2
+b +mglθ ( t )
dt dt

Applying laplace transform ,


τ ( S )=m l2 ( S 2 θ ( S ) − Sθ ( 0 ) −θ ' ( 0 ) ) +b (( Sθ ( S ) −θ ( 0 ) ) )+ mgl θ ( S )

⇒ τ ( S ) =θ ( S ) (m l 2 (S 2 )+b S +mgl )−( Sθ ( 0 ) +θ ' ( 0 ) +b θ ( 0 ) )

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)

So, the above derived is the transfer function of the system.


4

• Observing the behaviour of this system :

Considering the pendulum undamped, i.e. b=0


5

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,

Considering some damping i.e. b=0.00001

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.

This is shown in the figure below,


6

• 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...

what we understood about PID is,

“ 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

what is PID control system ?

PID consists of three blocks which process the error.

P – Proportional block ; I – Integral block ; D – Derivative block ;

• 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.

Fig 2.1 PID block diagram

PID controller output : U (t )=Kp+ki .∫ e( µ). d (µ)+ dde (tt )

where,

Kp = Proportional gain error signal : e(t )=r (t)− y (t)

Ki = intergral gian y(t) = output of system

Kd = Derivative gain r(t) = reference signal

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.

Fig.2.2 Understanding of overshoot , setting time , SSE , rise-time

(reference – Mathworks.com (youtube video – screenshot)


10

• Option 1 : Implimentation of simple PID :

i/p o/p
K(s) G(s)

feedback= output

Transfer function of closed loop system is given as ,


K ( s) . G (s )
H ( s)=
1+ K ( s) . G (s )

G(s) = open loop Transfer function (pendulum)

K(s) = PID Transfer function

system of inverted pendulum with PID ,


(θ ( S ) ) 1
G (s )= = 2 2
(open loop Transfer Function)
(τ ( S ) ) (m l S + b S +mgl)

(condition : after approximations applied and initial conditions ignored for derivation )

(in Laplcae domain)

how it works ?
• initially , refference is taken as input to system for which it will perform ideally.

• Then whatever output is given back to mixer. So, we measure difference in


reference point (set point) and output of system.

• 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.

• So this process consider as closed loop system.


11

PID implementation for vertically upward stable postion


g=9.81; #gravitational acceleration

m=0.05; #mass of pendulum bob considering rod massless

L=0.1; #Length of pendulum i.e. Radius of path

b=0.00001; #frictional damping coefficient

Kp = 0.5 , Kd = 0.8 , Ki = 0.01


12

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.

• Option 2 : Implimentation of PID in feedback :

i/p o/p

G(s)

K(s)

fig 2.4 Feedback PID block Diagram


Hereby we used PID in feedback path to control system feedback to compenstate
distubaces ,

d (θs)
τ ( s)=Kp . θ( s)+ Kd . + Ki . θ( s)
dt

how this system will work !


due to disturbances system will increase the output angle of sysem (Inverted
Pendulum) , so by measuring angle and given to Feedback PID , and it will genrate
opposite torque according to it .

so distrunaces are compensated by PID controlled input.


14

G ( s)
H ( s)=
1+ K ( S) . G (s )

K(s) = transfer function of PID in feedback

G(s) = Transfer Function of pendulum system

for Kp=1 ; Ki=0 ; Kd=1 ;

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

• Changing the angle ( the SetPoint Rush ) :

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.

Then finally by somehow, inserting and removing transfer functions in various


combinations,...finding laplace function of theta....,etc etc..

Something just worked !!!!!!

• “ 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 ( θ ))

∫ I ω (d ( ω))=∫ mgl ( θ)(d (θ ))


17

2 2
(ω ) (θ )
I =mgl +0
2 2
2
since I =ml here

g
ω =± (
√ l

g
(d ( θ ))
(d (t )) √
=± (
l
) θ (t)

applying Laplace transform,

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

FINAL CLOSED LOOP SYSTEM


18

Here, setpoint = θ (s) .

• 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.

So, the closed loop[ transfer function looks like.

K (s) G ( s)T (s)


H (s)=
1+ K (s) G (s )T (s)F (s)

here,

K(s)= main PID

G(s)= Pendulum system

T(s)= θ ( s) (setpoint)

F(s)= Feedback PID


19

---------------------------------------------------------------------------------------

ULTIMATE OUTPUT ( Kp=2,Ki=3,Kd=0.8; Kpf=0.1;Kdf=1 )

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 :

1) https://octave.sourceforge.io/ - Octave Packages found here , if you want to


install manually.

2) To automatically load all available Packages in octave , write the

“ 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

3) Else you can find resources in the Resources folder . Haha..

You might also like