This action might not be possible to undo. Are you sure you want to continue?
https://www.scribd.com/doc/39978214/InvertedPendulum1
04/27/2013
text
original
PENDULUM SYSTEM
AHMAD NOR KASRUDDIN BIN NASIR
UNIVERSITI TEKNOLOGI MALAYSIA
PSZ 19:16 (Pind. 1/ 97)
UNIVERSITI TEKNOLOGI MALAYSIA
BORANG PENGESAHAN STATUS TESIS
+
MODELING AND CONTROLLER DESIGN FOR
JUDUL:
AN INVERTED PENDULUM SYSTEM
2006/2007
SESI PENGAJ IAN:
AHMAD NOR KASRUDDIN B IN NASIR
Saya
(HURUF B ESAR)
mengaku membenarkan tesis (PSM/Sarjana/Doktor Falsafah)* ini disimpan di Perpustakaan
Universiti Teknologi Malaysia dengan syaratsyarat kegunaan seperti berikut:
1. Tesis adalah hakmilik Universiti Teknologi Malaysia.
2. Perpustakaan Universiti Teknologi Malaysia dibenarkan membuat salinan untuk tujuan
pengajian sahaja.
3. Perpustakaan dibenarkan membuat salinan tesis ini sebagai bahan pertukaran antara
institusi pengajian tinggi.
4. **Sila tandakan ( \ )
SULIT
TERHAD
TIDAK TERHAD
(Mengandungi maklumat yang berdarjah keselamatan atau
kepentingan Malaysia seperti yang termaktub di dalam
AKTA RAHSIA RASMI 1972)
(Mengandungi maklumat TERHAD yang telah ditentukan
oleh organisasi/badan di mana penyelidikan dijalankan)
\
Disahkan oleh
(TANDATANGAN PENULIS) (TANDATANGAN PENYELIA)
Alamat Tetap:
496 (F) KERATONG SATU
B ANDAR TUN ABDUL RAZAK
P.M DR. MOHD FUA’AD BIN HJ. RAHMAT
26900 PAHANG DARUL MAKMUR
Nama Penyelia
Tarikh: Tarikh:
30
th
APRIL 2007 30
th
APRIL 2007
CATATAN: * Potong yang tidak berkenaan.
** Jika tesis ini SULIT atau TERHAD, sila lampirkan surat daripada pihak
berkuasa/organisasi berkenaan dengan menyatakan sekali sebab dan tempoh tesis ini perlu
dikelaskan sebagai SULIT atau TERHAD.
+ Tesis dimaksudkan sebagai tesis bagi Ijazah Doktor Falsafah dan Sarjana secara
penyelidikan, atau disertasi bagi pengajian secara kerja kursus dan penyelidikan, atau
Laporan Projek Sarjana Muda (PSM).
“I hereby declare that I have read this thesis and in my opinion this thesis is
sufficient in term of scope and quality for the award of the degree of Master of
Engineering (Electrical  Mechatronics)”
Signature : …………………………………….
Supervisor’s Name: ASSOC. PROF. DR. MOHD FUA’AD BIN HJ. RAHMAT
Date : 30
th
APRIL 2007
MODELING AND CONTROLLER DESIGN FOR AN INVERTED PENDULUM
SYSTEM
AHMAD NOR KASRUDDIN BIN NASIR
A thesis submitted in fulfillment of the
requirements for the award of the degree of
Master of Electrical Engineering
(Mechatronics & Automatic Control)
Faculty of Electrical Engineering
Universiti Teknologi Malaysia
APRIL 2007
ii
I declare that this thesis entitled “Modeling and Controller Design for an Inverted
Pendulum System”is the result of my own research except as cited in the references.
The thesis has not been accepted for any degree and is not concurrently submitted in
candidature of any other degree.
Signature :…………………………………….
Name :AH MAD NOR KASRUDDIN BIN NASIR
Date :30
th
APRIL, 2007
iii
To my dearest father, mother and family,
for their encouragement, blessing and inspiration …
iv
ACKNOWLEDGEMENT
Alhamdullillah, I am grateful to ALLAH SWT on His blessing and mercy for
making this project successful.
First of all, I would like to express my deepest appreciation to my supervisor,
Assoc. Prof. Dr. Mohd. Fua’ad bin Haji Rahmat for his effort, guidance and support
throughout this project. Without his advice, suggestions and guidance, the project
would have not been successful achieve the objectives.
I sincerely thank to Dr. Hj. Mohd Fauzi bin Othman and Dr. Shahrum Shah
bin Abdullah for helping and guiding me a lot on the artificial intelligence control
theory. Special thank also to my employer, Universiti Malaysia Pahang for giving me
financial support to further my study here.
To all lecturers who have taught me, thank you for the lesson that has been
delivered. Not forgetting all my friends, especially Mohd Ashraf, Noor Azam, Mohd
Arif, Mohd Sazli and Haszuraidah, thank you for their useful idea, information and
moral support during the course of study.
Last but not least, I would like to express my heartiest appreciation to my
parents and my family, who are always there when it matters most.
v
ABSTRACT
This paper presents the simulation study of several control strategies for an
inverted pendulum system. The goal is to determine which control strategy delivers
better performance with respect to pendulum’s angle and cart’s position. The inverted
pendulum represents a challenging control problem, which continually moves toward an
uncontrolled state. Three controllers are presented i.e. proportionalintegralderivative
(PID), linear quadratic regulator (LQR) for controlling the linear system of inverted
pendulum and fuzzy logic controller (FLC) for controlling the nonlinear system of
inverted pendulum model. Simulation study has been done in Simulink shows that LQR
produced better response compared to PID and FLC control strategies and offers
considerable robustness.
vi
ABSTRAK
Dalam thesis ini, beberapa teknik kawalan untuk pendulum songsang telah
dikaji. Tujuannya adalah untuk menentukan teknik kawalan yang mempunyai
prestasi terbaik terhadap sudut pendulum dan kedudukan kereta. Pendulum songsang
adalah satu masalah dalam bidang kawalan yang mencabar yang mana secara
berterusan menuju ke arah keadaan yang tidak terkawal. Tiga pengawal
dibincangkan iaitu PID, LQR untuk mengawal sistem pendulum songsang yang liner
dan FLC untuk mengawal sistem pendulum songsang yang kompleks. Simulasi telah
dibuat dengan menggunakan perisian Simulink dimana pengawal LQR menghasilkan
sambutan masa terbaik berbanding dengan teknik pengawalan PID dan teknik
pengawalan FLC. Teknik pengawalan LQR mempunyai kestabilan yang memuaskan.
vii
TABLE OF CONTENTS
CHAPTER TITLE PAGE
DECLARATION ii
DEDICATION iii
ACKNOWLEDGEMENT iv
ABSTRACT v
ABSTRAK vi
TABLE OF CONTENTS vii
LIST OF TABLES xi
LIST OF FIGURES xii
LIST OF SYMBOLS xvi
LIST OF APPENDICES xviii
I INTRODUCTION
1.1 Overview 1
1.1.1 Why Choose the Inverted Pendulum 3
1.2 Objective 4
1.3 Scope of Project 4
1.4 Research Methodology 5
1.5 Thesis Outline 7
II MODELING OF AN INVERTED PENDULUM
2.1 Inverted Pendulum 9
2.2 Force Analysis and System Equations 11
2.2.1 Transfer Function 12
2.2.2 StateSpace 14
viii
2.3 What is Matlab 15
2.3.1 What is an mfile 15
2.3.2 What is simulink 16
2.3.3 What is GUIDE 17
III PID CONTROLLER
3.1 Introduction 18
3.2 Consideration of Pendulum’s Angle 19
3.2.1 PID controller 21
3.3 Consideration of Cart's Position
3.3.1 PID Controller 22
3.4 Consideration of Cart's Position and Pendulum’s Angle 25
3.5 Conclusion 26
IV LQR CONTROL METHOD
4.1 Introduction 28
4.2 StatesSpace Design 29
4.2.1 LQR Control Method 31
4.2.2 Adding a Reference Input 32
4.2.3 FullOrder Estimator 34
4.3 Conclusion 35
V FUZZY LOGIC CONTROLLER
5.1 Where Did Fuzzy Logic Come From 37
5.2 What Is Fuzzy Logic 38
5.2.1 The Form of Fuzzy Control Rules and 39
Inference Method
5.2.2 Type of Fuzzy Controllers 42
5.2.2.1. Inference Method 1 42
5.2.2.2 Inference Method 2 45
5.2.2.3. Inference Method 3 47
5.3. Planning Of Fuzzy Controllers 48
ix
5.4 How Is FL Different From Conventional 49
Control Method
5.5 How Does FL Work 50
5.6 Fuzzy Of Inverted Pendulum System 50
5.6.1 Fuzzy Logic Controller Design Flow Chart 51
5.6.2 Inputs and Outputs of FLC 54
5.6.3 Membership functions 55
5.6.4 Rule base 59
5.6.5 Implementation in Simulink 60
5.7 Conclusion 62
VI ARTIFICIAL NEURAL NETWORKS CONTROLLER
6.1 Introduction 63
6.2 Advantages of ANN’s 64
6.3 Types of Learning 66
6.4 Neural network structures 66
6.5 Activation functions 67
6.6 Learning Algorithms 67
6.7 Forward Modeling of Inverted 68
Pendulum Using Neural Networks
6.8 Learning rules 70
6.9 Implementation in Simulink 71
6.9.1 Problems and constraints in designing 74
the ANN controller
6.10 Conclusion 74
VII RESULTS AND DISCUSSION
7.1 Introduction 75
7.2 OpenLoop Results 75
7.3 PID Control Method 78
7.3.1 PID Control Method 78
x
7.3.2 Cart’s Position 80
7.3.3 Pendulum's Angle and Cart's Position 81
7.4 LQR Control Method 83
7.4.1 Pendulum's Angle and Cart's Position 83
7.5 Fuzzy Logic Controller Control Method 87
7.5.1 Pendulum's Angle and Cart's Position 87
7.6 Artificial Neural Network Control Method 88
7.7 Comparative Assessment and Analysis of the Response 91
7.8 Discussion 97
VIII CONCLUSION AND SUGGESTION
8.1 Conclusion 100
8.2 Suggestion for the Future Work 101
REFERENCES 103
Appendices 105108
xi
LIST OF TABLES
TABLE TITLE PAGE
3.1 ZeiglerNichols tuning method 26
5.1 Discrete type of Fuzzy variables 41
5.2 Inputs and outputs of FLC 54
5.3 Standard labels of quantization 55
5.4 Fuzzy rule matrix for control position FLC 59
5.5 Fuzzy rule matrix for control angle FLC 59
6.1 Properties of Neural Network 73
7.1 Comparison of output response of cart’s position 93
7.2 Comparison of output response of pendulum’s angle 96
xii
LIST OF FIGURES
FIGURE NUMBER TITLE PAGE
1.1 Flow chart of research methodology 6
2.1 Free body diagram of the inverted pendulum system 9
2.2 Free body diagrams of the system 11
2.3 Simulink block in Matlab 16
2.4 GUI front panel of Inverted Pendulum System 17
3.1 The schematic diagram for the closedloop system 20
with force as disturbance
3.2 The rearranged schematic diagram for the closedloop 20
system with force as disturbance
3.3 Actual schematic diagram of the Inverted 23
Pendulum System
3.4 Rearranged schematic diagram of the Inverted 23
Pendulum System
3.5 Schematic diagram of the Inverted Pendulum System 25
with two PID controllers
3.6 Schematic diagram of the Inverted Pendulum System 26
with two PID controllers in Simulink
4.1 Schematic diagram for Inverted Pendulum in 30
StateSpace form
4.2 Schematic diagram of system with NBar 33
4.3 Schematic diagram of system in StateSpace 35
xiii
with Estimator
5.1 Comparison between Fuzzy Logic Controller 38
and PID controller
5.2 Control algorithm of Fuzzy Logic Controller 39
5.3 A Triangular membership function of Fuzzy Logic 40
Controller
5.4 A H Type membership function 40
5.5 Block diagram of Fuzzy Controller 42
5.6 Schematic representation of Inference Method 1 44
5.7 Monotonic membership functions 45
5.8 Schematic representation of Inference Method 2 46
5.9 Fuzzy Logic Controller design flow chart 51
5.10 Block diagram of the system with Fuzzy Logic 52
Controller
5.11 Rearranged block diagram of the System with Fuzzy 53
Logic Controller
5.12 Fuzzy Logic Controller block diagram 54
5.13 Input 1 of Fuzzy Logic Controller 1 56
5.14 Input 2 of Fuzzy Logic Controller 1 56
5.15 Output of Fuzzy Logic Controller 1 57
5.16 Input 1 of Fuzzy Logic Controller 2 57
5.17 Input 2 of Fuzzy Logic Controller 2 58
5.18 Output of Fuzzy Logic Controller 2 58
5.19 Schematic diagram of the Nonlinear Inverted Pendulum 61
system with two FLC controllers in Simulink
6.1 Biological neuron 64
6.2 Diagram of neuron model 65
6.3 Diagram of the Perceptron model 66
6.4 Activation functions 67
6.5 Supervised learning 68
6.6 Forward modeling of Inverted Pendulum 69
xiv
using Neural Networks
6.7 Rearranged forward modeling of Inverted Pendulum 70
using Neural Networks
6.8 Block diagram of the Inverted Pendulum system 72
with an ANN in Simulink
7.1 Impulse response for pendulum’s angle using 76
transfer function
7.2 Impulse response for cart’s position using 76
transfer function
7.3 Impulse response for pendulum’s angle and cart’s 77
position using StateSpace
7.4 Impulse response for pendulum’s angle for 78
K=1, K
d
=1, K
i
=1
7.5 Impulse response for pendulum’s angle for 79
K=100, K
d
=1, K
i
=1
7.6 Impulse response for pendulum’s angle for 79
K=100, K
d
=20, K
i
=1
7.7 Impulse response of cart’s position for 80
K=100, K
d
=20, K
i
=1
7.8 Impulse response for pendulum’s angle for 82
K=50, K
d
=3.5, K
i
=110
7.9 Impulse response for cart’s position for 82
K=0.0001, K
d
=0.3, K
i
=10
7.10 Step response with LQR control for 84
x=5000 and y=100
7.11 Step response with LQR and Nbar control for 85
x=5000 and y= 100
7.12 Step response with Estimator for x=6000 and y=200 86
7.13 Impulse response for pendulum’s angle 87
7.14 Impulse response for cart’s position 88
7.15 Training output response of cart’s position 89
xv
7.16 Training output response of pendulum’s angle 89
7.17 System output response of cart’s position 90
7.18 System output response of pendulum’s angle 90
7.19 Comparison of output response of cart’s position 92
7.20 Output response of cart’s position 94
7.21 Comparison of output response of pendulum’s angle 95
8.1 Graphical User Interface front panel of Inverted 101
Pendulum System
xvi
LIST OF SYMBOLS
SYMBOL DESCRIPTION
b  Friction or cart
l  Length to pendulum centre of mass
x  Cart position coordinate
x  cart acceleration
ș  Pendulum angle from the vertical
u
 Pendulum angular acceleration
r(s)  Reference signal
e(s)  Error signal
u(s)  Plant input
g(s)  Plant
y(s)  Output, pendulum’s angle
f(s)  Disturbance, force
x  State vector
u  Input vector
y  Output vector
ts  Settling time
tr  Rising time
ess  Steady state error
Kp  Error multiplied by a gain
Ki  The integral of error multiplied by a gain
Kd  The rate of change of error multiplied by a gain
xvii
KD(s)  Controller gain
X(s)  Cart's position signal
NS  Negative small
NM  Negative medium
NL  Negative large
ZE  Zero
PS  Positive small
PM  Positive medium
PL  Positive Large
PID  Proportional Integral Derivative
LQR  Linear Quadratic Regulator
FLC  Fuzzy Logic Controller
ANN  Artificial Neural Network Controller
AI  Artificial Intelligence
GUI  Graphic User Interface
M  Mass of cart
M  Mass of pendulum
CV  Control variable
E  Error
SP  Set point
PV  Process variable
SISO  Singleinputsingleoutput
R  Step input to the cart
A  State matrix
B  Input matrix
C  Output matrix
D  Direct transmission matrix
%OS  Percent overshoot
I  Inertia of the pendulum
F  Force applied to cart
xviii
LIST OF APPENDICES
APPENDIX TITLE PAGE
A1 Matlab command to find open loop 105
transfer function of the system
A2 Matlab command for Polyadd function 105
A3 PID control method for pendulum’s angle 106
A4 PID control method for cart’s position 106
A5 Matlab command for LQR design 107
A6 Matlab command for adding the reference 108
input
A7 Matlab command to design a FullOrder 109
Estimator
1
CHAPTER 1
INTRODUCTION
1.1 Overview
The inverted pendulum offers a very good example for control engineers to
verify a modern control theory. This can be explained by the facts that inverted
pendulum is marginally stable, in control sense, has distinctive time variant
mathematical model.
Inverted Pendulum is a very good model for the attitude control of a space
booster rocket and a satellite, an automatic aircraft landing system, aircraft
stabilization in the turbulent airflow, stabilization of a cabin in a ship etc. To solve
such problem with nonlinear time variant system, there are alternatives such as real
time computer simulation of these equations or linearization.
The inverted pendulum is a highly nonlinear and openloop unstable system.
This means that standard linear techniques cannot model the nonlinear dynamics of
the system. When the system is simulated the pendulum falls over quickly. The
2
characteristics of the inverted pendulum make identification and control more
challenging.
The inverted pendulum is an intriguing subject from the control point of view
due to their intrinsic nonlinearity. The problem is to balance a pole on a mobile
platform that can move in only two directions, to the left or to the right. This control
problem is fundamentally the same as those involved in rocket or missile propulsion.
Common control approaches such as ProportionalIntegralDerivative (PID) control
and Linear Quadratic control (LQ) require a good knowledge of the system and
accurate tuning in order to obtain desired performances. However, it is often
impossible to specify an accurate mathematical model of the process, or the
description with differential equations is extremely complex. [3]
In order to obtain control surface, the inverted pendulum dynamics should be
locally linearized. Moreover, application of these control techniques to a two or
three stage inverted pendulum may result in a very critical design of control
parameters and difficult stabilization. However, using artificial intelligence
controllers such as artificial neural network and fuzzy logic controllers, the controller
can be design without require the model to be linearized. The nonlinearized model
can be simulated directly using the Matlab application to see result. Therefore, in
this project, four types of controllers will be simulated. These four controllers can be
divided into two categories.
(1) Conventional Controller
Proportional Integral Derivative (PID)
Linear Quadratic Regulator (LQR)
(2) Artificial Intelligence Controller
Fuzzy Logic Controller (FLC)
Artificial Neural Network Controller (ANN)
3
1.1.1 Why Choose the Inverted Pendulum
The following reasons help explain why the inverted pendulum on a cart has
been selected as the system on which the findings of this report will be implemented.
1. A progressive model can be built. It is a nonlinear system, yet can be
approximated as a linear system if the operating range is small (i.e. slight variations
of the angle from the norm).
2. Intuition plays a large part in the human understanding of the inverted pendulum
model. When the control method is supplemented with a fuzzy logic and artificial
neural network optimization techniques, the result will provide an insightful measure
of the ability of the method to provide control.
3. The cart/pole system is a common test case for fuzzy logic so any results can be
compared to previous work in the field. In order to perform sound criticism of any
controllers developed, a reference model must be designed at the outset of this work.
If any testing is worth doing at all it must be planned in such a way that it has at least
a good chance of giving a useful result [2]. A proportional, integral, derivative (PID)
and LQR controllers will be used as a reference because both the structure of the
controller is simple and the performance is not adversely affected by noise and
parameter variations.
4
1.2 Objectives
This project consists of three objectives as listed below:
i. To design artificial intelligence (AI) controller (Fuzzy Logic controller,
FLC and Artificial Neural Network controller, ANN) and conventional
controller technique (PID and LQR) for an inverted pendulum system
ii. To make comparison between artificial intelligence controller technique
and conventional controller technique
iii. To design a graphic user interface (GUI) for the inverted pendulum
system simulation
1.3 Scopes of Works
i. Determine the mathematical model for an inverted pendulum system.
ii. Design a controller using artificial intelligence technique (FLC and ANN)
and conventional technique (PID and LQR)
iii. Simulate the controllers using Matlab and conclude the best controller
based on the simulation results
iv. Design inverted pendulum system animation using Matlab
5
1.4 Research Methodology
1. Conducting literature review to understand the concept of an inverted
pendulum system
2. Searching out previous and current projects of an inverted pendulum system,
identifying problem faced by previous and current researcher and identifying
suitable technique of designing the controllers
3. Defining mathematical model for an inverted pendulum system
4. Defining mathematical model of the controllers
5. Study the Matlab programming language, graphical user interface and
simulink
6. Designing and writing Matlab program to simulate and animate the system
7. Analyze the process, Acquire control rules from experience operator and
simulate the FLC, ANN, PID and LQR
All the methodology above can be summarized as shown Figure 1.1
6
Mathematical Model
Transfer function
LQR Controller PID Controller
Fuzzy Logic
StateSpace Form
Controller Design
Comparison and GUI
Evaluate Performance
Conventional Artificial Intelligence
Design Requirement
Literature Review
Neural Network
Figure 1.1: Flow chart of research methodology
7
1.5 Thesis Outline
This report consists of eight chapters including this chapter. The scope of
each chapter is explained as stated below:
Chapter 1
This chapter gives the introduction to the project report, objectives, scopes of
works and methodology taken.
Chapter 2
This chapter discusses modeling of an inverted pendulum. It is contained the
derivation in mathematical modeling for the dynamic of the inverted pendulum
system, including the nonlinear and linearized equations. It consists of development
of an inverted pendulum model, followed by its transfer function and statespace
representations. The modeling technique in Simulink is also discussed.
Chapter 3
This chapter discusses the theory and application of PID controller of this
project. Both transfer function and statespace models are used to analyze the
controller to solve the inverted pendulum problem.
Chapter 4
This chapter proposes LQR control method in controlling the inverted
pendulum system by applying the statespace representation. There are also a few
modifications that have been done to meet the design requirements and to improve
the results.
8
Chapter 5
This chapter proposes the Fuzzy Logic Controller (FLC) for the inverted
pendulum system. It also describes some theoretical background of FLC such as the
introduction and types of fuzzy. The proposed FLC characteristics for the inverted
pendulum are also discussed.
Chapter 6
This chapter discusses the Artificial Neural Network controller (ANN) of
inverted pendulum system. Its also includes the introduction, advantages of ANN’s,
types of learning, neural network structures, activation functions, learning
algorithms, forward modeling of inverted pendulum using neural network, and
learning rules
Chapter 7
This chapter displays the results of the closed loop system of the inverted
pendulum, the results of the PID and LQR controllers, and also the results of the
Fuzzy Logic controller and Artificial Neural Network controller.
Chapter 8
This last chapter presents the overall discussion and conclusion of this
project. A few recommendations and suggestions also have been included for the
future work.
9
CHAPTER II
MODELING OF AN INVERTED PENDULUM
2.1 Inverted Pendulum
The inverted pendulum system is a classic control problem that is used in
universities around the world. It is a suitable process to test prototype controllers due
to its high nonlinearities and lack of stability. The system consists of an inverted
pole with mass, m, hinged by an angle ș from vertical axis on a cart with mass, M,
which is free to move in the x direction as shown in Figure 2.1. A force, F is
required to push the cart horizontally. In this chapter, the dynamical equations of the
system will be derived.
Figure 2.1: Free body diagram of the inverted pendulum system
10
This section outlines the assumptions, design requirements and physical
properties of the model and its components.
Assumptions:
1. The system starts in a state of equilibrium meaning that the initial conditions are
therefore assumed to be zero.
2. The pendulum does not move more than a few degrees away from the vertical to
satisfy a linear model.
3. A step input is applied.
Design Requirements:
1. The settling time, T
s
, is to be less than five seconds. Ts < 5secs
2. The system overshoot value is to be at most 22.5%. os < 22.5%
Properties of the Cart and Pendulum:
M – Mass of cart 0.5kg
m – Mass of pendulum 0.2kg
b – Friction or cart 0.1Nm1s1
l – Length to pendulum centre of mass 0.3m
I – Inertia of the pendulum 0.006 kg m2
F – Force applied to cart
x – Cart position coordinate
ș – Pendulum angle from the vertical
11
2.2 Force Analysis and System Equations
To derive the suitable mathematical model for an inverted pendulum system,
consider Figure 2.2:
Figure 2.2: Free body diagrams of the system.
Summing the forces of the cart in the horizontal direction
(2.1) F N b M
Summing the forces of the pendulum in the horizontal direction
(2.2)
Substituting equation 2.2 into equation 2.1
(2.3)
Sum the forces perpendicular to the pendulum
u u u u u cos sin cos sin x m ml mg N P
+ = ÷ + (2.4)
To get rid of the P and N terms in the equation above, sum the moments around the
centroid of the pendulum
u u u
I l N Pl = ÷ ÷ cos . sin (2.5)
x = + + x
+ u u u u cos
2
x M + u cos ) (
2
N ÷ sin
ml ml x M =
F ml ml b m = ÷ + + u u u sin
x
12
Combining equation 2.4 and equation 2.5
u u u cos sin ) (
2
x ml mgl ml I
÷ = + + (2.6)
Since Matlab can only work with linear functions, this set of equations should be
linearized about u =t . Assume that u = t + ø (ø represents a small angle from the
vertical upward direction). Therefore, cos (u ) = 1, sin (u ) = ø, and
2
) (dt
du
= 0.
After linearization the two equations of motion become (where u represents the
input):
x ml mgl ml I
= ÷ + o o ) 2 ( (2.7)
u ml x b x m M = ÷ + + o
) ( (2.8)
2.2.1 Transfer Function
Laplace transform of the system equations
(2.9)
2 2
( ( ( ) ( mgl ml ÷ = ÷ + o o
2
(2.10)
( ( ( ( U ml bX X m = ÷ + + o
) ) ) s s mlX s s s I
) ) )
2 2
s s s s s s s M ) ( )
Since the angle ø is the output of interest, solving equation 2.9 for X(s),
13
) (
) (
) (
2
2
s
s
g
ml
ml I
s X o
÷
+
= (2.11)
Substituting equation 2.11 into equation 2.10
) ( ) ( ) (
) (
) (
) (
) (
2
2
2
2
s U s s ml s s
s
g
ml
ml I
b s s
s
g
ml
ml I
m M = ÷
+
+
+
+
+
+ o o o (2.12)
Rearranging, the transfer function is
s
q
bmgl
s
q
mgl m M
s
q
ml I b
s
s
q
ml
s U
s
÷
+
÷
+
+
=
u
2 3
2
4
2
) ( ) ( ) (
) (
(2.13)
where, ] ) ( ) )( [(
2 2
ml ml I m M q ÷ + + =
From the transfer function above it can be seen that there is both a pole and a zero at
the origin. These can be canceled and the transfer function of the angle is shown as
in equation 2.14 and equation 2.15
q
bmgl
s
q
mgl m M
s
q
ml I b
s
s
q
ml
s U
s
÷
+
÷
+
+
=
u
) ( ) ( ) (
) (
2
2
3
(2.14)
4545 . 4 1818 . 31 1818 . 0
5455 . 4
) (
) (
2 3
÷ ÷ +
=
u
s s s
s
s U
s
(2.15)
Solving for the transfer function of the position, the following equation 2.16 will be
derived
4545 . 4 1818 . 31 1818 . 0
5455 . 44 8182 . 1
) (
) (
2 3
÷ ÷ +
÷
=
s s s
s
s U
s X
(2.16)
14
2.2.2 StateSpace
The linearized system equations can also be represented in statespace form
as shown in equation 2.17 till equation 2.19.
+ +
+
+ +
÷
+ + + +
+ ÷
=
) (
) (
) (
) (
0
) (
) (
) (
0
1 0 0 0
0
) ( ) (
) (
0
0 0 1 0
) (
) (
) (
) (
2 2
2
2 2
2
2
t
t
t x
t x
Mml m M I
m M mgl
Mml m M I
mlb
Mml m M I
gl m
Mml m M I
b ml I
t
t
t x
t x
o
o
o
o
(2.17)
) (
) (
0
) (
0
2
2
2
t u
Mml m M I
ml
Mml m M I
ml I
+ +
+ +
+
+
Substituting all the parameter values into the equation 2.17 yielding equation 2.18
and equation 2.19
) (
5455 . 4
0
8182 . 1
0
) (
) (
) (
) (
0 1818 . 31 4545 . 0 0
1 0 0 0
0 6727 . 2 1818 . 0 0
0 0 1 0
) (
) (
) (
) (
t u
t
t
t x
t x
t
t
t x
t x
+
÷
÷
=
o
o
o
o
(2.18)
) (
0
0
) (
) (
) (
) (
0 1 0 0
0 0 0 1
) ( t u
t
t
t x
t x
t y
+
=
o
o
(2.19)
The C matrix is 2 by 4, because both the cart's position and the pendulum's
position are part of the output. For the statespace design, a multioutput system will
be controlled so that the cart's position and pendulum’s angle can be observed from
the first row and second row of the output respectively.
15
2.3 What is Matlab
Matlab (short for MATrix LABoratory) is a language for technical
computing, developed by the The Mathworks, Inc. It provides a single platform for
computation, visualization, programming and software development. All problems
and solutions in Matlab are expressed in notation used in linear algebra and
essentially involve operations using matrices and vectors. Matlab can be used to
solve problems in control systems.
In addition, Matlab can be used to build Graphical User Interfaces (GUIs) so
that userfriendly custom software can be developed. The Matlab software
environment has a core module (called Matlab) and associated with that are a set of
"Toolboxes" that perform specialized computations.
2.3.1 What is an MFile
An mfile, or script file, is a simple text file where a Matlab command can be
placed. When the file is run, Matlab reads the commands and executes them exactly
if each command is typed sequentially at the Matlab prompt. All mfile names must
end with the extension '.m' (e.g. plot.m). By creating a new mfile with the same
name as an existing mfile, Matlab will choose the one which appears first in the path
order (help path for more information). To make life easier, choose a name for m
file which doesn't already exist.
16
For example, create a file containing these five lines.
A = [ ...
16.0 3.0 2.0 13.0
5.0 10.0 11.0 8.0
9.0 6.0 7.0 12.0
4.0 15.0 14.0 1.0 ];
Store the file under the name magic.m. Then the statement magic reads the file and
creates a variable, A.
2.3.2 What is Simulink
Simulink is a tool for modeling, simulating and analyzing multi domain
dynamic systems. Its primary interface is a graphical block diagramming tool and a
customizable set of block libraries. Example of simulink software is shown in Figure
2.3. Simulink offers tight integration with the rest of the MATLAB environment and
both drive MATLAB or can be scripted from it. Simulink is widely used in control
theory and digital signal processing for multi domain simulation and design.
Analysis of steadystate operation of a linear electrical circuit
Conti nuous
Z source
v
+

Vol tage
Measurement
Scope
Z
Impedance
Measurement
I source
300 Hz
?
Doubl e cl i ck here for detai l s
i
+

Current
Measurement
5th Harm.
Fi l ter
100 V
60 Hz
Current
Voltage
Figure 2.3: Simulink block in Matlab
17
2.3.3 What is GUIDE
GUIDE, the MATLAB graphical user interface development environment,
provides a set of tools for creating graphical user interfaces (GUIs). These tools
greatly simplify the process of designing and building GUIs. The GUIDE tools can
be used to Layout the GUI. Using the GUIDE Layout Editor, a GUI could be easily
layout by clicking and dragging GUI components such as panels, buttons, text fields,
sliders, menus, and so on into the layout area. GUIDE stores the GUI layout in a
FIGfile. GUIDE automatically generates an Mfile that controls how the GUI
operates. The Mfile initializes the GUI and contains a framework for the most
commonly used callbacks for each component and the commands that execute when
a user clicks a GUI component. Using the Mfile editor, code can be added to the
callbacks to perform the functions needed by user. Figure 2.4 shows the GUI front
panel of inverted pendulum system.
Figure 2.4: GUI front panel of inverted pendulum system
18
CHAPTER III
PID CONTROLLER
3.1 Introduction
PID stands for ProportionalIntegralDerivative. This is a type of feedback
controller whose output, a control variable (CV), is generally based on the error (e)
between some userdefined set point (SP) and some measured process variable (PV).
Each element of the PID controller refers to a particular action taken on the error.
• Proportional: error multiplied by a gain, Kp. This is an adjustable amplifier. In
many systems Kp is responsible for process stability: too low and the PV can drift
away; too high and the PV can oscillate.
• Integral: the integral of error multiplied by a gain, Ki. In many systems Ki is
responsible for driving error to zero, but to set Ki too high is to invite oscillation or
instability or integrator windup or actuator saturation.
19
• Derivative: the rate of change of error multiplied by a gain, Kd. In many systems
Kd is responsible for system response: too high and the PV will oscillate; too low and
the PV will respond sluggishly. The designer should also note that derivative action
amplifies any noise in the error signal.
Tuning of a PID involves the adjustment of Kp, Ki, and Kd to achieve some user
defined "optimal" character of system response.
3.2 Consideration of Pendulum’s Angle
As mentioned earlier in the previous section, the transfer function of this
system for the pendulum’s angle is shown in equation 3.1
s
q
bmgl
s
q
mgl m M
s
q
ml I b
s
s
q
ml
s U
s
÷
+
÷
+
+
=
u
2 3
2
4
2
) ( ) ( ) (
) (
(3.1)
where,
] ) ( ) )( [(
2 2
ml ml I m M q ÷ + + =
For this case, the design criteria to be fulfilled as stated below:
 Settling time of less than 5 seconds.
 Pendulum should not move more than 0.05 radian away from the vertical.
20
Since the objective is to control the pendulum's position, which should return
to the vertical after the initial disturbance, the reference signal for the position should
be zero. The force applied to the cart is added as an impulse disturbance. It can be
represented in block diagram as shown in Figure 3.1.
) (s u
PLANT 1
G2(S)
PLANT 1
G1(S)
PID
CONTROLLER
¯ ¯
r(s)=0
e(s)
f(s)=F
) (s X
) (s u
u(s)
+
+
+

Figure 3.1: The schematic diagram for the closedloop system with force as
disturbance
For simplicity, the block diagram can be rearranged as shown in Figure 3.2
Figure 3.2: The rearranged schematic diagram for the closedloop system with force
as disturbance
21
where,
r(s) = reference signal
e(s) = error signal
u(s) = plant input
g(s) = plant
y(s) = output, pendulum’s angle
KD(s) = controller gain
f(s) = disturbance, force
Therefore, the closedloop transfer function of the diagram can be found as shown by
the equation 3.2.
) )( (
) )( (
1
) (
) ( ) ( 1
) (
) (
den denPID
num numPID k
den
num
s F
s G s KD
s G
s y
+
=
+
=
(3.2)
) (
) )( ( ) )( (
) (
s F
num numPID k den denPID
denPID num
+
=
3.2.1 PID controller
The closedloop transfer function in equation 3.2 can be implemented into
Matlab by using the mfile code as stated in the appendix. Both of the transfer
functions from the laplace transforms or from the state space representation can be
used. This transfer function assumes that both derivative and integral control will be
needed along with proportional control.
22
This closedloop transfer function can be modeled in Matlab by copying the
code from Appendix A3 for this section to the end of mfile. The function polyadd is
not originally in the Matlab toolbox. It has to be copied to a new mfile to use it
(refer to Appendix A2 for Polyadd function). This transfer function is assumed that
both derivative and integral control will be needed along with proportional control.
The actual control of this system could be started by subjecting impulse or
step input. The velocity response plot for the impulse disturbance is shown in Figure
7.4 in Chapter 7. The response is still not stable and can be improved by increasing
the proportional control to the system. The K variable is increased to see what the
effect on the response. By setting K= 100, and the axis to axis ( [0, 2.5,  0.2, 0.2] ),
the velocity response plot as shown in Figure 7.5 in Chapter 7 will be determined.
From the response, the settling time is acceptable at about 2 seconds. Since the
steadystate error has already been reduced to zero, no more integral control is
needed. The integral gain constant could be removed to see for the small integral
control is needed. The overshoot is too high, so that must be fixed. The problem can
be solved by increasing the K
d
variable. With K
d
= 20 a satisfactory result should be
determined. See the velocity response plot as shown in Figure 7.6 in Chapter 7.
The overshoot has been reduced so that the pendulum moves less than 0.05 radian
from the vertical. All of the design criteria have been met.
3.3 Consideration of Cart's Position
3.3.1 PID Controller
The block representing the position was left out at the beginning because that
variable was not being controlled. Considering the cart's position and the pendulum's
angle using one PID controller, the inverted pendulum system can be represented in a
block diagram as shown in Figure 3.3.
23
Figure 3.3: Actual schematic diagram of the inverted pendulum system
Rearranging the block diagram above, a simpler block diagram of inverted pendulum
system is produced as shown in Figure 3.4.
Figure 3.4: Rearranged schematic diagram of the inverted pendulum system
where,
X(s) = cart's position signal; e (s) = pendulum's angle signal
G(s) = pendulum's angle; G
2
(s) = cart's position
The transfer function from the cart's position to the impulse force, with the PID
feedback controller is given as shown in equation 3.3 and equation 3.4.
) (
) 1 )( (
) 1 )( (
1
2
2
) ( 1 ) ( 1
) ( 2
) ( s F
den denPID
num numPID k
den
num
s G s KD
s G
s X
+
=
+
= (3.3)
24
) (
) 2 )( 1 )( ( ) 2 )( 1 )( (
) 1 )( )( 2 (
) ( s F
den num numPID k den den denPID
den denPID num
s X
+
= (3.4)
Recall that den1=den2 if the pole/zero at the origin that was cancelled is added back
into equation 3.4. So the transfer function from X to F can be simplified into
equation 3.5.
) 1 )( ( ) )( (
) )( 2 (
) (
num numPID k den denPID
denPID num
s X
+
= (3.5)
The transfer function for the entire system is determined. Therefore the response of
the system can be considered. The transfer function for the cart's position are
determined by taking the laplace transforms of the system equations and find the
transfer function from X(s) to U(s) by manipulating equation 3.5. The transfer
function for the cart’s position is shown in equation 3.6.
q
bmgl
s
q
mgl m M
s
q
ml I b
s
q
mgl
s
q
ml I
s U
s X
÷
+
÷
+
+
÷
+
=
) ( ) (
) (
) (
) (
2
2
3
2
2
(3.6)
where,
] ) ( ) )( [(
2 2
ml ml I m M q ÷ + + =
The Matlab command for this step can be referred to Appendix A4. By referring to
Figure 7.7 in Chapter 7 for the impulse response of the cart's position using PID
technique, the result shows that the cart moves in the negative direction with a
constant velocity. So, although the PID controller stabilizes the angle of the
pendulum, this design would not be feasible to implement on an actual physical
system.
25
3.4 Consideration of Cart's Position and Pendulum’s Angle
Block diagram in Figure 3.5 shows that the system was controlled by 2
different PID controllers. As can be seen, the ‘PID Controller 1’ and ‘PID Controller
2’ were used to control the pendulum’s angle and cart’s position respectively.
PID
Controller 2
(Position)
PID
Controller 1
(Angle)
Position
Force
Angle
r(s)
Zero
+


+
+
x (s)
o (s)
F
Figure 3.5: Schematic diagram of the inverted pendulum system with two PID
controllers
Ziegler and Nichols method was implemented in designing the PID
controllers. Both of the controllers were tuned simultaneously so that the control
variable of the controllers is appropriately determined. The control variables were
summed together to become a force to the system. By using this block diagram, the
inverted pendulum system was successfully stabilized. The response of this system
is shown in the later chapter.
26
Table 3.1 shows the ZeiglerNichols chart that was used in tuning the PID
controllers. From this table, all the coefficients of the PID controllers are easily
determined by applying the given formula. The refining process of the output
response can be done iteratively by changing the coefficient parameters.
Table 3.1: ZeiglerNichols tuning method
Controller Type Proportional
Gain, K
c
Integral Time,
T
i
Derivative
Time, T
d
Proportional (P)
g p
K K 5 . 0 =  
ProportionalIntegral (PI)
g p
K K 45 . 0 =
g
g
I
K
K
e
54 . 0
=

ProportionalIntegral
Derivative (PID)
g
K 6 . 0
g
g
I
K
K
e
2 . 1
=
4
3 . 0
g g
D
K
K
e
=
Figure 3.6 shows the schematic diagram of the inverted pendulum system
with two PID controllers in Simulink. For the ‘PID Controller 1’, the parameter
values inside the block are (P=50; I=;110 D=3.5). The parameter values inside the
‘PID Controller 2’ block are (P=0.0001; I=;10 D=0.3).
27
x
0.65357
Target Posi ti on
(MouseDri ven)
Target Posi ti on
Swi tch
In1
teta1
x1
Subsystem
Step1
R2D
Radi ans
to Degrees
PID
PID Control l er2
PID
PID Control l er1
Mux
Mux
Manual
Swi tch
1 Constant
ani mcp
Ani mati on
Figure 3.6: Schematic diagram of the inverted pendulum system with two PID
controllers in Simulink
3.5 Conclusion
As a conclusion, PID control method is a good controller for controlling the
singleinputsingleoutput (SISO) system. It means that only one input could be
controlled by a PID controller in a time. However, the PID alone cannot be used
successfully to control the cart's pendulum and the pendulum’s angle in the same
time. The results display that the cart moves in the negative direction with a constant
velocity when an impulse force is applied to move it. However, in this project, by
applying 2 PID controllers for the system, the inverted pendulum was stabilized
successfully. ‘PID Controller 1’ and ‘PID Controller 2’ were used to control the
angle of the pendulum and the position of the cart respectively. As a conclusion, the
linear model of inverted pendulum system can be stabilized successfully by applying
two PID controllers simultaneously if they are tuned properly.
28
CHAPTER IV
LQR CONTROL METHOD
4.1 Introduction
Chapter 4 discusses the Linear Quadratic Regulator (LQR) control technique
in detail. LQR is a method in modern control theory that uses statespace approach to
analyze such a system. While conventional control theory is based on the input
output relationship, or transfer function, modern control theory is based on the
description of system equations in terms of n firstorder differential equations, which
may be combined into a first order vectormatrix differential equation.
29
4.2 StatesSpace Design
The model of inverted pendulum system can be represented in state space as shown
in equation 4.1.
) (
5455 . 4
0
8182 . 1
0
) (
) (
) (
) (
0 1818 . 31 4545 . 0 0
1 0 0 0
0 6727 . 2 1818 . 0 0
0 0 1 0
) (
) (
) (
) (
t u
t
t
t x
t x
t
t
t x
t x
+
÷
÷
=
o
o
o
o
(4.1)
) (
0
0
) (
) (
) (
) (
0 1 0 0
0 0 0 1
) ( t u
t
t
t x
t x
t y
+
=
o
o
The design criteria for this system with the cart receiving a step input are as follows:
 Settling time for x and theta of less than 5 seconds.
 Rise time for x of less than 1 second.
 Overshoot of theta less than 20 degrees (0.35 radians).
 Steadystate error within 2%.
For the PID controller, two controllers are needed to control both the carts’ position
and pendulum’s angle simultaneously. Using statespace method, it is relatively
simple to work with a multioutput system.
30
In this chapter, a LQR controller design with both the pendulum's angle and
the cart's position are considered. The equation 4.1 has been determined using the
method as discussed in the inverted pendulum modeling part in Chapter 2. This
problem can be solved using full state feedback. The schematic of this type of
control system is shown in Figure 4.1.
Full State Feedback
K
R
y
x
+

) ( ) (
) ( ) ( ) (
t Cx t y
t By t Ax t x
=
+ =
Figure 4.1: Schematic diagram for inverted pendulum in statespace form
where,
A = state matrix; R = step input to the cart
C = output matrix; D = direct transmission matrix
X(t) = state vector; u(t) = input vector;
y(t) = output vector B = input matrix
In this problem, R represents the commanded step input to the cart. The four states,
( ) represent the position and velocity of the cart and the angle and angular
velocity of the pendulum. The output y contains both the position of the cart and the
angle of the pendulum. A controller will be designed so that when a step input is
given to the system, the pendulum should be displaced, but eventually return to zero
o o
, , , x x
31
(i.e. the vertical) and the cart should move to its new commanded position. The first
step in designing this type of controller is to determine the openloop poles of the
system. The Matlab command of this step can be referred to the Appendix A5. There
is one righthalfplane pole at 5.57. This proved that the system is unstable in open
loop.
4.2.1 LQR Control Method
The next step in the design process is to assume that the system have full
state feedback. By finding the vector K, the feedback control law is determined. If
the desired closedloop poles know, the place or acker command could be used.
Another option is to use the LQR function that will give the optimal controller.
Using the LQR function, two parameters i.e. R and Q can be chosen, which will
balance the relative importance of the input and state in the cost function for
optimizing.
The simplest way is to assume R=l, and Q=C'*C. Essentially, the LQR
method allows for the control of both outputs. In this case, the LQR controller
design will be easier to do. The controller can be tuned by changing the nonzero
elements in the Q matrix to get a desirable response. To find the structure of Q, the
term Q = C’ * C is entered into the Matlab command window.
The element in the (1, 1) position (i.e. at the columnl, row1) will be used to
weight the cart's position and the element in the (3, 3) position (i.e. at column3, row
3) will be used to weight the pendulum's angle. The input weighting R will remain at
1. Since the Q matrix has been determined previously, therefore the K matrix that
will produce a good controller could be found by running the mfile code in Matlab.
32
The response can be plotted easily in one step so that changes can be made in the
control and it can be automatically seen in the system output.
Matlab command of this step can be referred to the Appendix A5. The
response plot is shown in the Figure 7.8 in Chapter 7 for the step response with LQR
control. However, this plot is not satisfactory achieved. The pendulum and cart's
overshoot appear fine (less than 0.35 radians), but the settling times (Ts) need
improvement and the cart's rise time (T
r
) needs to go down. This error will be dealt
with in the next section by adding a reference input to the system block diagram.
The x and y variables could be changed to see the various responses. As an
example, when the command with x = 5000 and y = 100 is put in Matlab command
window, the best response should be obtained (see Appendix A5 for the command
to get step response with LQR control). If x and y are increased even higher,
improvement to the response should be obtained even more. But, for this case, the
plot of Figure 7.8 was chosen because it satisfied the design requirements while
keeping x and y as small as possible. In this problem, the values of x and y have
been used to describe the relative weight of the tracking error in the cart's position
and pendulum's angle versus the control effort. The higher x and y are given, the
more control effort is used, but the smaller the tracking error.
4.2.2 Adding a Reference Input
In contrast to the other design methods, where the output is feedback and
compared to the reference input to compute an error, with a fullstate feedback
controller, all the states are feedback so that it can be multiplied with the K matrix.
33
It is required to compute the steadystate value of the states should be,
multiply that by the chosen gain K, and use a new value as a reference for computing
the input. This can be done by adding a constant gain named Nbar, (N) after the
reference. The schematic of this relationship is shown in Figure 4.2.
K
N R
y
x
+

Cx y
By Ax x
=
+ =
Figure 4.2: Schematic diagram of system with constant gain, Nbar
Nbar,( N
*
) can be found using the userdefined function rscale. This function
is not a standard function provided in the Matlab control system toolbox. This
function is built in mfile code as shown in Appendix A6. In order to use rscale
function, the mfile code of Nbar should be run together with the Matlab command
for LQR design. The lsim line should be deleted while the rscale function is copied
into the command window. The step response with consideration of Nbar,( N
*
) can
be seen by running the mfile code. A different C had to be used because the rscale
function will not work for multiple outputs. However, the value of Nbar,( N
*
) is
found correct as shown below:
Nbar = 70.7107
34
The step response with LQR and Nbar control is shown as in the Figure 7.9 in
Chapter 7. The steadystate error is within limit, the rise and settling times are met
and the pendulum's overshoot is within range of the design criteria.
4.2.3 FullOrder Estimator
This response can be consider as a good response, but was found assuming
fullstate feedback, which most likely will not be a valid assumption. To compensate
this problem, the next design is a fullorder estimator to estimate those states that are
not measured. A schematic of this kind of system without Nbar is shown in Figure
4.3
Figure 4.3: Schematic diagram of system in statespace with estimator
In order to design full order estimator, the controller poles have to be found
first. This step could be done by copying the following code to the end of mfile
p = eig(Ac)
35
The estimator poles are about 4 to 10 times as fast as slowest pole, say at 40
is chosen. The place command in Matlab is used to find the L vector. The place
command cannot have all the desired poles at the same location. The lsim command
should be deleted and the command for P and L is entered as shown in the Appendix
A7 at the end of current mfile to find the L matrix. Both outputs have been used
(the angle of the pendulum and the position of the cart) to design the estimator. The
system is not observable using only the angle of the pendulum as output. The
situation could be checked via Matlab command.
rank(obsv(A,C(2, :)))
The system is observable if the output of the rank command is equal to four .
If the only angle of the pendulum could be measured, it is cannot determine what the
position of the cart will be. Now combination of the controllaw design and the
estimator design is proposed to get the compensator. The response should be similar
to the one from the controllaw design. Then, it is needed to copy the MATLAB
command in the Appendix A7 to find the step response for the system with estimator.
By running the mfile, the step response simulation is plotted as shown in the
Figure 7.10 in Chapter 7 should be determined. It is found that all of the design
requirements have been met with the minimum amount of control effort, so no more
iteration is needed.
36
4.3 Conclusion
As a conclusion, it is found that LQR statespace method is the best control
method to control a multioutput system compared to PID control method which was
described previously. The higher x and y are given, the more control effort is used,
but the smaller the tracking error is get. Then by adding a reference input, the steady
state error is within the limits, the rise and settling times are met and the pendulum's
overshoot is within range of the design criteria. By applying a combination of the
controllaw design and estimator to get the compensator, it is determined that all of
the design requirements have been met successfully. However, The PID and LQR
controllers are both could control the linear system or a linearized model. This
drawback can be solved by applying the Artificial Intelligent controller such as FLC
and ANN. This type of controller will be discussed in the next chapter.
37
CHAPTER V
FUZZY LOGIC CONTROLLER
5.1 Where Did Fuzzy Logic Come From
The concept of Fuzzy Logic Controller (FLC) was conceived by Lotfi Zadeh,
a professor at the University of California at Berkley, and presented not as a control
methodology, but as a way of processing data by allowing partial set membership
rather than crisp set membership or nonmembership. This approach to set theory
was not applied to control systems until the 70's due to insufficient smallcomputer
capability prior to that time. Professor Zadeh reasoned that people do not require
precise, numerical information input, and yet they are capable of highly adaptive
control. If feedback controllers could be programmed to accept noisy, imprecise
input, they would be much more effective and perhaps easier to implement. [13]
5.2 What Is Fuzzy Logic
In this context, FLC is a problemsolving control system methodology that
lends itself to implementation in systems ranging from simple, small, embedded
microcontrollers to large, networked, multichannel PC or workstationbased data
38
acquisition and control systems. It can be implemented in hardware, software, or a
combination of both. FLC provides a simple way to arrive at a definite conclusion
based upon vague, ambiguous, imprecise, noisy, or missing input information. FLC's
approach to control problems mimics how a person would make decisions, only
much faster. [4]
Figure 5.1 shows the comparison method between Fuzzy Logic controller and
PID controller. As can be seen, in order to design PID controller, the inverted
pendulum model should be linearized. This will produce inaccurate model if it is
applied to the real system. In contrast with the FLC controller, the inverted
pendulum does not need to be linearized. However the model should be fuzzify and
defuzzify by applying reasoning with fuzzy control rules.
u
INVERTED
PENDULUM
X
DESIGN PID CONTROLLER
LINEARISE
APPLY PID
CONTROLLER
STABILISE AN
INVERTED
PENDULUM
PENDULUM IS
STABILISED
FUZZIFY
REASONING WITH
FUZZY CONTROL RULES
DEFUZZIFY
CONTROL SIGNAL
F
Figure 5.1: Comparison between Fuzzy Logic controller and PID controller
When idea of fuzzy logic is applied to control, it is generally called as ' fuzzy
control. Fuzzy control is the first ever known to which fuzzy logic is applied. Main
areas of application are numerous, such as control of cement kilns, electric trains,
water purification plants etc. Many research activities and application are going on
especially in Japan. [11]
39
5.2.1 The Form of Fuzzy Control Rules and Inference Method
Fuzzy control describes the algorithm for process control as a fuzzy relation
between information about the condition of the process to be controlled, x and y and
the input for the process (amount of work). The control algorithm is given in the IF 
THEN expression such as
if x is small and y is big then z is medium.
if x is big and y is medium, then z is big.
The above expression can be simplified into another statement as shown in Figure
5.2.
Figure 5.2: Control algorithm of fuzzy logic controller
This way of control is synonymous to a control applied by a worker or a
driver, i.e. an expert who controls a system. For example, driver wants to go up to
100 km / h and car goes at 20 km / h (relatively small speed) and acceleration is
small then driver increases the speed of car largely. In that sense, the driver uses the
above mentioned if  then clause. Naturally, a driver does not calculate the speed,
acceleration, time needed to reach 100 km/h, he just uses the rules which he has
learned beforehand. These rules are such as ' if speed gets too high, push the break
firmly or if he is taking a hill and there is snow on the road then go moderately ' and
so on.
The above mentioned if clause of the rules is called the antecedent and the '
then 'clause is called ' consequent '. In general, variables x and y are called the input
40
and the z output. Small, big, firmly, moderately etc. are fuzzy variables for x and y
and they are expressed by fuzzy sets.
Although the fuzzy variables are used, input and output of the system are not
linguistics variables but certain mathematical values (crisp values). In order to
fuzzify these crisp values, membership functions are used both for input and output.
Figure 5.3 and Figure 5.4 show the triangular membership function and trapezoidal
membership function of fuzzy logic controller respectively. Normally, the amplitude
or grade of the membership function is set to 1. However, the range of the
membership function or universe of discourse can be varied within a specified range.
The range gives a major effect to the system response because it will affect the fuzzy
reasoning.
Figure 5.3: A Triangular membership function of Fuzzy Logic Controller
Figure 5.4: A H Type membership function
41
There are two types of fuzzy variables, continuous and discrete types. Discrete fuzzy
variables are the simplifying method for continuous fuzzy variables as shown in
Table 5.1
Table 5.1: Discrete type of fuzzy variables
Input Domain
0 1 2 3 4 5 6
PB 0 0 0 0 3 7 10
PM 0 0 3 7 10 7 3
PS 0 3 7 10 7 3 0
ZR 10 7 3 0 0 0 0
As number of discrete variables increases it approaches to continuous type of
fuzzy variables. However, as number of discrete variables increases computing time
also increases i.e. increasing respond time. As a result an optimization should be
carried out between the resolution and computing time. Fuzzy controllers are
constructed of groups of these fuzzy control rules, and when an actual input is given,
the output is calculated by means of fuzzy inference. Fuzzy inference is based on
fuzzy logic, but in consideration of the time for the calculation, simple methods are
used. The inference for fuzzy control is different from standard fuzzy inference in
that the propositions (the actual input for the fuzzy controller) are commonly
standard numerical values, not fuzzy values. The major difference between the
methods used in areas such as production rules for knowledge engineering and fuzzy
control is that latter permits fuzzy expression (single stage inference) whereas the
former is almost multistage. Block diagram of the fuzzy controller is given as shown
in Figure 5.5.
42
Figure 5.5: Block diagram of fuzzy controller
5.2.2 Type of Fuzzy Controllers
5.2.2.1. Inference Method 1
In fuzzy inference method 1, it is common to have five to seven fuzzy
variables. [12]
A two input, singleoutput instance of this inference method comes out as follows.
If x1 is A11, x2 is A12 then y is B1
If x1 is A21, x2 is A22 then y is B2
The above two rules may be applied to case of single input single output
process set point control, and x1 is error x2 is delta error ( the change in error during
one sampling) and delta u for the output.
43
In each control loop, two crisp values of x1 = x1o and x2= x2o are provided
by some means, such as sensor and analoguedigital converter. The first step in the
control loop is to find out compatibility for each of the compatibility antecedent
conditions of the rules and the input. In general, let the compatibility for the
antecedent 'x is A ' be A(x0), that is, the membership function of x0 for fuzzy set A.
In this example the antecedent is two dimensional, so compatibility will be;
wi=min ( Ai1( x1o), Ai2 (x20) i=1,2
where
i is the number of the rule, and min is the function which gives minimum of its
parameters.
The next step is to get the results of the inference for the ith rule, i.e.
y is wiBi but wi Bi ( y) = wi x Bi(y)
There are cases where a min operation replaces the multiplication as
wi Bi(y)= wi ·Bi ( y).
The complete inference result yo is constructed from the w1B1 and w2B2,
B*=w1B1 · w2B2
and found as the central axis of the membership function of B* as
dy y B
ydy y B
y
) ( *
) ( *
0
¯
¯
=
It is also shown graphically in Figure 5.6.
44
The first inference method is made of the following three steps. In fact, these are
essentially the same for all inference methods.
(1) Calculate the compatibility for the inputs and antecedent of the rules
(2) Find the inference results for each rule
(3) Find the complete inference result as a weighted mean of the inference results for
each rule with respect to compatibility
Schematic representation of this inference method is given in Figure 5.6
Figure 5.6: Schematic representation of Inference Method 1
45
5.2.2.2 Inference Method 2
This second method is especially suitable for the fuzzy variables that have
monotony membership functions, such as shown in Figure 5.7. It can be easily seen
from the figure that there are only two types of variables as positive and negative and
as can easily be seen from the figure that arctan(x) can be used for the membership
function. There are also changes in slope.
Figure 5.7: Monotonic membership functions
As an example, consider the following two rules,
if x1 is N and x2 is P then y is N
if x1 is P and x2 is N then y is P
Here in this method, there is no difference between first and second method
for finding the compatibility of the antecedent for inputs x10 and x20 and w1 and w2
are found for the first and the second rules respectively.
46
Inference results y1 and y2 (non fuzzy crisp values) for each rule are found using the
following relational equations.
w1= N(y1) and w2=P(y2)
The overall inference result is given by taking the weighted mean of y1 and y2. The
inference method is shown in below Figure 5.8
Figure 5.8: Schematic representation of Inference Method 2
If a comparison is made between first and the second methods, these
differences can be found;
i) Fewer rules are necessary for the second method than for the first one
ii) First method is suitable when there are many fuzzy variables
iii) Since there are few fuzzy variables, Second method is not a suitable one for
putting the knowledge of expert, i.e. taking linguistic form into logical form.
47
5.2.2.3. Inference Method 3
The antecedents used in this method are made up of fuzzy propositions, and
the consequent are the standard relational equations of inputs and outputs. This was
conceived for fuzzy process modeling rather than for fuzzy control. The fuzzy
variables used in the antecedent are trapezoidal membership functions composed of
straight lines.
Consider the following two rules;
if x1 is A11, x2 is A12 then y=f1(x1, x2)
if x1 is A21, x2 is A22 then y=f2( x1, x2)
The compatibility of antecedents for x1 and x2 is found as w1 and w2
respectively, and then inference results for each of the rules are calculated directly
from the equations written in the consequent. The complete inference result is found
using the following equation, as done in Inference Method 2.
In this method f11 and f22 are linear equations. It can be easily seen that if
number of rules is 1, the antecedent parts are no longer necessary, and only
consequent part remains; so the result is the same as having a linear expression.
48
If there is more than one rule, the input interval is partitioned into subspaces
and a linear input / output relation is found for each subspace; that group gives
something very similar to global nonlinear inputoutput relation. This method is not
suitable for linguistic expressions but exceeds the others in descriptive capability.
The rules used in inference method 1 do not go beyond description of quantitative
relations.
In fact, there is no difference in the structure of the relation
if x1 = PB ( positive big) and x2=PS ( positive small) then y = NM (negative
medium )
if x1 = 10 and x2 = 2 then y = 6
In other words, they are numerical tables and only quantify amount.
However, the rules that arise using the conditions (subspaces) specified in the
antecedents in the third form are written directly in the consequent.
5.3. Planning Of Fuzzy Controllers
In designing fuzzy control, the problem of determining the form of the
control rules is very crucial. This problem can be divided into two parts, i.e.
determination of the antecedents and the determination of the consequent. For the
antecedent part, three things have to be determined.
1) The input information for x1, x2, and etc which must be used in the antecedents is
selected
49
2) Determination of the conditions, that is, the fuzzy partitions of the input
3) Determination of the parameters for the fuzzy variables.
For the consequent part, output is generally the control input for the process
controlled. The only remaining problem is the fuzzy parameters. Determination of
the consequent is not difficult, and the only problem is the wholly determination of
the antecedents.
5.4 How Is FLC Different From Conventional Control Methods
FLC incorporates a simple, rulebased IF X AND Y THEN Z approach to a
solving control problem rather than attempting to model a system mathematically.
The FLC model is empiricallybased, relying on an operator's experience rather than
their technical understanding of the system. For example, rather than dealing with
temperature control in terms such as "SP =500F", "T <1000F", or "210C <TEMP
<220C", terms like "IF (process is too cool) AND (process is getting colder) THEN
(add heat to the process)" or "IF (process is too hot) AND (process is heating rapidly)
THEN (cool the process quickly)" are used. These terms are imprecise and yet very
descriptive of what must actually happen. Consider what you do in the shower if the
temperature is too cold: you will make the water comfortable very quickly with little
trouble. FLC is capable of mimicking this type of behavior but at very high rate.
50
5.5 How Does FLC Work
FLC requires some numerical parameters in order to operate such as what is
considered significant error and significant rateofchangeoferror, but exact values
of these numbers are usually not critical unless very responsive performance is
required in which case empirical tuning would determine them. For example, a
simple temperature control system could use a single temperature feedback sensor
whose data is subtracted from the command signal to compute "error" and then time
differentiated to yield the error slope or rateofchangeoferror, hereafter called
"errordot". Error might have units of degs F and a small error considered to be 2F
while a large error is 5F. The "errordot" might then have units of degs/min with a
small errordot being 5F/min and a large one being 15F/min. These values don't
have to be symmetrical and can be "tweaked" once the system is operating in order to
optimize performance. Generally, FLC is so forgiving that the system will probably
work the first time without any tweaking. [42]
5.6 Fuzzy Of Inverted Pendulum System
FLC was conceived as a better method for sorting and handling data but has
proven to be an excellent choice for many control system applications since it
mimics human control logic. It can be built into anything from small, handheld
products to large computerized process control systems. It uses an imprecise but
very descriptive language to deal with input data more like a human operator. It is
very robust and forgiving of operator and data input and often works when first
implemented with little or no tuning. In this study, a very new technique, fuzzy
controller, has been employed for stabilization of the inverted pendulum. Fuzzy
controller, when inverted pendulum is considered, is a very good choice for control
strategy. The reasons are nonlinearity, complex mathematical computation and real
time computation need. Fuzzy controller fits the requirements very well in such
51
cases. Moreover, applying a new technique offers new horizons to the researcher,
especially for higher complex systems which need direct expert control.
5.6.1 Fuzzy Logic Controller Design Flow Chart
Figure 5.9 shows the flow of designing the fuzzy logic controller. Generally,
in designing the controller, it is important to plan the characteristic of the controller.
In designing FLC, the input and output of the system, number of fuzzy partitions
must be identified, type of membership functions should be chosen correctly, fuzzy
control rulesbased must be derived. Moreover, the inference engine and the
defuzzification method should be chosen correctly. By following the flow chart as
shown in Figure 5.9, the FLC can be designed successfully.
Design Planning
Identify process input and output variable
Identify controllers’ inputs and outputs
Determine of number fuzzy partitions
Choose type of membership functions
Derive fuzzy control rulesbased
Define inference engine
Choose Defuzzification method
Parameter Tuning
Mapping of membership functions
Fuzzy inference rules
Scaling factors
Fuzzy Logic Controller
Operation
Fuzzification
Fuzzy inference
Defuzzification
Simulation & Testing
OK
Yes
No
End
Figure 5.9: Fuzzy Logic controller design flow chart
52
From Figure 5.10 and Figure 5.11, it can be seen that the input of the system
is the disturbance force. The outputs of the system are the cart displacement, cart
velocity, pendulum angle, and angular velocity of the pendulum. All of these system
outputs will then be sent to the FLC s inputs. The FLC will manipulate the
information and produces the output force that is back propagated to the system.
In this problem, it is possible to give two inputs to the FLC as shown in
Figure 5.11. The proposed defuzzification methods for the FLC are Sugeno or
Mamdani. This is because both of these techniques are commonly used in designing
the FLC.
u
INVERTED
PENDULUM
(NONLINEAR)
A
A
o
o
X
X
F
F
FLC
CONTROLLER
Figure 5.10: Block diagram of the system with fuzzy logic controller
In order to implement four inputs to the controllers, the FLC were divided
into two. As can be seen in Figure 5.11, the ‘FLC 1’ controls the cart’s position,
whereas the ‘FLC 2’ controls the pendulum’s angle. The ‘FLC 1’ received x and ǻx
53
as the inputs while the ‘FLC 2’ received Į and ǻĮ as the inputs. The control
variables of both FLC were summed together to become a force and the input to the
system.
FLC 1
(Control
Position)
FLC 2
(Control
Angle)
Position
Force
Angle
+
+


+
+
Reference
position
Reference
Angle
ǻx
ǻĮ
x
Į
Figure 5.11: Rearranged block diagram of the system with Fuzzy Logic Controller
Figure 5.12 shows the FLC block diagram. This block diagram shows the
flow of the FLC in detail. As stated in the diagram, the defuzzification method used
is the Mamdani Sugeno type.
54
INFERENCE
ENGINE FUZZIFIER DEFUZZIFIER
KNOWLEDGE
BASE
PROCESS
FUZZY CONTROLLER
FUZZY FUZZY
PROCESS OUTPUT
& STATES
CRISP CONTROL
SIGNAL
4 Inputs Mamdani
Sugeno
Figure 5.12: Fuzzy logic controller block diagram
5.6.2 Inputs and Outputs of FLC
Through observations the input and output fuzzy variables has been identified. This
is shown in Table 5.2.
Table 5.2: Inputs and outputs of FLC
No Input Output
1.
Angle between pendulum shaft/pole
and vertical line, Į
2.
Angular velocity of pendulum
shaft/pole, ǻĮ
3.
Difference (error signal) between
position of cart and set point
position, x
4.
Rate at which the error of position
changes, ǻx
Force to push the cart, F
55
5.6.3 Membership functions
The input and output variables have to be quantized into several modules or
fuzzy subsets and the appropriate labels are assigned in this controller. Two fuzzy
logic controllers are needed to excite the stabilize force to the cart. There are FLC to
control position and FLC to control angle. According to the complexity of this
inverted pendulum system, seven fuzzy subsets are needed to quantize each fuzzy
variable for both FLC as sown in Table 5.3.
Table 5.3: Standard labels of quantization
Linguistic Term Label
Negative Big NB
Negative Medium NM
Negative Small NS
Zero ZE
Positive Small PS
Positive Medium PM
Positive Big PB
Figure 5.13 till Figure 5.18 show the membership functions of FLC’s. The
triangular shape was used to design the FLC. In addition, the membership functions
were evenly distributed. It was done so that the tuning process of the controller can
be easily done. As we can see from the figure, the ranges of the membership
functions are different to each other. It was the crucial step to determine the
appropriate values. It is needed to know the nature of the plant from the expert
knowledge. This can be acquired from the previous research papers that were done
by the expert.
56
Membership functions for each of the fuzzy subsets of the control position FLC
3 2 1 0 1 2 3
0
0.2
0.4
0.6
0.8
1
Position
D
e
g
r
e
e
o
f
m
e
m
b
e
r
s
h
i
p
NB NM NS ZE PS PM PB
Figure 5.13: Input 1 of Fuzzy Logic Controller 1
3 2 1 0 1 2 3
0
0.2
0.4
0.6
0.8
1
Delposition
D
e
g
r
e
e
o
f
m
e
m
b
e
r
s
h
i
p
NB NM NS ZE PS PM PB
Figure 5.14: Input 2 of Fuzzy Logic Controller 1
57
10 8 6 4 2 0 2 4 6 8 10
0
0.2
0.4
0.6
0.8
1
Force
D
e
g
r
e
e
o
f
m
e
m
b
e
r
s
h
i
p
NB NM NS ZE PS PM PB
Figure 5.15: Output of Fuzzy Logic Controller 1
Membership functions for each of the fuzzy subsets of the control angle FLC:
0.25 0.2 0.15 0.1 0.05 0 0.05 0.1 0.15 0.2 0.25
0
0.2
0.4
0.6
0.8
1
Angle
D
e
g
r
e
e
o
f
m
e
m
b
e
r
s
h
i
p
NB NM NS ZE PS PM PB
Figure 5.16: Input 1 of Fuzzy Logic Controller 2
58
1 0.8 0.6 0.4 0.2 0 0.2 0.4 0.6 0.8 1
0
0.2
0.4
0.6
0.8
1
Delangle
D
e
g
r
e
e
o
f
m
e
m
b
e
r
s
h
i
p
NB NM NS ZE PS PM PB
Figure 5.17: Input 2 of Fuzzy Logic Controller 2
10 8 6 4 2 0 2 4 6 8 10
0
0.2
0.4
0.6
0.8
1
Force
D
e
g
r
e
e
o
f
m
e
m
b
e
r
s
h
i
p
NB NM NS ZE PS PM PB
Figure 5.18: Output of Fuzzy Logic Controller 2
59
5.6 Rule base
Table 5.4 and Table 5.5 show the fuzzy rule matrix for controlling the
position and fuzzy rule matrix for controlling the angle respectively. As can be seen
from the tables, all the rules are the same. The total rules that should be given are 49
rules. However, there are only 34 rules that are applied to the controllers.
Table 5.4: Fuzzy rule matrix for control position FLC
POSITION
NB NM NS ZE PS PM PB
NB NB NM NS NS PS PM PB
NM NM NS NS PS PM
NS NS NS PS
ZE NB NM NS ZE PS PM PB
PS NS PS PS
PM NM NS PS PS
D
E
L
P
O
S
I
T
I
O
N
PB NB NM NS PS PS PM
Table 5.5: Fuzzy rule matrix for control angle FLC
ANGLE
NB NM NS ZE PS PM PB
NB NB NM NS NS PS PM PB
NM NM NS NS PS PM
NS NS NS PS
ZE NB NM NS ZE PS PM PB
PS NS PS PS
PM NM NS PS PS
D
E
L
A
N
G
L
E
PB NB NM NS PS PS PM
60
5.6.4 Implementation in Simulink
Figure 5.19 shows the schematic diagram of the Nonlinear Inverted
Pendulum System with two FLC controllers in Simulink. As can be seen from the
figure, there are 2 FLC’s in the diagram. Each of them has a function to control the
position of a cart and to control the angle of the pendulum respectively. The output
of the controllers is the forces which will be summed up together to produce
equivalent force to the plant system. The tuning process of the FLC is more difficult
compared to PID and LQR controllers. This is because there are a lot of parameters
need to be considered such as membership functions, gains, range values and etc.
The output response of the system will be discussed in Chapter 7.
61
xdot
x
tetadot
si mout1
posi ti on
nonl i near i nverted pendul um
si mout
angl e
Total
Force
0.675
Target Posi ti on
(MouseDri ven)
Target Posi ti on
Swi tch
Step1
R2D
Radi ans
to Degrees
Mux
Mux
Mux
Mux
Manual
Swi tch
1
Gai n1
.94
Gai n
Fuzzy Logi c
Control l er
(Posi ti on)
Fuzzy Logi c
Control l er
(Angl e)
1 Constant
ani mcp
Ani mati on
Figure 5.19: Schematic diagram of the Nonlinear Inverted Pendulum system with
two FLC controllers in Simulink
62
5.6 Conclusion
As a conclusion, the control objective in stabilizing the inverted pendulum
has been achieved by using two block of Fuzzy logic controller. This can be verified
through the output responses of the system which satisfy the design criteria. The
controller design could stabilize the pendulum rod and keeping the cart in a desired
position. Fuzzy logic has provided a simple way without going through the
mathematical approach as conventional controller in order to arrive at a definite
conclusion based upon nonlinear and an unstable of inverted pendulum system.
63
CHAPTER VI
ARTIFICIAL NEURAL NETWORKS CONTROLLER
6.1 Introduction
A neural network is an informationprocessing paradigm inspired by the way,
the brain processes information [8]. It is composed of a large number of highly
interconnected processing elements (neurons) working in parallel to solve a specific
problem. ANNs learn by example, trained using known input/output data sets to
adjust the synaptic connections that exist between the neurons. The biological
neuron is composed of a large number of highly interconnected processing elements
called neurons and is tied together with weighted connections or synapses. Learning
in biological systems involves adjustments to the synaptic connections that exist
between the neurons. These connections store the knowledge necessary to solve
specific problems. The biological neuron can be illustrated in Figure 6.1.
64
Figure 6.1: Biological neuron
One of the most interesting features of NNs is their learning ability. This is
achieved by presenting a training set of different examples to the network and using
learning algorithms, which changes the weights (or parameters of activation
functions) in such a way that the network will reproduce a correct output with the
correct input values. One encountered difficulty is how to guarantee generalization
and to determine when the network is sufficiently trained. A neural network offers
nonlinearity, inputoutput mapping, adaptivity and fault tolerance. Nonlinearity is
a desired property if the generator of the input signal is inherently nonlinear [10].
The high connectivity of the network ensures that the influence of errors in a few
terms will be minor, which ideally gives a high fault tolerance.
6.2 Advantages of ANN’s
There are several advantages of ANN as follows:
1. The main advantage of neural networks is that it is possible to train a neural
network to perform a particular function by adjusting the values of connections
(weights) between elements. For example, to train a neuron model to approximate a
65
specific function, the weights that multiply each input signal will be updated until the
output from the neuron is similar to the function.
2. Neural networks are composed of elements operating in parallel. Parallel
processing allows increased speed of calculation compared to slower sequential
processing. The example of neuron model is illustrated in Figure 6.2
Figure 6.2: Diagram of neuron model
Artificial neural networks (ANN) have memory. The memory in neural networks
corresponds to the weights in the neurons. Neural networks can be trained offline
and then transferred into a process where adaptive learning takes place. In this case,
a neural network controller could be trained to control an inverted pendulum system
offline say in the simulink environment. After training, the network weights are set.
The ANN is placed in a feedback loop with the actual process. The network will
adapt the weights to improve performance as it controls the pendulum system.
The main disadvantage of ANN is they operate as black boxes. The rules of
operation in neural networks are completely unknown. It is not possible to convert
the neural structure into known model structures such as Armax, etc. Another
disadvantage is the amount of time taken to train networks. It can take considerable
time to train an ANN for certain functions.
66
6.3 Types of Learning
Neural networks have three main modes of operation – supervised, reinforced
and unsupervised learning [6]. In supervised learning the output from the neural
network is compared with a set of targets, the error signal is used to update the
weights in the neural network. Reinforced learning is similar to supervised learning
however there are no targets given, the algorithm is given a grade of the ANN
performance. Unsupervised learning updates the weights based on the input data
only. The ANN learns to cluster different input patterns into different classes.
6.4 Neural network structures
There are three main types of ANN structures single layer feedforward
network, multilayer feedforward network and recurrent networks. [7] The most
common type of single layer feedforward network is the perceptron. Other types of
single layer networks are based on the perceptron model. The details of the
perceptron is shown in Figure 6.3
Figure 6.3: Diagram of the Perceptron model
Inputs to the perceptron are individually weighted and then summed. The perceptron
computes the output as a function F of the sum. The activation function, F is needed to
67
introduce nonlinearities into the network. This makes multilayer networks powerful in
representing nonlinear functions. [5]
6.5 Activation functions
There are number of different types of activation functions such as step,
ramp, sigmoid etc. However the most commonly used activation functions are tan
sigmoid, logsigmoid and linear function as shown in Figure 6.4. The effect of the
linear function is to multiply by a factor a constant factor. The sigmoid function has
an S shaped curve. [9]
Logsigmoid function Tansigmoid function Linear function
Figure 6.4: Activation functions
6.6 Learning Algorithms
In neural networks learning ability is achieved by presenting a training set of
different examples to the network and using learning algorithm to changes the
weights (or the parameters of activation functions) in such a way that the network
68
will reproduce a correct output with the correct input values. There are three main
classes of learning reinforced, supervised, and unsupervised. The latter two will be
considered here.
In the supervised learning procedure, there is a set of pairs of inputoutput
patterns. The network propagates the pattern inputs to produce its own output
pattern and then compares this with the desired output. The difference is the error, if
this is absence; learning is stopped, if present error is back propagated to have weight
and bias changed. A supervised learning scheme is illustrated in Figure 6.5.
Figure 6.5: Supervised learning
6.7 Forward Modeling of Inverted Pendulum Using Neural Networks
A common structure for achieving system identification using neural
networks is forward modeling as shown in Figure 6.6. This form of learning
structure is a classic example of supervised learning. The neural network model is
placed in parallel with the system both receiving the same input; the error between
the system and network outputs is calculated and subsequently used as the network
training signal.
69
` Supervised Learning
INVERTED
PENDULUM
INPUT SYSTEM
o
o
x
x
u
LEARNING
ALGORITHM
ADJUST WEIGHT
ARCHITECTURE
u
o
o
x
x
DESIRED
RESPONSE
Figure 6.6: Forward modeling of inverted pendulum using neural networks
The block diagram of Figure 6.6 can be simplified into another form as
shown in Figure 6.7. From Figure 6.6 and Figure 6.7, it can be seen that the output
of the inverted pendulum system is compared to the desired response so that the error
signal will be produced. The error signal is then back propagated so that weight and
bias is changed as stated in the previous section.
70
INVERTED
PENDULUM
SYSTEM I/P SYSTEM O/P
o
o
x
x
u
NEURAL NETWORK
System with NN
Figure 6.7: Rearranged forward modeling of inverted pendulum using neural
networks
6.8 Learning rules
Hebb’s Rule was the first rule developed. The rule declares that when a
neuron receives an input from another neuron, and if both are highly active, then the
weight between the neurons should be strengthened. Kohonen’s learning rule is a
procedure whereby competing processing elements contend for the opportunity to
learn. The only permitted output is from the winning element, furthermore this
element plus its adjacent neighbors are permitted to adjust their connection weights.
It should also be noted that the size of the neighborhood may adjust during this
training period. The Back propagation learning algorithm is perhaps the most
popular learning algorithm. The net simply propagates the pattern inputs to outputs
to produce its own patterns comparing this with the desired output, the difference
71
being the error. If no error is present learning stops, however if error is present, it is
back propagated to change weights and biases, this recurs until no error is present.
6.9 Implementation in Simulink
Figure 6.8 show the block diagram of the Inverted Pendulum System with
two ANN controllers in Simulink. The design of the ANN in simulink is tedious to
implement. As can be seen from the figure, the diagram is more complex compared
to the other controllers that were discussed previously. In the task, ANN is divided
into 2 parts to get the equivalent force as the input to the plant. The reason of doing
this approach is that the ANN training method was done using mfile. Controller one
was used to control the angle of the pendulum while controller two was used to
control the position of the cart simultaneously. The ANN controller block was then
imported to the simulink diagram. The drawback of this approach is the online
training using the simulink diagram could not be done. Therefore, the tuning process
is difficult to do. In order to solve the problem, a few parameter blocks such as gain
and saturation blocks were added to the diagram. However, this would make the
simulation into few limitations. The output response will be discussed in Chapter 7.
72
n o n l i n e a r i n v e rt e d p e n d u l u m
f
T o W o rksp a c e 5
x d o t
T o Wo rksp a c e 4
x
T o Wo rksp a c e 3
t e t a d o t
T o Wo rksp a c e 2
t e t a
T o Wo rksp a c e 1
si m o u t
T o Wo rksp a c e
0 . 6 7 5
T a rg e t P o si t i o n
(M o u se D ri v e n )
T a rg e t P o si t i o n
S w i t c h
S t e p 1
S c o p e
S a t u ra t i o n 3
S a t u ra t i o n 2
S a t u ra t i o n 1
S a t u ra t i o n
R 2 D
R a d i a n s
t o D e g re e s
p { 1 } y { 1 }
N e u ra l N e t w o rk2
p { 1 } y { 1 }
N e u ra l N e t w o rk1
M u x
M a n u a l
S w i t c h
0 . 8
G a i n 4
1 0
G a i n 3
0 . 5
G a i n 2
0 . 9 4
G a i n 1
1 . 5
G a i n
1 C o n st a n t
a n i m c p
A n i m a t i o n
Figure 6.8: Block diagram of the inverted pendulum system with ANN in Simulink
73
In designing ANN controller, feeddforward architecture and backpropagation
learning algorithm were used as discussed in the previous chapter. Some of the
properties in designing ANN were summarized as in Table 6.1
Table 6.1: Properties of Neural Network
ANN Model
Feedforward Architecture
All signals flow in one direction only,
i.e. from lower layers (input) to upper layers (output)
Learning Rule
The Back propagation learning
Most popular learning algorithm.
The net simply propagates the pattern inputs to outputs to
produce its own patterns
Activation
Function
TanSigmoid (Hidden Layer)
Linear Function (Output Layer)
Learning
Algorithm in
ANNs
Supervised learning:
Learning with teacher signals or targets
Produce its own output pattern and then compares this
with the desired output.
The difference is the error
2 Layers
One hidden layer is suitable for the purpose of
identification.
Hornik and indeed other researchers have shown that even
a twolayer network with a suitable number of nodes in
the hidden layer can approximate any continuous function
over a compact subset [1].
74
6.9.1 Problems and constraints in designing the ANN controller
The design failure of the ANN controller because of some constrains and problems
that have been faced during the design process. Some of the factors are as follows:
1. Online training can’t be done in Simulink block instead of mfile. Therefore,
model can’t be updated directly from Simulink. The model was build in mfile,
then is was imported to the Simulink block.
2. The tuning process was difficult to do. Unlike the FLC, a lot of parameter values
can be changed directly from Simulink blocks.
3. System identification is involved. In order to train a stable model, an
identification of accurate response needs to be done. The response of the
pendulum system would depend on the training response. The generation of
teaching signal for learning can not be easily realized, and the learning hardly be
evaluated.
4. No appropriate Simulink block of multiple outputs for ANN. Since this system
involved multiple output response, the particular ANN block could not be used.
Instead of that, the block was generated from the mfile command.
6.10 Conclusion
As a conclusion, the neural network controller was not successfully designed
due to the some limitations that were previously discussed. However, the training
signal for the network model was satisfactorily achieved. Therefore, further
improvement could be done to reach the better response as required by the design
criteria.
75
CHAPTER VII
RESULTS AND DISCUSSION
7.1 Introduction
This chapter discusses the results of the open loop system without controller,
the responses of the system with several controllers such as PID, LQR, FLC and
ANN are being applied.
7.2 OpenLoop Results
As mentioned in Chapter 2, the mathematical model and equations using the
transfer function and statespace of the inverted pendulum have been determined. By
implementing all these equations into Matlab Mfile command, the following results
could be seen. From the Figure 7.1 till Figure 7.3, it can be noticed that the inverted
pendulum system is not stable without controller. The curve of the pendulum’s angle
and cart’s position were approached infinity as the time increases. Therefore, some
controllers need to be designed in order to stabilize the system.
76
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
10
20
30
40
50
60
IMPULSERESPONSE(ANGLE)
TIME(SEC)
A
M
P
L
I
T
U
D
E
Figure 7.1: Impulse response for pendulum’s angle using transfer function
Figure 7.2: Impulse response for cart’s position using transfer function
77
Cart's Position
Pendulum's Angle
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
0
10
20
30
40
50
60
70
80
90
100
TIME(SEC)
A
M
P
L
I
T
U
D
E
RESPONSE TO A STEP INPUT
Figure 7.3: Impulse response for pendulum’ angle and cart’s position using
statespace
From Figure 7.3, the green line is the response of the pendulum’s angle while
the blue line is the response of the cart’s angle. As can be seen that both of the
responses approaches infinity as time increases.
78
.3 PID Control Method
he implementation of PID control method is done by adjusting the value of gain K,
.3.1 PID Control Method
This section discusses the results of the pendulum’s angle as the value of gain
K, K
d
,
7
T
K
i
, and K
d
in order to get the best impulse response of the system.
7
K
i
changes. From Figure 7.4 and Figure 7.5, it can be seen that the graph of
the pendulum’s angle are not stable. However by using the suitable value of gain
K=100, Kd=20, Ki=1, the pendulum’s angle is satisfactorily achieved as shown in
Figure 7.6
Figure 7.4: Impulse response for pendulum’s angle for K=1, K
d
=1, K
i
=1
79
Figure 7.5: Impulse response for pendulum’ angle for K=100, Kd=1, Ki=1
Figure 7.6: Impulse response for pendulum’ angle for K=100, Kd=20, Ki=1
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
0.2
0.15
0.1
0.05
0
0.05
0.1
0.15
0.2
IMPULS RESPONSE
PID CONTROL (K=100,Kd=20,ki=1)
TIME(SEC)
A
M
P
L
I
T
U
D
E
E
X: 0.04
Y: 0.0417
X: 0.04
Y: 0.0417
80
.3.2 Cart’s Position
It is found that the pole/zero at the origin cancelled out of the transfer
functio
7
n for o have been put back in for the closed loop transfer function of cart’s
position to the impulse input. So, denl = den2, and it is making calculations easier.
From Figure 7.7, it can be seen that the cart moves in the negative direction
with a
PID Controller
i=1
constant velocity. So although the PID controller stabilizes the angle of the
pendulum, this control method would not be feasible to be implemented on an actual
physical system that was presented of cart's position and pendulum's angle as the
outputs of the system.
Figure 7.7: Impulse response of cart’s position for K=100, Kd=20, K
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
0.6
0.5
0.4
0.3
0.2
0.1
0
0.1
IMPULSERESPONSE
TIME(SEC)
P
O
S
I
T
I
O
N
O
F
C
A
R
T
81
.3.3 Pendulum's Angle and Cart's Position
Since one PID controller could not stabilize both of the angle and the position
of the
y using the Ziegler and Nichols method, the parameters of both PID
control
7
pendulum and the cart, another PID controller is applied to the diagram as
discussed in Chapter 3.
B
lers were determined successfully. For the PID controller 1, the parameter
values inside the block are (P=50; I=;110 D=3.5). The parameter values inside the
PID controller 2 block are (P=0.0001; I=;10 D=0.3). As stated in chapter III, the
PID controller 1 controls the angle of the pendulum while the PID controller 2
controls the position of the cart. The output responses of the system (angle and
position) are shown in Figure 7.8 and Figure 7.9 respectively. The analysis of the
output responses will be discussed in section 7.7.
82
1
Figure 7.8: Impulse response for pendulum’ angle for K=50, K
d
=3.5, K
i
=110
Figure 7.9: Impulse response for cart’s position for K=0.0001, Kd=0.3, Ki=10
0 1 2 3 4 5 6 7 8 9 10
0
0. 2
0. 4
0. 6
0. 8
1
1. 2
X: 450
Y : 1.003
X: 360
Y : 0.98
TIME (SEC)
P
O
S
I
T
I
O
N
STEP RESPONSE (POSITION)
2 3 4 5 6 7 8 9 10
4
3. 5
3
2. 5
2
1. 5
1
0. 5
0
X:
Y
108
: 0.4803
0. 5
X: 4
Y : 
48
0.02059
X
Y
: 164
:  4.392
TIM E (S E C)
A
N
G
L
E
S TE P RE S P ONS E (A NGLE )
X=1.08
Y=0.4803
X: 80
Y : 0.
2 X=8.02
0001037
Y=0.0001037
X=4.48
Y=0.02059
X=1.64
Y=4.392
X=4.5
Y=1.003
X=3.6
Y=0.98
83
7.4 LQR Control Method
7.4.1 Pendulum's Angle and Cart's Position
Using statespace methods it is relatively simple to work with a multioutput
system, so in this section, a controller is designed with both the pendulum's angle and
the cart's position consideration. Therefore the consideration of cart's position is
combined with the pendulum's angle part into a single section.
From the previous LQR design, it was determined that the controller could be
tuned by changing the nonzero elements in the Q matrix to get a desirable response.
There are two weighting elements for the Q matrix, x and y. x is used to weight the
cart's position and y is used to weight the pendulum's angle. The input weighting R
will remain at 1. The K matrix was found and the response has been plotted all in
one step so any changes could be made in the control and be seen automatically in
the response. From Figure 7.10, it can be seen that both the pendulum’s angle and
cart’s position satisfy the design requirement.
84
Figure 7.10: Step response with LQR control for x=5000 and y=100
The following is the value for K:
K = 1.0000 1.6567 18.6854 3.4594
The Figure 7.10 is the best result or response (with x=5000 and y=l00) for this
problem. It can be noted that even if the x and y are given higher, the response can
be improved even more. But, using these values (x=5000 and y=100), its response
are satisfied the design requirements while keeping x and y as small as possible.
Now, the steadystate error will be eliminated. As mentioned in the Chapter
4, it was done by adding a constant gain, Nbar( N ) after the reference. Therefore, the
result is shown in Figure 7.11
85
Figure 7.11: Step response with LQR and Nbar control for x=5000 and y= 100
Nbar = 70.7107
The steadystate error is within the limits, the rise and settling times are met the
desired requirements and the pendulum's overshoot is within range of the design
criteria.
The response is good, but it was found by assuming fullstate feedback,
which most likely will not be a valid assumption. It is needed to use an estimator to
estimate those states. It is found that the system is not observable because the rank
shown is three, not exactly four. Therefore, the controllaw design has been
combined with this estimator design to be as a compensator. The best result is
obtained as shown in Figure 7.12 with K value:
K = 1.0000 1.6567 18.6854 3.4594
86
Figure 7.12: Step response with estimator for x=6000 and y=200
All of the design requirements have been met with the minimum amount of control
effort, so no more iteration is needed. Therefore, LQR statespace method is better
control method to control a multioutput system than the PID.
87
7.5 Fuzzy Logic Controller Control Method
7.5.1 Pendulum's Angle and Cart's Position
As discussed in Chapter 5, four inputs have been applied to the FLC. The
FLC was divided into two FLC’s so that each FLC can receive two inputs from the
system. The output of each of the FLC were summed up together to produce the
equivalent force. This force was fired as the input to the system. Figure 7.13 and
Figure 7.14 show the output responses (angle and position) of the pendulum and cart
respectively. The analysis of the responses will be discussed in section 7.7.
1 2 3
Figure 7.13: Impulse response for pendulum’s angle
4 5 6 7 8 1
 2 0
 1 5
 1 0
 5
0
5
1 0
1 5
X : 1 5 3
Y : 2 0 . 2 2
2 0
X
Y
: 8 2 8
: 0 . 0 3 6
X
Y
: 2 1 3
:  1 9 . 5 2
TIM E (S E C )
A
N
G
L
E
S TE P R E S P O N S E ( A N G L E )
X=1.53
Y=20.22
X=8.28
Y=0.036
X=2.13
Y=19.52
88
0 1 2 3 4 5 6 7 8 9 10
0
0. 2
0. 4
0. 6
0. 8
1
X: 302
Figure 7.14: Impulse response for cart’s position
7.6 Artificial Neural Network Control Method
In this section, the training and simulation results are shown. Recall that the
control objective is to keep the pendulum in its up right position and the cart in the
specified position. Using the backpropagation learning algorithm with one output
layer and one input layer, the following training responses for the position and angle
were achieved.
Y: 1.036
X: 923
Y: 1.011
TIME (SEC)
P
O
S
I
T
I
O
N
STEP RESPONSE (POSITION)
X=3.02
Y=1.036
X=9.23
Y=1.011
X: 489
X=4.89
Y : 1.02
Y=1.02
89
As can be seen from the Figure 7.15 and Figure 7.16 output training response
for the pendulum’s angle and cart’s position were satisfactorily achieved. However,
for the sake of accuracy, an improvement of the training should be done so that both
desired and actual response is coincidence each other.
1 2 3 4 5 6 7 8 9
0
0 . 2
0 . 4
0 . 6
0 . 8
1
1 . 2
T IM E ( S E C )
P
O
S
I
T
I
O
N
T R A IN IN G O U T P U T R E S P O N S E ( P O S IT IO N )
Figure 7.15: Training output response of cart’s position
0 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 0 0
0
2
4
6
8
1 0
1 2
1 4
1 6
T I M E ( S E C )
A
N
G
L
E
T R A I N I N G O U T P U T R E S P O N S E ( A N G L E )
Figure 7.16: Training output response of pendulum’s angle
90
Applying the mfile command into matlab, an ANN controller block would
be generated. The block was exported into simulink diagram so that the simulation
could be operated and the system response could be analyzed. Figure 7.17 and
Figure 7.18 show the system output response of cart’s position and the system output
response of pendulum’s angle respectively.
0 1 0 2 0 3 0 4 0 5 0 6 0 0 1 0 2 0
 3 . 5
 3
 2 . 5
 2
 1 . 5
 1
 0 . 5
0
0 . 5
1
1 . 5
T I M E ( S E C )
P
O
S
I
T
I
O
N
(
m
)
S T E P R E S P O N S E ( P O S I T I O N )
Figure 7.17: System output response of cart’s position
0 1 0 2 0 3 0 4 0 5 0 6 0 0 1 0 2 0 3 0
 1 0
 8
 6
 4
 2
0
2
4
6
8
1 0
T I M E ( S E C )
A
N
G
L
E
(
D
E
G
R
E
E
)
S T E P R E S P O N S E ( A N G L E )
Figure 7.18: System output response of pendulum’s angle
91
For the cart’s angle response Figure 7.17, it can be seen that the response
goes down to infinity. Therefore, the system is not stable system. For the
pendulum’s angle response in Figure 7.18, it can be seen that the response oscillates
within 10 to 10 degrees. It does not settle down to zero which again makes the
system unstable. This could be concluded that the ANN controller design is not
satisfactorily achieved as required by the design criteria. Some modifications need to
be done especially for the cart’s position controller.
7.7 Comparative Assessment and Analysis of the Response
In the previous chapter, three controllers were successfully designed. In this
section, all the results of the controllers will be discussed. Figure 7.19 shows the
overall step responses of the cart’s position (meter) versus the time (second) are
compared. As can be seen, the red dotted line represents the cart’s position using the
LQR controller, blue dotted line represents cart’s position using PID controller and
the solid green line represents cart’s position using fuzzy controller. Notice that
there are many differences between the characteristics of the responses. All the
characteristics values of the responses are summarized in Table 7.1.
92
0 1 2 3 4 5 6 7
0 . 4
0 . 2
0
0 . 2
0 . 4
0 . 6
0 . 8
1
TIM E (S E C )
P
O
S
I
T
I
O
N
S TE P R E S P O N S E (P O S ITIO N )
L Q R
P ID
F U ZZY
Figure 7.19: Comparison of output response of cart’s position
Table 7.1 summarized the comparison of output response of cart’s position.
From this table, it can be clearly seen the difference of the characteristics between
the responses. Among three controllers, PID has the fastest rising time (T
r
) of 1.50
seconds while the LQR controller has the slowest rising time (Tr) of 0.4121 seconds.
In addition, LQR also has the smallest value of settling time, (Ts) of 2.0366 seconds
while fuzzy has the largest value of settling time, (Ts) of 4.91 seconds. From both of
these characteristics, it can be stated that the LQR controller has the ability to
response quickly compared to PID and Fuzzy controllers. For the overshoot
percentage (%OS), LQR does not has overshoot while the fuzzy controller has the
largest overshoot percentage of 2.57 %. The last characteristic is the steady state
error, (ess). Fuzzy is the only controller that has the steady state error (ess) of 0.01.
93
Table 7.1: Comparison of output response of cart’s position
Controller
Characteristics
PID LQR FUZZY
RISING TIME
(Tr)
1.50 s 0.41 s 0.95 s
SETTLING TIME
(Ts)
3.59 s 2.04 s 4.91 s
OVERSHOOT
PERCENTAGE
(%OS)
0.32 % 0 % 2.57 %
STEADY STATE
ERROR (ess)
0 0 0.01
Comparing all the characteristics from Table 7.1, LQR controller has the best
performance among three controllers. In fact, all the characteristics have fulfilled the
design criteria that were initially fixed.
94
Figure 7.20 shows the comparison of the response of the cart’s position between PID,
LQR and Fuzzy controllers in bar chart form. All the values in the bar chart are the
same as in Table 7.1.
0.32
1.5
3.59
0.00
0.41
2.04
2.57
0.95
4.91
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
PERCENT
OVERSHOOT
RISING TIME SETTLING TIME
PID LQR FUZZY
Figure 7.20: Output response of cart’s position
95
Figure 7.21 shows the overall output responses of the pendulum’s angle
(degree) versus time (second) between the PID, LQR and Fuzzy controllers. As
could be seen, all the responses finally settled down to zero which stable the
pendulum vertically upright position. All the characteristic values of the responses
were summarized in Table 7.2
0 1 2 3 4 5 6 7
4 0
3 0
2 0
1 0
0
1 0
2 0
TIM E ( S E C )
A
N
G
L
E
S TE P R E S P O N S E (A N G L E )
L Q R
P ID
F U ZZY
Figure 7.21: Comparison of output response of pendulum’s angle
96
Table 7.2: Comparison of output response of pendulum’s angle
Controller
Characteristics
PID LQR FUZZY
SETTLING TIME
(Ts)
4.48 s 3.34 s 4.82 s
MAXIMUM
OVERSHOOT
RANGE
0.50 ° 4.39 ° 19.57°  46.47 ° 20.22 ° 19.52 °
STEADY STATE
ERROR (ess)
0 0 0.03
Based on the Table 7.2, LQR has the fastest settling time of 3.34 seconds
while fuzzy has the slowest settling time of 4.82 seconds. However, for the
maximum overshoot range, PID controller has the best range which is the lowest
range among the three controllers. Both of the fuzzy and LQR controllers have
exceeded the maximum range of 20 degrees. Finally, the last characteristic, only
fuzzy controller has the steady state error of 0.03. Based on this table, PID controller
has the best response for controlling the pendulum’s angle compared to Fuzzy and
LQR. However, for the overall performance by considering both pendulum’s angle
and cart’s position, LQR controller has the best response and better performance
which satisfy the design criteria very much.
97
7.8 Discussion
The main objective of this project is to design Artificial Intelligence
controller such as FLC and ANN. Both of these AI controllers will be compared to
the Conventional controller such as PID and LQR controllers to see the performance
of the controller in order to control an inverted pendulum system. Two tasks are
involved in controlling the inverted pendulum system which is the pendulum’s angle
and cart’s position.
The controlling of the inverted pendulum is implemented by using PID
control method. From the analysis, it was found that the PID controller is a good
controller to control the singleinputsingleoutput (SISO) system. However, the PID
alone cannot be used successfully to control the cart's pendulum and pendulum's
angle simultaneously. The results displayed that the cart moves in the negative
direction with a constant velocity when an impulse force is applied to move it. So,
although the PID controller stabilizes the angle of the pendulum, this design would
not be feasible to implement on an actual physical system due to its uncontrollability
of cart's position.
Because of this reason, the block diagram of the system in Figure 3.4 was
modified into the diagram shown in Figure 3.5. Another PID controller was added to
the system so that two PID controllers could control both outputs such the angle and
the position as discussed in section 3.4. By using this approach, the system is
successfully stabilized. All of the characteristics for the both responses of the system
are met design criteria satisfactorily.
The best response is obtained by using the LQR control method. It was found
that LQR statespace method is the best control method to control a multioutput
system compared to the other methods described previously. The values of x and y
have been used to describe the relative weight of the tracking error in the cart's
98
position and pendulum's angle versus the control effort. Then by adding a reference
input, the steadystate error is reduced, the rise and settling times are met the design
criteria and the pendulum's overshoot is within range specified. By applying a
designed estimator and a combination of the controllaw design and estimator design
as a compensator, it is determined that all of the design requirements were met
successfully.
For the fuzzy logic controller and the artificial neural network controller,
different method will be done to control the cart’s position and the pendulum’s angle.
In this approach, the nonlinear system of inverted pendulum will be controlled.
Since the AI controller can control the multi input – multi output system, this
controller is assumed to be practically done in real time application.
As discussed in Chapter 5, FLC incorporates a simple rulebased IF X AND
Y THEN Z approach to a solving control problem rather than attempting to model a
system mathematically. FLC requires some numerical parameters in order to operate
such as what is considered significant error and significant rateofchangeoferror,
but exact values of these numbers are not critical unless very responsive performance
is required in which case empirical tuning would determine them.
However the tuning process was the difficult part to do. A lot of parameters
were needed to be changed. In this case, two parameters gave a major effect of the
response. First was the scale of the membership function or the universe of
discourse, and the second parameter was the fuzzy rules. This problem was solved
by applying the standard fuzzy rules generated from the under damped response
curve. This response was transform into fuzzy rules using the following formula:
) ( ) ( ) ( k y k r k e ÷ =
) 1 ( ) ( ) ( ÷ ÷ = A k e k e k e
99
Then, the rules as summarized in Table 5.4 and Table 5.5 were determined.
After doing the parameter tuning and operating the fuzzy controllers, the diagram
was simulated. From the characteristics of both responses, the design criteria were
successfully satisfied.
In Chapter VI, ANN was discussed in detail. One of the most interesting
features of NNs is their learning ability. This is achieved by presenting a training set
of different examples to the network and using learning algorithms, which changes
the weights (or parameters of activation functions) in such a way that the network
will reproduce a correct output with the correct input values. One encountered
difficulty is how to guarantee generalization and to determine when the network is
sufficiently trained. Neural networks offer nonlinearity, inputoutput mapping,
adaptivity and fault tolerance.
Implementing neural network for control is not easy task to do. It was
involved the identification, training and control approaches. There were several
constraints and problems in designing the ANN controller which has been discussed
in section 6.9.1. In this project, the identification and training parts were
satisfactorily achieved. However when it goes to the control part, the response are
not successfully stabilized.
100
CHAPTER VIII
CONCLUSION & SUGGESTION
8.1 Conclusion
From the early discussion, it can be concluded that both of control methods of
the conventional controllers (PID and LQR) are capable of controlling the inverted
pendulum's angle and the cart's position of the linearized system. The PID control
approach that was proposed in the reference number [10] was modified and solved
successfully. The response characteristics have satisfied the design criteria. New
control approach of the fuzzy logic is capable of controlling the inverted pendulum's
angle and the cart's position of the nonlinear system. FLC could stabilize the system
with some limitation as discussed in the previous chapter.
All the successfully design controller were compared. The responses of each
controller were plotted in one window and summarized in table. Simulation results
show that LQR controller has better performance compared to PID in controlling the
linear system.
101
Finally, GUI for Inverted Pendulum system is successfully designed. The
front panel of the GUI is shown in Figure 8.1. As can be seen from the figure, four
controllers button has been provided. Each controller provide three types of input
such as step input, square wave input, and user define input. By clicking one of the
buttons, the user can operate and simulate the system as well as the output response.
Figure 8.1: Graphical User Interface front panel of Inverted Pendulum System
8.2 Suggestion for the Future Work
Although the controllers has been successfully stabilized the system,
implementation of the algorithm into real hardware is very important. Since FLC
could stabilize the nonlinear system, it is expected that the FLC will work well if it is
102
implemented into real system. Therefore, further work for the proposed approaches
will have great advantage.
AI controller technique should be improved so that a robust controller and a better
response can be achieved. The limitation in a FLC design should be eliminated. The
neural network controller also should be designed based on the input training signal
that is successfully achieved. A lot of techniques can be figure out from the previous
paper and research that were successfully done.
103
REFERENCES
[1] K. Hornik and M. Stinchcombe and H.White. “Multilayer FeedForward
Networks Are Universal Approximators”. Department of Encomics, University of
California, San Diego, La Lolla, CA, 1988
[2] NOVAK V., 1986. “Fuzzy Sets and Their Applications “Adam Hilger Imprint by
IOP Publishing Ltd, London, U.K
[3] Chen Wei Ji Fang Lei Lei Kam Kin, “Fuzzy Logic Controller for an Inverted
Pendulum System” Faculty of Science and Technology, University of Macau
[4] Chen Wei Ji, Fang Lei, Lei Kam Kin, I997 IEEE International Conference on
Intelligent Processing System October 28  31. “Fuzzy Logic Controller for an
Inverted Pendulum System”
[5] Tsutomu Ishida, Naofumi Shiokawa, Tsutomu Nagado, “Learning Control of an
Inverted Pendulum Using a Neural Network”, University of Ryukyus,Okinawa Japan
[6] S. Kawaji, T. Maeda, N. Matsunaga, “Learning Control of an Inverted Pendulum
Using a Neural Network”, Kumamoto University, Japan
[7] Charles W. Anderson, “Learning to Control an Inverted Pendulum Using Neural
Networks”
[8] Lawrence Bush, Fuzzy Logic Controller for the Inverted Pendulum Problem,
Computer Science Department, Rensselaer Polytechnic Institute, Troy New York,
November 27, 2001
104
[9] Victor Williams, Kiyotoshi Matsuoka, “Learning to Balance the Inverted
Pendulum using Neural Network”, Kitakushu Japan
[10] Carnegie Mellon, University of Michigan
www.engin.umich.edu/group/ctm/examples
[11]
http://www.seattlerobotics.org/encoder/mar98/fuz/fl_part1.html#WHAT%20IS%20F
UZZY%20LOGIC?
[12] Mehmet Emin ARI (1995) “Stabilization of an Inverted Pendulum by Using a
Fuzzy Controller”, Middle East Technical University: Master's Thesis
[13]Malcolm Jeffers (2001) “A Genetic Algorithm based Fuzzy Logic Controller”,
Dublin City University
105
APPENDICES
M = .5;
m = 0.2;
b = 0.1;
i = 0.006;
g = 9.8;
l = 0.3;
q = (M+m)*(i+m*l^2)(m*l)^2; %simplifies input
num = [m*l/q 0]
den = [1 b*(i+m*l^2)/q (M+m)*m*g*l/q b*m*g*l/q]
Output should be:
num =
4.5455 0
den =
1.0000 0.1818 31.1818 4.4545
A1: Matlab command to find open loop transfer function of the system
function[poly]=polyadd(poly1,poly2)
%Copyright 1996 Justin Shriver
%polyadd(poly1,poly2) adds two polynominals possibly of uneven length
if length(poly1)<length(poly2)
short=poly1;
long=poly2;
else
short=poly2;
long=poly1;
end
mz=length(long)length(short);
if mz>0
poly=[zeros(1,mz),short]+long;
else
poly=long+short;
end
A2: Matlab command for Polyadd function
106
kd = 1;
k = 1;
ki = 1;
numPID = [kd k ki];
denPID = [1 0];
numc = conv(num,denPID)
denc = polyadd(conv(denPID,den),conv(numPID,num))
t=0:0.01:5;
impulse(numc,denc,t)
axis([0 1.5 0 40])
A3: PID control method for pendulum’s angle
M = .5;
m = 0.2;
b = 0.1;
i = 0.006;
g = 9.8;
l = 0.3;
q = (M+m)*(i+m*l^2)(m*l)^2; %simplifies input
num1 = [m*l/q 0 0];
den1 = [1 b*(i+m*l^2)/q (M+m)*m*g*l/q b*m*g*l/q
0];
num2 = [(i+m*l^2)/q 0 m*g*l/q];
den2 = den1
kd = 20;
k = 100;
ki = 1;
numPID = [kd k ki];
denPID = [1 0];
numc = conv(num2,denPID);
denc = polyadd(conv(denPID,den2),conv(numPID,num1));
t=0:0.01:5;
impulse(numc,denc,t)
A4: PID control method for cart’s position
107
M = 0.5;
m = 0.2;
b = 0.1;
i = 0.006;
g = 9.8;
l = 0.3;
p = i*(M+m)+M*m*l^2; %denominator
A = [0 1 0 0;
0 (i+m*l^2)*b/p (m^2*g*l^2)/p 0;
0 0 0 1;
0 (m*l*b)/p m*g*l*(M+m)/p 0];
B = [0; (i+m*l^2)/p; 0; m*l/p];
C = [1 0 0 0;
0 0 1 0];
D = [0;0];
p = eig(A)
C'*C
x=1;
y=1
R = 1;
K = lqr(A,B,Q,R)
Ac = [(AB*K)];
Bc = [B];
Cc = [C];
Dc = [D];
T=0:0.01:5;
U=0.2*ones(size(T));
[Y,X]=lsim(Ac,Bc,Cc,Dc,U,T);
plot(T,Y)
legend('Cart','Pendulum')
A5: Matlab command for LQR design
108
Cn=[1 0 0 0];
Nbar=rscale(A,B,Cn,0,K)
Bcn=[Nbar*B];
[Y,X]=lsim(Ac,Bcn,Cc,Dc,U,T);
plot(T,Y)
legend('Cart','Pendulum')
A6: Matlab command for adding the reference input
p = eig(Ac)
P = [40 41 42 43];
L = place(A',C',P)'
Ace = [AB*K B*K;
zeros(size(A)) (AL*C)];
Bce = [ B*Nbar;
zeros(size(B))];
Cce = [Cc zeros(size(Cc))];
Dce = [0;0];
T = 0:0.01:5;
U = 0.2*ones(size(T));
[Y,X] = lsim(Ace,Bce,Cce,Dce,U,T);
plot(T,Y)
legend('Cart','Pendulum')
A7: Matlab command to design a FullOrder Estimator
PSZ 19:16 (Pind. 1/ 7) 9
UNIVERSITI TEKNOLOGI MALAYSIA
BORANG PENGESAHAN STATUS TESIS
JUDUL: MODELING AND CONTROLLER DESIGN FOR AN INVERTED PENDULUM SYSTEM
SESI PENGAJAN: I Saya
2006/ 007 2
AHMAD NOR KASRUDDIN IN NASIR B
(HURUF ESAR) B
mengaku membenarkan tesis (PSM/Sarjana/Doktor Falsafah)* ini disimpan di Perpustakaan Universiti Teknologi Malaysia dengan syaratsyarat kegunaan seperti berikut: 1. Tesis adalah hakmilik Universiti Teknologi Malaysia. 2. Perpustakaan Universiti Teknologi Malaysia dibenarkan membuat salinan untuk tujuan pengajian sahaja. 3. Perpustakaan dibenarkan membuat salinan tesis ini sebagai bahan pertukaran antara institusi pengajian tinggi. 4. **Sila tandakan ( ) SULIT (Mengandungi maklumat yang berdarjah keselamatan atau kepentingan Malaysia seperti yang termaktub di dalam AKTA RAHSIA RASMI 1972) (Mengandungi maklumat TERHAD yang telah ditentukan oleh organisasi/badan di mana penyelidikan dijalankan)
TERHAD
TIDAK TERHAD Disahkan oleh
(TANDATANGAN PENULIS) Alamat Tetap:
(TANDATANGAN PENYELIA)
496 (F) KERATONG SATU ANDAR TUN AB UL RAZAK B D 26900 PAHANG DARUL MAKMUR
Tarikh:
P.M DR. MOHD FUA’AD B HJRAHMAT IN .
Nama Penyelia Tarikh:
30th APRIL 2007
30th APRIL 2007
CATATAN:
* Potong yang tidak berkenaan. ** Jika tesis ini SULIT atau TERHAD, sila lampirkan surat daripada pihak berkuasa/organisasi berkenaan dengan menyatakan sekali sebab dan tempoh tesis ini perlu dikelaskan sebagai SULIT atau TERHAD. Tesis dimaksudkan sebagai tesis bagi Ijazah Doktor Falsafah dan Sarjana secara penyelidikan, atau disertasi bagi pengajian secara kerja kursus dan penyelidikan, atau Laporan Projek Sarjana Muda (PSM).
“I hereby declare that I have read this thesis and in my opinion this thesis is sufficient in term of scope and quality for the award of the degree of Master of Engineering (Electrical  Mechatronics)”
Signature Date
: ……………………………………. : 30th APRIL 2007
Supervisor’s Name: ASSOC. PROF. DR. MOHD FUA’AD BIN HJ. RAHMAT
MODELING AND CONTROLLER DESIGN FOR AN INVERTED PENDULUM SYSTEM AHMAD NOR KASRUDDIN BIN NASIR A thesis submitted in fulfillment of the requirements for the award of the degree of Master of Electrical Engineering (Mechatronics & Automatic Control) Faculty of Electrical Engineering Universiti Teknologi Malaysia APRIL 2007 .
2007 .ii I declare that this thesis entitled “Modeling and Controller Design for an Inverted Pendulum System”is the result of my own research except as cited in the references. :AH AD NOR KASRUDDIN BIN NASIR M :30 th APRIL. The thesis has not been accepted for any degree and is not concurrently submitted in candidature of any other degree. Signature Name Date :… .
mother and family.iii To my dearest father. blessing and inspiration … . for their encouragement.
Mohd Fauzi bin Othman and Dr. First of all. I would like to express my heartiest appreciation to my parents and my family. To all lecturers who have taught me. information and moral support during the course of study. guidance and support throughout this project. I sincerely thank to Dr. Mohd Sazli and Haszuraidah. Noor Azam. Universiti Malaysia Pahang for giving me financial support to further my study here. Last but not least. the project would have not been successful achieve the objectives. Not forgetting all my friends. thank you for the lesson that has been delivered. suggestions and guidance. who are always there when it matters most. I would like to express my deepest appreciation to my supervisor. Fua’ad bin Haji Rahmat for his effort. Without his advice. Mohd Arif. Dr. I am grateful to ALLAH SWT on His blessing and mercy for making this project successful. thank you for their useful idea. Hj. especially Mohd Ashraf. Shahrum Shah bin Abdullah for helping and guiding me a lot on the artificial intelligence control theory. Prof. Assoc.iv ACKNOWLEDGEMENT Alhamdullillah. . Special thank also to my employer. Mohd.
. The goal is to determine which control strategy delivers better performance with respect to pendulum’s angle and cart’s position. Simulation study has been done in Simulink shows that LQR produced better response compared to PID and FLC control strategies and offers considerable robustness.e. linear quadratic regulator (LQR) for controlling the linear system of inverted pendulum and fuzzy logic controller (FLC) for controlling the nonlinear system of inverted pendulum model.v ABSTRACT This paper presents the simulation study of several control strategies for an inverted pendulum system. The inverted pendulum represents a challenging control problem. proportionalintegralderivative (PID). Three controllers are presented i. which continually moves toward an uncontrolled state.
Simulasi telah dibuat dengan menggunakan perisian Simulink dimana pengawal LQR menghasilkan sambutan masa terbaik berbanding dengan teknik pengawalan PID dan teknik pengawalan FLC. Tujuannya adalah untuk menentukan teknik kawalan yang mempunyai prestasi terbaik terhadap sudut pendulum dan kedudukan kereta. LQR untuk mengawal sistem pendulum songsang yang liner dan FLC untuk mengawal sistem pendulum songsang yang kompleks. Tiga pengawal dibincangkan iaitu PID. beberapa teknik kawalan untuk pendulum songsang telah dikaji. .vi ABSTRAK Dalam thesis ini. Teknik pengawalan LQR mempunyai kestabilan yang memuaskan. Pendulum songsang adalah satu masalah dalam bidang kawalan yang mencabar yang mana secara berterusan menuju ke arah keadaan yang tidak terkawal.
2 Force Analysis and System Equations 2.3 Scope of Project 1.1 Transfer Function 2.4 Research Methodology 1.2 Objective 1.2.vii TABLE OF CONTENTS CHAPTER DECLARATION DEDICATION TITLE PAGE ii iii iv v vi vii xi xii xvi xviii ACKNOWLEDGEMENT ABSTRACT ABSTRAK TABLE OF CONTENTS LIST OF TABLES LIST OF FIGURES LIST OF SYMBOLS LIST OF APPENDICES I INTRODUCTION 1.5 Thesis Outline 1 3 4 4 5 7 II MODELING OF AN INVERTED PENDULUM 2.1 Overview 1.1.1 Inverted Pendulum 2.2 StateSpace 9 11 12 14 .1 Why Choose the Inverted Pendulum 1.2.
3.2.2.2.2 What is simulink 2.3.1 LQR Control Method 4.2.2.1.1 The Form of Fuzzy Control Rules and Inference Method 5. Planning Of Fuzzy Controllers 42 42 45 47 48 37 38 39 .2.2 Inference Method 2 5.3.3 FullOrder Estimator 4.1 What is an mfile 2.1 PID Controller 3.2 Adding a Reference Input 4. Inference Method 1 5.2.1 Where Did Fuzzy Logic Come From 5.5 Conclusion 22 26 3.2.2.2.2 StatesSpace Design 4.1 Introduction 4.3.2 What Is Fuzzy Logic 5. Inference Method 3 5.2.2 Consideration of Pendulum’s Angle 3.1 Introduction 3.3 Conclusion 28 29 31 32 34 35 V FUZZY LOGIC CONTROLLER 5.1 PID controller 3.3.3 What is GUIDE 15 15 16 17 III PID CONTROLLER 3.viii 2.3 Consideration of Cart's Position 3.2.3 What is Matlab 2.4 Consideration of Cart's Position and Pendulum’s Angle 25 18 19 21 IV LQR CONTROL METHOD 4.2 Type of Fuzzy Controllers 5.3.
6.2 OpenLoop Results 7.1 Introduction 6.9.1 Introduction 7.6.4 Neural network structures 6.6 Learning Algorithms 6.7 Conclusion VI ARTIFICIAL NEURAL NETWORKS CONTROLLER 6.4 Rule base 5.1 PID Control Method 75 75 78 78 .6.10 Conclusion 74 70 71 74 63 64 66 66 67 67 68 50 50 51 54 55 59 60 62 49 VII RESULTS AND DISCUSSION 7.6 Fuzzy Of Inverted Pendulum System 5.1 Problems and constraints in designing the ANN controller 6.5 Activation functions 6.5 How Does FL Work 5.ix 5.9 Implementation in Simulink 6.2 Advantages of ANN’s 6.7 Forward Modeling of Inverted Pendulum Using Neural Networks 6.3 Membership functions 5.3.5 Implementation in Simulink 5.4 How Is FL Different From Conventional Control Method 5.2 Inputs and Outputs of FLC 5.3 PID Control Method 7.6.6.1 Fuzzy Logic Controller Design Flow Chart 5.3 Types of Learning 6.8 Learning rules 6.
2 Suggestion for the Future Work 100 101 103 105108 REFERENCES Appendices .1 Pendulum's Angle and Cart's Position 7.1 Pendulum's Angle and Cart's Position 7.7 Comparative Assessment and Analysis of the Response 91 VIII CONCLUSION AND SUGGESTION 8.3 Pendulum's Angle and Cart's Position 7.3.2 Cart’s Position 7.4.5 Fuzzy Logic Controller Control Method 7.8 Discussion 80 81 83 83 87 87 88 97 7.6 Artificial Neural Network Control Method 7.3.4 LQR Control Method 7.5.1 Conclusion 8.x 7.
2 TITLE ZeiglerNichols tuning method Discrete type of Fuzzy variables Inputs and outputs of FLC Standard labels of quantization Fuzzy rule matrix for control position FLC Fuzzy rule matrix for control angle FLC Properties of Neural Network Comparison of output response of cart’s position PAGE 26 41 54 55 59 59 73 93 96 Comparison of output response of pendulum’s angle .xi LIST OF TABLES TABLE 3.4 5.1 7.5 6.2 5.1 5.1 7.3 5.1 5.
3 2.3 3.1 3.2 4.2 2.6 4.5 3.4 3.1 4.4 3.2 3.1 2.3 Flow chart of research methodology Free body diagram of the inverted pendulum system Free body diagrams of the system Simulink block in Matlab GUI front panel of Inverted Pendulum System The schematic diagram for the closedloop system with force as disturbance The rearranged schematic diagram for the closedloop system with force as disturbance Actual schematic diagram of the Inverted Pendulum System Rearranged schematic diagram of the Inverted Pendulum System Schematic diagram of the Inverted Pendulum System with two PID controllers Schematic diagram of the Inverted Pendulum System with two PID controllers in Simulink Schematic diagram for Inverted Pendulum in StateSpace form Schematic diagram of system with NBar Schematic diagram of system in StateSpace 6 9 11 16 17 20 20 23 23 25 26 30 33 35 .xii LIST OF FIGURES FIGURE NUMBER TITLE PAGE 1.1 2.
12 5.19 6.14 5.15 5.4 5.8 5.17 5.2 6.5 6.18 5.13 5.2 5.4 6.1 5.7 5.xiii with Estimator 5.3 Comparison between Fuzzy Logic Controller and PID controller Control algorithm of Fuzzy Logic Controller A Triangular membership function of Fuzzy Logic Controller 5.11 5.6 A Type membership function 40 42 44 45 46 51 52 53 54 56 56 57 57 58 58 61 64 65 66 67 68 69 39 40 38 Block diagram of Fuzzy Controller Schematic representation of Inference Method 1 Monotonic membership functions Schematic representation of Inference Method 2 Fuzzy Logic Controller design flow chart Block diagram of the system with Fuzzy Logic Controller Rearranged block diagram of the System with Fuzzy Logic Controller Fuzzy Logic Controller block diagram Input 1 of Fuzzy Logic Controller 1 Input 2 of Fuzzy Logic Controller 1 Output of Fuzzy Logic Controller 1 Input 1 of Fuzzy Logic Controller 2 Input 2 of Fuzzy Logic Controller 2 Output of Fuzzy Logic Controller 2 Schematic diagram of the Nonlinear Inverted Pendulum system with two FLC controllers in Simulink Biological neuron Diagram of neuron model Diagram of the Perceptron model Activation functions Supervised learning Forward modeling of Inverted Pendulum .9 5.3 6.10 5.6 5.16 5.1 6.5 5.
10 7. Kd=1.6 7.5 7.12 7. Ki=1 Impulse response for pendulum’s angle for K=100. Ki=110 Impulse response for cart’s position for K=0.14 7. Kd=20. Kd=20.1 7. Kd=1.13 7. Ki=1 Impulse response of cart’s position for K=100.8 7.xiv using Neural Networks 6.3 7.5. Ki=1 Impulse response for pendulum’s angle for K=100.3.7 7.11 7. Ki=10 Step response with LQR control for x=5000 and y=100 Step response with LQR and Nbar control for x=5000 and y= 100 Step response with Estimator for x=6000 and y=200 Impulse response for pendulum’s angle Impulse response for cart’s position Training output response of cart’s position 86 87 88 89 85 84 82 82 80 79 79 78 77 76 76 72 70 . Ki=1 Impulse response for pendulum’s angle for K=50.2 7. Kd=3.7 6.8 7.9 7.0001.15 Rearranged forward modeling of Inverted Pendulum using Neural Networks Block diagram of the Inverted Pendulum system with an ANN in Simulink Impulse response for pendulum’s angle using transfer function Impulse response for cart’s position using transfer function Impulse response for pendulum’s angle and cart’s position using StateSpace Impulse response for pendulum’s angle for K=1.4 7. Kd=0.
xv 7.1 Training output response of pendulum’s angle System output response of cart’s position System output response of pendulum’s angle Comparison of output response of cart’s position Output response of cart’s position Comparison of output response of pendulum’s angle Graphical User Interface front panel of Inverted Pendulum System 89 90 90 92 94 95 101 .16 7.17 7.18 7.20 7.21 8.19 7.
force State vector Input vector Output vector Settling time Rising time Steady state error Error multiplied by a gain The integral of error multiplied by a gain The rate of change of error multiplied by a gain x  u y  ts tr ess Kp Ki Kd   .xvi LIST OF SYMBOLS SYMBOL b l x r(s) e(s) u(s) g(s) y(s) f(s) x DESCRIPTION Friction or cart Length to pendulum centre of mass Cart position coordinate cart acceleration Pendulum angle from the vertical Pendulum angular acceleration Reference signal Error signal Plant input Plant Output. pendulum’s angle Disturbance.
xvii KD(s) X(s) NS NM NL ZE PS PM PL PID LQR FLC ANN AI GUI M M CV E SP PV SISO R A B C D %OS I F Controller gain Cart's position signal Negative small Negative medium Negative large Zero Positive small Positive medium Positive Large Proportional Integral Derivative Linear Quadratic Regulator Fuzzy Logic Controller Artificial Neural Network Controller Artificial Intelligence Graphic User Interface Mass of cart Mass of pendulum Control variable Error Set point Process variable Singleinputsingleoutput Step input to the cart State matrix Input matrix Output matrix Direct transmission matrix Percent overshoot Inertia of the pendulum Force applied to cart .
xviii LIST OF APPENDICES APPENDIX TITLE PAGE A1 A2 A3 A4 A5 A6 A7 Matlab command to find open loop transfer function of the system Matlab command for Polyadd function PID control method for pendulum’s angle PID control method for cart’s position Matlab command for LQR design Matlab command for adding the reference input Matlab command to design a FullOrder Estimator 105 105 106 106 107 108 109 .
in control sense. The inverted pendulum is a highly nonlinear and openloop unstable system.1 CHAPTER 1 INTRODUCTION 1.1 Overview The inverted pendulum offers a very good example for control engineers to verify a modern control theory. This can be explained by the facts that inverted pendulum is marginally stable. an automatic aircraft landing system. This means that standard linear techniques cannot model the nonlinear dynamics of the system. To solve such problem with nonlinear time variant system. When the system is simulated the pendulum falls over quickly. has distinctive time variant mathematical model. stabilization of a cabin in a ship etc. The . there are alternatives such as real time computer simulation of these equations or linearization. aircraft stabilization in the turbulent airflow. Inverted Pendulum is a very good model for the attitude control of a space booster rocket and a satellite.
The problem is to balance a pole on a mobile platform that can move in only two directions. This control problem is fundamentally the same as those involved in rocket or missile propulsion. Common control approaches such as ProportionalIntegralDerivative (PID) control and Linear Quadratic control (LQ) require a good knowledge of the system and accurate tuning in order to obtain desired performances.2 characteristics of the inverted pendulum make identification and control more challenging. application of these control techniques to a two or three stage inverted pendulum may result in a very critical design of control parameters and difficult stabilization. to the left or to the right. Moreover. Therefore. the inverted pendulum dynamics should be locally linearized. The inverted pendulum is an intriguing subject from the control point of view due to their intrinsic nonlinearity. These four controllers can be divided into two categories. However. it is often impossible to specify an accurate mathematical model of the process. four types of controllers will be simulated. [3] In order to obtain control surface. or the description with differential equations is extremely complex. using artificial intelligence controllers such as artificial neural network and fuzzy logic controllers. the controller can be design without require the model to be linearized. However. in this project. The nonlinearized model can be simulated directly using the Matlab application to see result. (1) Conventional Controller Proportional Integral Derivative (PID) Linear Quadratic Regulator (LQR) (2) Artificial Intelligence Controller Fuzzy Logic Controller (FLC) Artificial Neural Network Controller (ANN) .
1 Why Choose the Inverted Pendulum The following reasons help explain why the inverted pendulum on a cart has been selected as the system on which the findings of this report will be implemented. 3. When the control method is supplemented with a fuzzy logic and artificial neural network optimization techniques. A proportional.3 1. derivative (PID) and LQR controllers will be used as a reference because both the structure of the controller is simple and the performance is not adversely affected by noise and parameter variations. The cart/pole system is a common test case for fuzzy logic so any results can be compared to previous work in the field. slight variations of the angle from the norm). the result will provide an insightful measure of the ability of the method to provide control. If any testing is worth doing at all it must be planned in such a way that it has at least a good chance of giving a useful result [2].1.e. a reference model must be designed at the outset of this work. 1. It is a nonlinear system. Intuition plays a large part in the human understanding of the inverted pendulum model. A progressive model can be built. In order to perform sound criticism of any controllers developed. 2. integral. . yet can be approximated as a linear system if the operating range is small (i.
2 Objectives This project consists of three objectives as listed below: i. Design inverted pendulum system animation using Matlab . To design artificial intelligence (AI) controller (Fuzzy Logic controller.4 1. To design a graphic user interface (GUI) for the inverted pendulum system simulation 1. Determine the mathematical model for an inverted pendulum system. To make comparison between artificial intelligence controller technique and conventional controller technique iii. Design a controller using artificial intelligence technique (FLC and ANN) and conventional technique (PID and LQR) iii. Simulate the controllers using Matlab and conclude the best controller based on the simulation results iv. ANN) and conventional controller technique (PID and LQR) for an inverted pendulum system ii. ii.3 Scopes of Works i. FLC and Artificial Neural Network controller.
1 . identifying problem faced by previous and current researcher and identifying suitable technique of designing the controllers 3. Acquire control rules from experience operator and simulate the FLC. Defining mathematical model for an inverted pendulum system 4. Analyze the process. Study the Matlab programming language.5 1. Designing and writing Matlab program to simulate and animate the system 7. Searching out previous and current projects of an inverted pendulum system. PID and LQR All the methodology above can be summarized as shown Figure 1.4 Research Methodology 1. Defining mathematical model of the controllers 5. Conducting literature review to understand the concept of an inverted pendulum system 2. graphical user interface and simulink 6. ANN.
6 Literature Review Mathematical Model Design Requirement Transfer function StateSpace Form Controller Design Conventional Artificial Intelligence PID Controller LQR Controller Fuzzy Logic Neural Network Evaluate Performance Comparison and GUI Figure 1.1: Flow chart of research methodology .
The scope of each chapter is explained as stated below: Chapter 1 This chapter gives the introduction to the project report. scopes of works and methodology taken.7 1.5 Thesis Outline This report consists of eight chapters including this chapter. Chapter 2 This chapter discusses modeling of an inverted pendulum. Chapter 3 This chapter discusses the theory and application of PID controller of this project. The modeling technique in Simulink is also discussed. Both transfer function and statespace models are used to analyze the controller to solve the inverted pendulum problem. including the nonlinear and linearized equations. It is contained the derivation in mathematical modeling for the dynamic of the inverted pendulum system. Chapter 4 This chapter proposes LQR control method in controlling the inverted pendulum system by applying the statespace representation. objectives. It consists of development of an inverted pendulum model. followed by its transfer function and statespace representations. There are also a few modifications that have been done to meet the design requirements and to improve the results. .
8 Chapter 5 This chapter proposes the Fuzzy Logic Controller (FLC) for the inverted pendulum system. and also the results of the Fuzzy Logic controller and Artificial Neural Network controller. Chapter 8 This last chapter presents the overall discussion and conclusion of this project. learning algorithms. The proposed FLC characteristics for the inverted pendulum are also discussed. forward modeling of inverted learning rules pendulum using neural network. A few recommendations and suggestions also have been included for the future work. Its also includes the introduction. types of learning. the results of the PID and LQR controllers. advantages of ANN’s. Chapter 6 This chapter discusses the Artificial Neural Network controller (ANN) of inverted pendulum system. activation functions. It also describes some theoretical background of FLC such as the introduction and types of fuzzy. and Chapter 7 This chapter displays the results of the closed loop system of the inverted pendulum. . neural network structures.
It is a suitable process to test prototype controllers due to its high nonlinearities and lack of stability. The system consists of an inverted pole with mass. In this chapter. m. which is free to move in the x direction as shown in Figure 2. A force.1 Inverted Pendulum The inverted pendulum system is a classic control problem that is used in universities around the world. the dynamical equations of the system will be derived. F is required to push the cart horizontally. Figure 2.1: Free body diagram of the inverted pendulum system .9 CHAPTER II MODELING OF AN INVERTED PENDULUM 2. hinged by an angle from vertical axis on a cart with mass. M.1.
is to be less than five seconds.006 kg m2 Force applied to cart Cart position coordinate Pendulum angle from the vertical .5%. os < 22.10 This section outlines the assumptions. Assumptions: 1.1Nm1s1 Length to pendulum centre of mass 0. design requirements and physical properties of the model and its components. Ts.5% Properties of the Cart and Pendulum: M m b l I F x – – – – – – – – Mass of cart 0. A step input is applied.5kg Mass of pendulum 0. The pendulum does not move more than a few degrees away from the vertical to satisfy a linear model. Ts < 5secs 2. The system starts in a state of equilibrium meaning that the initial conditions are therefore assumed to be zero. 3.2kg Friction or cart 0. Design Requirements: 1. The system overshoot value is to be at most 22. The settling time. 2.3m Inertia of the pendulum 0.
3) Sum the forces perpendicular to the pendulum P sin N cos mg sin ml mx cos (2.2) Substituting equation 2. consider Figure 2.l cos I (2. Summing the forces of the cart in the horizontal direction Mx b x N F (2.1 (M m) x bx ml cos ml 2 sin F (2.2: Free body diagrams of the system.11 2.1) Summing the forces of the pendulum in the horizontal direction Mx ml cos ml 2 sin N (2.4) To get rid of the P and N terms in the equation above. sum the moments around the centroid of the pendulum Pl sin N .5) .2 into equation 2.2 Force Analysis and System Equations To derive the suitable mathematical model for an inverted pendulum system.2: Figure 2.
9 for X(s).1 Transfer Function Laplace transform of the system equations (I ml 2 ) ( s ) s 2 mgl ( s ) mlX ( s) s 2 (2. solving equation 2.9) (M m) X ( s ) s 2 bX ( s) s ml ( s ) s 2 U ( s) (2. Therefore. and d = 0.12 Combining equation 2. (dt ) 2 After linearization the two equations of motion become (where u represents the input): (I ml 2) mgl mlx (2.6) Since Matlab can only work with linear functions.10) Since the angle ø is the output of interest.2.7) (M m) x bx ml u (2. .5 (I ml 2 ) mgl sin mlx cos (2.8) 2. sin ( ) = ø. cos ( ) = 1. this set of equations should be linearized about = . Assume that = + ø (ø represents a small angle from the vertical upward direction).4 and equation 2.
12) Rearranging.11) Substituting equation 2.1818s 31.1818s 4. the following equation 2.5455s 0.14 and equation 2.8182s 44.5455 0.4545 (2. q [( M m)( I ml 2 ) (ml ) 2 ] From the transfer function above it can be seen that there is both a pole and a zero at the origin.13) where.13 X (s) (I ml ) ml 2 g s2 ( s) (2.15) Solving for the transfer function of the position.15 (s) U ( s) s 3 b( I ml 2 ) 2 s q ml s q (M m)mgl s q bmgl q (2. These can be canceled and the transfer function of the angle is shown as in equation 2.10 (I ml2 ) g (I ml2 ) g 2 (M m) (s)s b (s)s ml (s)s 2 U (s) ml s ml s (2.4545 2 (2. the transfer function is (s) U (s) s 4 b( I ml 2 ) 3 s q ml 2 s q ( M m)mgl 2 s q bmgl s q (2.14) ( s) U ( s) s 3 4.16) .11 into equation 2.1818s 2 31.1818s 4.16 will be derived X ( s) U (s) s 3 1.
17 yielding equation 2.19) The C matrix is 2 by 4. x(t) x(t) (t) (t) 1 (I ml2 )b 0 I (M m) Mml2 0 0 mlb 0 I (M m) Mml2 I I (M 0 0 m2 gl 2 I (M m) Mml2 0 mgl(M m) I (M m) Mml2 x(t) x(t) 1 (t) 0 (t) 0 0 (2. For the statespace design.2 StateSpace The linearized system equations can also be represented in statespace form as shown in equation 2.17) I (M 0 ml 2 m) Mml 2 u (t ) 0 ml m) Mml 2 Substituting all the parameter values into the equation 2.18 and equation 2. a multioutput system will be controlled so that the cart's position and pendulum’s angle can be observed from the first row and second row of the output respectively.2.1818 0 x(t ) 0 x(t ) 1 (t ) 0 (t ) 0 1.14 2.6727 0 0 0.8182 u (t ) 0 4. because both the cart's position and the pendulum's position are part of the output.19.1818 2. .19 x(t ) x(t ) (t ) (t ) 0 0 0 0 1 0 0.18) y (t ) x(t ) 1 0 0 0 x(t ) 0 0 1 0 (t ) (t ) 0 u (t ) 0 (2.17 till equation 2.5455 (2.4545 31.
All problems and solutions in Matlab are expressed in notation used in linear algebra and essentially involve operations using matrices and vectors. By creating a new mfile with the same name as an existing mfile. All mfile names must end with the extension '. choose a name for mfile which doesn't already exist. The Matlab software environment has a core module (called Matlab) and associated with that are a set of "Toolboxes" that perform specialized computations. Inc.m). 2. When the file is run. programming and software development. Matlab can be used to solve problems in control systems.3. Matlab can be used to build Graphical User Interfaces (GUIs) so that userfriendly custom software can be developed. plot. visualization. is a simple text file where a Matlab command can be placed. It provides a single platform for computation. developed by the The Mathworks.g.15 2. or script file. Matlab will choose the one which appears first in the path order (help path for more information).3 What is Matlab Matlab (short for MATrix LABoratory) is a language for technical computing.1 What is an MFile An mfile. Matlab reads the commands and executes them exactly if each command is typed sequentially at the Matlab prompt. In addition. To make life easier.m' (e. .
0 12.0 1.16 For example. create a file containing these five lines. Analysis of ste adystate ope ration of a line ar e le ctrical circuit + i  Current Voltage Z source Current Measurement Scope 100 V 60 Hz I source 300 Hz Z Impedance Measurement 5th Harm.0 Store the file under the name magic.3.0 14. 16.0 7. Then the statement magic reads the file and creates a variable.0 2.0 3. A. Simulink is widely used in control theory and digital signal processing for multi domain simulation and design.. Its primary interface is a graphical block diagramming tool and a customizable set of block libraries. Simulink offers tight integration with the rest of the MATLAB environment and both drive MATLAB or can be scripted from it. Filter +  v Voltage Measurement ? Conti nuous Double click here for detai ls Figure 2.0 15.0 ]. 4. A = [ .0 5. Example of simulink software is shown in Figure 2.m.2 What is Simulink Simulink is a tool for modeling.0 9.0 6.0 11.0 13.3: Simulink block in Matlab .0 8. 2. simulating and analyzing multi domain dynamic systems.0 10.3..
3 What is GUIDE GUIDE. code can be added to the callbacks to perform the functions needed by user. Figure 2. GUIDE stores the GUI layout in a FIGfile. Figure 2. GUIDE automatically generates an Mfile that controls how the GUI operates. provides a set of tools for creating graphical user interfaces (GUIs).4: GUI front panel of inverted pendulum system . menus.17 2. Using the Mfile editor. buttons.4 shows the GUI front panel of inverted pendulum system. The GUIDE tools can be used to Layout the GUI.3. text fields. a GUI could be easily layout by clicking and dragging GUI components such as panels. These tools greatly simplify the process of designing and building GUIs. sliders. Using the GUIDE Layout Editor. the MATLAB graphical user interface development environment. The Mfile initializes the GUI and contains a framework for the most commonly used callbacks for each component and the commands that execute when a user clicks a GUI component. and so on into the layout area.
Ki. is generally based on the error (e) between some userdefined set point (SP) and some measured process variable (PV).1 Introduction PID stands for ProportionalIntegralDerivative. Each element of the PID controller refers to a particular action taken on the error. • Integral: the integral of error multiplied by a gain. This is a type of feedback controller whose output. Kp. In many systems Ki is responsible for driving error to zero. • Proportional: error multiplied by a gain. a control variable (CV). . In many systems Kp is responsible for process stability: too low and the PV can drift away.18 CHAPTER III PID CONTROLLER 3. too high and the PV can oscillate. but to set Ki too high is to invite oscillation or instability or integrator windup or actuator saturation. This is an adjustable amplifier.
q [( M m)( I ml 2 ) (ml ) 2 ] For this case. the design criteria to be fulfilled as stated below: Settling time of less than 5 seconds. Tuning of a PID involves the adjustment of Kp.2 Consideration of Pendulum’s Angle As mentioned earlier in the previous section. In many systems Kd is responsible for system response: too high and the PV will oscillate.1 ml 2 s q ( M m)mgl 2 s q (s) U (s) s 4 b( I ml 2 ) 3 s q bmgl s q (3. 3. The designer should also note that derivative action amplifies any noise in the error signal. Pendulum should not move more than 0. Ki. too low and the PV will respond sluggishly.19 • Derivative: the rate of change of error multiplied by a gain.05 radian away from the vertical. .1) where. and Kd to achieve some userdefined "optimal" character of system response. Kd. the transfer function of this system for the pendulum’s angle is shown in equation 3.
The force applied to the cart is added as an impulse disturbance. It can be represented in block diagram as shown in Figure 3.1: The schematic diagram for the closedloop system with force as disturbance For simplicity. PLANT 1 G2(S) f(s)=F X (s ) r(s)=0 + (s) PID e(s) CONTROLLER  + + u(s) PLANT 1 G1(S) (s) Figure 3.2: The rearranged schematic diagram for the closedloop system with force as disturbance . the reference signal for the position should be zero.2 Figure 3. the block diagram can be rearranged as shown in Figure 3.20 Since the objective is to control the pendulum's position.1. which should return to the vertical after the initial disturbance.
. the closedloop transfer function of the diagram can be found as shown by the equation 3.2. This transfer function assumes that both derivative and integral control will be needed along with proportional control. pendulum’s angle KD(s) = controller gain f(s) = disturbance. y ( s) G ( s) F (s) 1 KD ( s )G ( s ) num den k (numPID)(num) 1 (denPID)(den) (3. Both of the transfer functions from the laplace transforms or from the state space representation can be used.2.2 can be implemented into Matlab by using the mfile code as stated in the appendix. force Therefore.21 where. r(s) e(s) u(s) g(s) y(s) = reference signal = error signal = plant input = plant = output.2) num(denPID) F ( s) (denPID)(den) k (numPID)(num) 3.1 PID controller The closedloop transfer function in equation 3.
2.4 in Chapter 7. The velocity response plot for the impulse disturbance is shown in Figure 7.3 Consideration of Cart's Position 3. It has to be copied to a new mfile to use it (refer to Appendix A2 for Polyadd function). 2.5. The integral gain constant could be removed to see for the small integral control is needed. 3. . See the velocity response plot as shown in Figure 7. the settling time is acceptable at about 2 seconds. By setting K= 100. The function polyadd is not originally in the Matlab toolbox. Considering the cart's position and the pendulum's angle using one PID controller. From the response. .05 radian from the vertical.6 in Chapter 7. The overshoot has been reduced so that the pendulum moves less than 0. This transfer function is assumed that both derivative and integral control will be needed along with proportional control.3.3. The K variable is increased to see what the effect on the response. The problem can be solved by increasing the Kd variable. Since the steadystate error has already been reduced to zero. so that must be fixed.1 PID Controller The block representing the position was left out at the beginning because that variable was not being controlled. 0. the inverted pendulum system can be represented in a block diagram as shown in Figure 3. The actual control of this system could be started by subjecting impulse or step input. The response is still not stable and can be improved by increasing the proportional control to the system.5 in Chapter 7 will be determined. All of the design criteria have been met. no more integral control is needed. and the axis to axis ( [0. the velocity response plot as shown in Figure 7. The overshoot is too high.22 This closedloop transfer function can be modeled in Matlab by copying the code from Appendix A3 for this section to the end of mfile.2] ).0. With Kd = 20 a satisfactory result should be determined.
23
Figure 3.3: Actual schematic diagram of the inverted pendulum system Rearranging the block diagram above, a simpler block diagram of inverted pendulum system is produced as shown in Figure 3.4.
Figure 3.4: Rearranged schematic diagram of the inverted pendulum system
where, X(s) = cart's position signal; G(s) = pendulum's angle;
e (s) = pendulum's angle signal
G2(s) = cart's position
The transfer function from the cart's position to the impulse force, with the PID feedback controller is given as shown in equation 3.3 and equation 3.4. G 2( s ) 1 KD ( s )G1( s ) num2 den2 F ( s) k (numPID)(num1) 1 (denPID)(den1)
X ( s)
(3.3)
24 X ( s) (num2)(denPID)(den1) F ( s) (denPID)(den1)(den2) k (numPID)(num1)(den2) (3.4)
Recall that den1=den2 if the pole/zero at the origin that was cancelled is added back into equation 3.4. So the transfer function from X to F can be simplified into equation 3.5.
X (s)
(num2)(denPID) (denPID)(den) k (numPID)(num1)
(3.5)
The transfer function for the entire system is determined. Therefore the response of the system can be considered. The transfer function for the cart's position are determined by taking the laplace transforms of the system equations and find the transfer function from X(s) to U(s) by manipulating equation 3.5. The transfer function for the cart’s position is shown in equation 3.6.
X (s) U (s)
s
3
ml 2 ) 2 s q b( I ml 2 ) 2 ( M s q (I
mgl q m)mgl s q
bmgl q
(3.6)
where, q [( M m)( I ml 2 ) (ml ) 2 ]
The Matlab command for this step can be referred to Appendix A4. By referring to Figure 7.7 in Chapter 7 for the impulse response of the cart's position using PID technique, the result shows that the cart moves in the negative direction with a constant velocity. So, although the PID controller stabilizes the angle of the
pendulum, this design would not be feasible to implement on an actual physical system.
25
3.4 Consideration of Cart's Position and Pendulum’s Angle
Block diagram in Figure 3.5 shows that the system was controlled by 2 different PID controllers. As can be seen, the ‘PID Controller 1’ and ‘PID Controller 2’ were used to control the pendulum’s angle and cart’s position respectively.
r(s)
+

PID Controller 2 (Position)
x (s) Position
+ F
Force Angle (s)
Zero
+ 
PID Controller 1 (Angle)
Figure 3.5: Schematic diagram of the inverted pendulum system with two PID controllers
Ziegler and Nichols method was implemented in designing the PID controllers. Both of the controllers were tuned simultaneously so that the control variable of the controllers is appropriately determined. The control variables were summed together to become a force to the system. By using this block diagram, the inverted pendulum system was successfully stabilized. The response of this system is shown in the later chapter.
2 K g g KD 0.26 Table 3.110 D=3.10 D=0. all the coefficients of the PID controllers are easily determined by applying the given formula.54 K g g  ProportionalIntegralDerivative (PID) 0.5K g   ProportionalIntegral (PI) Kp 0. I=.1 shows the ZeiglerNichols chart that was used in tuning the PID controllers. The parameter values inside the ‘PID Controller 2’ block are (P=0. From this table.45K g KI 0.1: ZeiglerNichols tuning method Controller Type Proportional Gain.6 K g KI 1. the parameter values inside the block are (P=50.3K g 4 g Figure 3.6 shows the schematic diagram of the inverted pendulum system with two PID controllers in Simulink.5).3). For the ‘PID Controller 1’. Table 3. Kc Integral Time. The refining process of the output response can be done iteratively by changing the coefficient parameters. Ti Derivative Time. I=. Td Proportional (P) Kp 0. .0001.
65357 (MouseDriven) PID PID Controller2 In1 x x1 Subsystem R2D PID PID Controller1 Radians to Degrees Figure 3.6: Schematic diagram of the inverted pendulum system with two PID controllers in Simulink 3. However. by applying 2 PID controllers for the system. the linear model of inverted pendulum system can be stabilized successfully by applying two PID controllers simultaneously if they are tuned properly. the PID alone cannot be used successfully to control the cart's pendulum and the pendulum’s angle in the same time. ‘PID Controller 1’ and ‘PID Controller 2’ were used to control the angle of the pendulum and the position of the cart respectively. in this project. It means that only one input could be controlled by a PID controller in a time.27 Step1 animcp Manual Switch Mux Target Position Constant 1 Switch Mux teta1 Animation Target Position 0. .5 Conclusion As a conclusion. However. the inverted pendulum was stabilized successfully. PID control method is a good controller for controlling the singleinputsingleoutput (SISO) system. The results display that the cart moves in the negative direction with a constant velocity when an impulse force is applied to move it. As a conclusion.
which may be combined into a first order vectormatrix differential equation. or transfer function. modern control theory is based on the description of system equations in terms of n firstorder differential equations.1 Introduction Chapter 4 discusses the Linear Quadratic Regulator (LQR) control technique in detail.28 CHAPTER IV LQR CONTROL METHOD 4. While conventional control theory is based on the input output relationship. . LQR is a method in modern control theory that uses statespace approach to analyze such a system.
For the PID controller. Using statespace method. Rise time for x of less than 1 second.5455 (4.1818 2. x(t ) x(t ) (t ) (t ) 0 0 0 0 1 0 0.2 StatesSpace Design The model of inverted pendulum system can be represented in state space as shown in equation 4. Overshoot of theta less than 20 degrees (0. it is relatively simple to work with a multioutput system. . two controllers are needed to control both the carts’ position and pendulum’s angle simultaneously.1818 0 x(t ) 0 x(t ) 1 (t ) 0 (t ) 0 1.35 radians).6727 0 0 0.1) y (t ) x(t ) 1 0 0 0 x(t ) 0 0 1 0 (t ) (t ) 0 u (t ) 0 The design criteria for this system with the cart receiving a step input are as follows: Settling time for x and theta of less than 5 seconds.1.29 4. Steadystate error within 2%.8182 u (t ) 0 4.4545 31.
The schematic of this type of control system is shown in Figure 4.1: Schematic diagram for inverted pendulum in statespace form where. C = output matrix. This problem can be solved using full state feedback. but eventually return to zero .1 has been determined using the method as discussed in the inverted pendulum modeling part in Chapter 2. The output y contains both the position of the cart and the angle of the pendulum. The four states. A = state matrix. . ) represent the position and velocity of the cart and the angle and angular velocity of the pendulum. B = input matrix state vector. a LQR controller design with both the pendulum's angle and the cart's position are considered.1. Full State Feedback y R +  x(t) Ax(t) By(t) y(t) Cx(t) K x Figure 4. ( x. The equation 4. the pendulum should be displaced. y(t) = output vector In this problem. x.30 In this chapter. R represents the commanded step input to the cart. A controller will be designed so that when a step input is given to the system. X(t) = R = step input to the cart D = direct transmission matrix u(t) = input vector.
row3) will be used to weight the pendulum's angle.2. the place or acker command could be used. 4. The element in the (1. at the columnl.e. row1) will be used to weight the cart's position and the element in the (3. therefore the K matrix that will produce a good controller could be found by running the mfile code in Matlab. the vertical) and the cart should move to its new commanded position. 3) position (i. The Matlab command of this step can be referred to the Appendix A5. To find the structure of Q. There is one righthalfplane pole at 5. and Q=C'*C. the LQR method allows for the control of both outputs. . This proved that the system is unstable in open loop. Since the Q matrix has been determined previously. By finding the vector K. R and Q can be chosen.1 LQR Control Method The next step in the design process is to assume that the system have fullstate feedback. In this case. The simplest way is to assume R=l. two parameters i.57. If the desired closedloop poles know. The input weighting R will remain at 1. The first step in designing this type of controller is to determine the openloop poles of the system. The controller can be tuned by changing the nonzero elements in the Q matrix to get a desirable response. Using the LQR function. which will balance the relative importance of the input and state in the cost function for optimizing. the feedback control law is determined. at column3.e.31 (i. the term Q = C’ * C is entered into the Matlab command window. Another option is to use the LQR function that will give the optimal controller.e.e. Essentially. the LQR controller design will be easier to do. 1) position (i.
where the output is feedback and compared to the reference input to compute an error. This error will be dealt with in the next section by adding a reference input to the system block diagram. the plot of Figure 7. In this problem. all the states are feedback so that it can be multiplied with the K matrix.2 Adding a Reference Input In contrast to the other design methods. but the settling times (Ts) need improvement and the cart's rise time (Tr) needs to go down.8 in Chapter 7 for the step response with LQR control. the best response should be obtained (see Appendix A5 for the command to get step response with LQR control). Matlab command of this step can be referred to the Appendix A5. improvement to the response should be obtained even more. The response plot is shown in the Figure 7. but the smaller the tracking error. But.32 The response can be plotted easily in one step so that changes can be made in the control and it can be automatically seen in the system output. 4. The higher x and y are given. for this case. . As an example. the more control effort is used. The pendulum and cart's overshoot appear fine (less than 0. The x and y variables could be changed to see the various responses. However. this plot is not satisfactory achieved. If x and y are increased even higher. with a fullstate feedback controller.35 radians).2.8 was chosen because it satisfied the design requirements while keeping x and y as small as possible. the values of x and y have been used to describe the relative weight of the tracking error in the cart's position and pendulum's angle versus the control effort. when the command with x = 5000 and y = 100 is put in Matlab command window.
the value of Nbar. A different C had to be used because the rscale function will not work for multiple outputs.7107 . The lsim line should be deleted while the rscale function is copied into the command window. This function is built in mfile code as shown in Appendix A6.2. The step response with consideration of Nbar.2: Schematic diagram of system with constant gain. multiply that by the chosen gain K. This can be done by adding a constant gain named Nbar. the mfile code of Nbar should be run together with the Matlab command for LQR design. R N +  y x y Ax Cx By K x Figure 4.33 It is required to compute the steadystate value of the states should be. Nbar Nbar. However.( N ) is found correct as shown below: Nbar = 70.( N ) can be found using the userdefined function rscale.( N ) can be seen by running the mfile code. The schematic of this relationship is shown in Figure 4. (N) after the reference. This function is not a standard function provided in the Matlab control system toolbox. and use a new value as a reference for computing the input. In order to use rscale function.
The steadystate error is within limit. A schematic of this kind of system without Nbar is shown in Figure 4.3 FullOrder Estimator This response can be consider as a good response. but was found assuming fullstate feedback. 4. the rise and settling times are met and the pendulum's overshoot is within range of the design criteria. which most likely will not be a valid assumption.3 Figure 4.9 in Chapter 7.34 The step response with LQR and Nbar control is shown as in the Figure 7. the controller poles have to be found first.3: Schematic diagram of system in statespace with estimator In order to design full order estimator. This step could be done by copying the following code to the end of mfile p = eig(Ac) .2. the next design is a fullorder estimator to estimate those states that are not measured. To compensate this problem.
. The system is not observable using only the angle of the pendulum as output.35 The estimator poles are about 4 to 10 times as fast as slowest pole. The response should be similar to the one from the controllaw design. rank(obsv(A.10 in Chapter 7 should be determined. :))) The system is observable if the output of the rank command is equal to four . it is cannot determine what the position of the cart will be. Then.C(2. The lsim command should be deleted and the command for P and L is entered as shown in the Appendix A7 at the end of current mfile to find the L matrix. By running the mfile. If the only angle of the pendulum could be measured. The situation could be checked via Matlab command. it is needed to copy the MATLAB command in the Appendix A7 to find the step response for the system with estimator. say at 40 is chosen. the step response simulation is plotted as shown in the Figure 7. The place command in Matlab is used to find the L vector. Now combination of the controllaw design and the estimator design is proposed to get the compensator. The place command cannot have all the desired poles at the same location. so no more iteration is needed. It is found that all of the design requirements have been met with the minimum amount of control effort. Both outputs have been used (the angle of the pendulum and the position of the cart) to design the estimator.
the steady state error is within the limits. This drawback can be solved by applying the Artificial Intelligent controller such as FLC and ANN.36 4. However. The PID and LQR controllers are both could control the linear system or a linearized model. the rise and settling times are met and the pendulum's overshoot is within range of the design criteria.3 Conclusion As a conclusion. it is found that LQR statespace method is the best control method to control a multioutput system compared to PID control method which was described previously. the more control effort is used. Then by adding a reference input. . it is determined that all of the design requirements have been met successfully. By applying a combination of the controllaw design and estimator to get the compensator. This type of controller will be discussed in the next chapter. but the smaller the tracking error is get. The higher x and y are given.
1 Where Did Fuzzy Logic Come From The concept of Fuzzy Logic Controller (FLC) was conceived by Lotfi Zadeh. This approach to set theory was not applied to control systems until the 70's due to insufficient smallcomputer capability prior to that time. embedded microcontrollers to large. they would be much more effective and perhaps easier to implement. networked.2 What Is Fuzzy Logic In this context. and yet they are capable of highly adaptive control. [13] 5. but as a way of processing data by allowing partial set membership rather than crisp set membership or nonmembership. a professor at the University of California at Berkley. Professor Zadeh reasoned that people do not require precise. multichannel PC or workstationbased data . small. imprecise input. If feedback controllers could be programmed to accept noisy.37 CHAPTER V FUZZY LOGIC CONTROLLER 5. FLC is a problemsolving control system methodology that lends itself to implementation in systems ranging from simple. and presented not as a control methodology. numerical information input.
[11] . Main areas of application are numerous. the inverted pendulum does not need to be linearized. FLC's approach to control problems mimics how a person would make decisions. Many research activities and application are going on especially in Japan. FLC provides a simple way to arrive at a definite conclusion based upon vague.1: Comparison between Fuzzy Logic controller and PID controller When idea of fuzzy logic is applied to control. imprecise. As can be seen. It can be implemented in hardware. However the model should be fuzzify and defuzzify by applying reasoning with fuzzy control rules. Fuzzy control is the first ever known to which fuzzy logic is applied. or a combination of both. it is generally called as ' fuzzy control. ambiguous. REASONING WITH FUZZY CONTROL RULES FUZZIFY DEFUZZIFY CONTROL SIGNAL STABILISE AN INVERTED PENDULUM F INVERTED PENDULUM PENDULUM IS STABILISED X LINEARISE DESIGN PID CONTROLLER APPLY PID CONTROLLER Figure 5.38 acquisition and control systems. or missing input information. the inverted pendulum model should be linearized. only much faster. [4] Figure 5. In contrast with the FLC controller. water purification plants etc. such as control of cement kilns. This will produce inaccurate model if it is applied to the real system. noisy.1 shows the comparison method between Fuzzy Logic controller and PID controller. electric trains. in order to design PID controller. software.
x and y and the input for the process (amount of work). The above expression can be simplified into another statement as shown in Figure 5. The control algorithm is given in the IF THEN expression such as if x is small and y is big then z is medium.then clause. Naturally.e. the driver uses the above mentioned if . he just uses the rules which he has learned beforehand. These rules are such as ' if speed gets too high. In general. Figure 5. time needed to reach 100 km/h.2: Control algorithm of fuzzy logic controller This way of control is synonymous to a control applied by a worker or a driver. i. acceleration. an expert who controls a system. For example. push the break firmly or if he is taking a hill and there is snow on the road then go moderately ' and so on. In that sense. a driver does not calculate the speed.1 The Form of Fuzzy Control Rules and Inference Method Fuzzy control describes the algorithm for process control as a fuzzy relation between information about the condition of the process to be controlled. if x is big and y is medium.39 5.2. variables x and y are called the input .2. driver wants to go up to 100 km / h and car goes at 20 km / h (relatively small speed) and acceleration is small then driver increases the speed of car largely. then z is big. The above mentioned if clause of the rules is called the antecedent and the ' then 'clause is called ' consequent '.
firmly. input and output of the system are not linguistics variables but certain mathematical values (crisp values). Small.4: A Type membership function . membership functions are used both for input and output. The range gives a major effect to the system response because it will affect the fuzzy reasoning.4 show the triangular membership function and trapezoidal membership function of fuzzy logic controller respectively. Figure 5. However.3: A Triangular membership function of Fuzzy Logic Controller Figure 5. big.3 and Figure 5.40 and the z output. the range of the membership function or universe of discourse can be varied within a specified range. are fuzzy variables for x and y and they are expressed by fuzzy sets. moderately etc. the amplitude or grade of the membership function is set to 1. Normally. Figure 5. Although the fuzzy variables are used. In order to fuzzify these crisp values.
Block diagram of the fuzzy controller is given as shown in Figure 5.41 There are two types of fuzzy variables. increasing respond time. The inference for fuzzy control is different from standard fuzzy inference in that the propositions (the actual input for the fuzzy controller) are commonly standard numerical values. and when an actual input is given. Fuzzy controllers are constructed of groups of these fuzzy control rules.e. simple methods are used. but in consideration of the time for the calculation.1 Table 5. continuous and discrete types.1: Discrete type of fuzzy variables Input Domain 0 PB PM PS ZR 0 0 0 10 1 0 0 3 7 2 0 3 7 3 3 0 7 10 0 4 3 10 7 0 5 7 7 3 0 6 10 3 0 0 As number of discrete variables increases it approaches to continuous type of fuzzy variables. not fuzzy values. as number of discrete variables increases computing time also increases i. . the output is calculated by means of fuzzy inference. Fuzzy inference is based on fuzzy logic. However. As a result an optimization should be carried out between the resolution and computing time. Discrete fuzzy variables are the simplifying method for continuous fuzzy variables as shown in Table 5.5. The major difference between the methods used in areas such as production rules for knowledge engineering and fuzzy control is that latter permits fuzzy expression (single stage inference) whereas the former is almost multistage.
1. If x1 is A11.2.2. singleoutput instance of this inference method comes out as follows.2. . x2 is A12 then y is B1 If x1 is A21. and x1 is error x2 is delta error ( the change in error during one sampling) and delta u for the output.5: Block diagram of fuzzy controller 5.2 Type of Fuzzy Controllers 5. x2 is A22 then y is B2 The above two rules may be applied to case of single input single output process set point control. Inference Method 1 In fuzzy inference method 1. [12] A two input. it is common to have five to seven fuzzy variables.42 Figure 5.
The first step in the control loop is to find out compatibility for each of the compatibility antecedent conditions of the rules and the input. two crisp values of x1 = x1o and x2= x2o are provided by some means. The next step is to get the results of the inference for the ith rule. In this example the antecedent is two dimensional. In general.6. and min is the function which gives minimum of its parameters. i. such as sensor and analoguedigital converter. so compatibility will be.e. that is.2 where i is the number of the rule. the membership function of x0 for fuzzy set A. B*=w1B1 w2B2 and found as the central axis of the membership function of B* as B * ( y ) ydy B * ( y )dy y0 It is also shown graphically in Figure 5. The complete inference result yo is constructed from the w1B1 and w2B2. .43 In each control loop. let the compatibility for the antecedent 'x is A ' be A(x0). wi=min ( Ai1( x1o). Ai2 (x20) i=1. y is wiBi but wi Bi ( y) = wi x Bi(y) There are cases where a min operation replaces the multiplication as wi Bi(y)= wi Bi ( y).
6: Schematic representation of Inference Method 1 . these are essentially the same for all inference methods. In fact.6 Figure 5. (1) Calculate the compatibility for the inputs and antecedent of the rules (2) Find the inference results for each rule (3) Find the complete inference result as a weighted mean of the inference results for each rule with respect to compatibility Schematic representation of this inference method is given in Figure 5.44 The first inference method is made of the following three steps.
2 Inference Method 2 This second method is especially suitable for the fuzzy variables that have monotony membership functions. Figure 5.45 5. if x1 is N and x2 is P then y is N if x1 is P and x2 is N then y is P Here in this method.7: Monotonic membership functions As an example.2. such as shown in Figure 5.2. There are also changes in slope. consider the following two rules. It can be easily seen from the figure that there are only two types of variables as positive and negative and as can easily be seen from the figure that arctan(x) can be used for the membership function. . there is no difference between first and second method for finding the compatibility of the antecedent for inputs x10 and x20 and w1 and w2 are found for the first and the second rules respectively.7.
e. taking linguistic form into logical form.8: Schematic representation of Inference Method 2 If a comparison is made between first and the second methods. Second method is not a suitable one for putting the knowledge of expert. i. The inference method is shown in below Figure 5.8 Figure 5.46 Inference results y1 and y2 (non fuzzy crisp values) for each rule are found using the following relational equations. i) Fewer rules are necessary for the second method than for the first one ii) First method is suitable when there are many fuzzy variables iii) Since there are few fuzzy variables. . w1= N(y1) and w2=P(y2) The overall inference result is given by taking the weighted mean of y1 and y2. these differences can be found.
Inference Method 3 The antecedents used in this method are made up of fuzzy propositions. so the result is the same as having a linear expression.47 5. x2 is A12 then y=f1(x1. the antecedent parts are no longer necessary. x2) if x1 is A21. and then inference results for each of the rules are calculated directly from the equations written in the consequent. . This was conceived for fuzzy process modeling rather than for fuzzy control. x2) The compatibility of antecedents for x1 and x2 is found as w1 and w2 respectively. if x1 is A11. as done in Inference Method 2.2. x2 is A22 then y=f2( x1.2. The fuzzy variables used in the antecedent are trapezoidal membership functions composed of straight lines. It can be easily seen that if number of rules is 1. In this method f11 and f22 are linear equations. and only consequent part remains.3. The complete inference result is found using the following equation. Consider the following two rules. and the consequent are the standard relational equations of inputs and outputs.
This problem can be divided into two parts.3. the problem of determining the form of the control rules is very crucial. This method is not suitable for linguistic expressions but exceeds the others in descriptive capability. there is no difference in the structure of the relation if x1 = PB ( positive big) and x2=PS ( positive small) then y = NM (negative medium ) if x1 = 10 and x2 = 2 then y = 6 In other words. For the antecedent part. 5. they are numerical tables and only quantify amount. i. Planning Of Fuzzy Controllers In designing fuzzy control. determination of the antecedents and the determination of the consequent. 1) The input information for x1. that group gives something very similar to global nonlinear inputoutput relation. x2. the input interval is partitioned into subspaces and a linear input / output relation is found for each subspace. In fact.e. three things have to be determined. The rules used in inference method 1 do not go beyond description of quantitative relations.48 If there is more than one rule. the rules that arise using the conditions (subspaces) specified in the antecedents in the third form are written directly in the consequent. However. and etc which must be used in the antecedents is selected .
output is generally the control input for the process controlled. . the fuzzy partitions of the input 3) Determination of the parameters for the fuzzy variables. 5.4 How Is FLC Different From Conventional Control Methods FLC incorporates a simple. For the consequent part. relying on an operator's experience rather than their technical understanding of the system. and the only problem is the wholly determination of the antecedents.49 2) Determination of the conditions. rather than dealing with temperature control in terms such as "SP =500F". These terms are imprecise and yet very descriptive of what must actually happen. Determination of the consequent is not difficult. that is. rulebased IF X AND Y THEN Z approach to a solving control problem rather than attempting to model a system mathematically. FLC is capable of mimicking this type of behavior but at very high rate. The FLC model is empiricallybased. "T <1000F". terms like "IF (process is too cool) AND (process is getting colder) THEN (add heat to the process)" or "IF (process is too hot) AND (process is heating rapidly) THEN (cool the process quickly)" are used. The only remaining problem is the fuzzy parameters. or "210C <TEMP <220C". For example. Consider what you do in the shower if the temperature is too cold: you will make the water comfortable very quickly with little trouble.
These values don't have to be symmetrical and can be "tweaked" once the system is operating in order to optimize performance. complex mathematical computation and realtime computation need. Generally.6 Fuzzy Of Inverted Pendulum System FLC was conceived as a better method for sorting and handling data but has proven to be an excellent choice for many control system applications since it mimics human control logic.5 How Does FLC Work FLC requires some numerical parameters in order to operate such as what is considered significant error and significant rateofchangeoferror. [42] 5. It uses an imprecise but very descriptive language to deal with input data more like a human operator. when inverted pendulum is considered. handheld products to large computerized process control systems. Error might have units of degs F and a small error considered to be 2F while a large error is 5F. Fuzzy controller fits the requirements very well in such . For example. but exact values of these numbers are usually not critical unless very responsive performance is required in which case empirical tuning would determine them. FLC is so forgiving that the system will probably work the first time without any tweaking. has been employed for stabilization of the inverted pendulum. It is very robust and forgiving of operator and data input and often works when first implemented with little or no tuning. hereafter called "errordot". Fuzzy controller. a very new technique. fuzzy controller. The "errordot" might then have units of degs/min with a small errordot being 5F/min and a large one being 15F/min. It can be built into anything from small. In this study.50 5. a simple temperature control system could use a single temperature feedback sensor whose data is subtracted from the command signal to compute "error" and then timedifferentiated to yield the error slope or rateofchangeoferror. The reasons are nonlinearity. is a very good choice for control strategy.
Generally. number of fuzzy partitions must be identified. especially for higher complex systems which need direct expert control. type of membership functions should be chosen correctly.1 Fuzzy Logic Controller Design Flow Chart Figure 5. the input and output of the system. In designing FLC.9.9: Fuzzy Logic controller design flow chart . Design Planning Identify process input and output variable Identify controllers’ inputs and outputs Determine of number fuzzy partitions Choose type of membership functions Derive fuzzy control rulesbased Define inference engine Choose Defuzzification method Parameter Tuning Mapping of membership functions Fuzzy inference rules Scaling factors Fuzzy Logic Controller Operation Fuzzification Fuzzy inference Defuzzification Simulation & Testing No OK Yes End Figure 5.51 cases. it is important to plan the characteristic of the controller. fuzzy control rulesbased must be derived.6. Moreover. 5.9 shows the flow of designing the fuzzy logic controller. By following the flow chart as shown in Figure 5. in designing the controller. applying a new technique offers new horizons to the researcher. the inference engine and the defuzzification method should be chosen correctly. the FLC can be designed successfully. Moreover.
pendulum angle. The proposed defuzzification methods for the FLC are Sugeno or Mamdani. All of these system outputs will then be sent to the FLC s inputs.11. it can be seen that the input of the system is the disturbance force. In this problem.52 From Figure 5. the ‘FLC 1’ controls the cart’s position. whereas the ‘FLC 2’ controls the pendulum’s angle.11.10 and Figure 5. F INVERTED PENDULUM (NONLINEAR) X X F FLC CONTROLLER Figure 5. cart velocity. As can be seen in Figure 5. The FLC will manipulate the information and produces the output force that is back propagated to the system.11. it is possible to give two inputs to the FLC as shown in Figure 5. and angular velocity of the pendulum. The outputs of the system are the cart displacement.10: Block diagram of the system with fuzzy logic controller In order to implement four inputs to the controllers. The ‘FLC 1’ received x and x . This is because both of these techniques are commonly used in designing the FLC. the FLC were divided into two.
This block diagram shows the flow of the FLC in detail. the defuzzification method used is the Mamdani Sugeno type. As stated in the diagram.53 as the inputs while the ‘FLC 2’ received and as the inputs. The control variables of both FLC were summed together to become a force and the input to the system. + Reference position  x FLC 1 (Control Position) + + Force FLC 2 (Control Angle) Position x Angle + Reference Angle  Figure 5.11: Rearranged block diagram of the system with Fuzzy Logic Controller Figure 5.12 shows the FLC block diagram. .
F 2.2. position of cart and set point position. x 4.54 FUZZY CONTROLLER KNOWLEDGE BASE 4 Inputs FUZZY FUZZY Mamdani Sugeno DEFUZZIFIER FUZZIFIER INFERENCE ENGINE PROCESS OUTPUT & STATES PROCESS CRISP CONTROL SIGNAL Figure 5. Angular velocity of pendulum shaft/pole.2 Inputs and Outputs of FLC Through observations the input and output fuzzy variables has been identified. x .2: Inputs and outputs of FLC No Input Output 1. Angle between pendulum shaft/pole and vertical line. Table 5. 3. This is shown in Table 5. Difference (error signal) between Force to push the cart.12: Fuzzy logic controller block diagram 5. Rate at which the error of position changes.6.
This can be acquired from the previous research papers that were done by the expert. It was done so that the tuning process of the controller can be easily done. The triangular shape was used to design the FLC.3: Standard labels of quantization Linguistic Term Label Negative Big Negative Medium Negative Small Zero Positive Small Positive Medium Positive Big NB NM NS ZE PS PM PB Figure 5. It is needed to know the nature of the plant from the expert knowledge. It was the crucial step to determine the appropriate values. In addition. seven fuzzy subsets are needed to quantize each fuzzy variable for both FLC as sown in Table 5. Table 5. Two fuzzy logic controllers are needed to excite the stabilize force to the cart.3. As we can see from the figure. There are FLC to control position and FLC to control angle. . the membership functions were evenly distributed.3 Membership functions The input and output variables have to be quantized into several modules or fuzzy subsets and the appropriate labels are assigned in this controller.18 show the membership functions of FLC’s.55 5. the ranges of the membership functions are different to each other.13 till Figure 5. According to the complexity of this inverted pendulum system.6.
56 Membership functions for each of the fuzzy subsets of the control position FLC NB 1 NM NS ZE PS PM PB 0.6 0.8 D g e o m m e ip e re f e b rsh 0.8 Degree of membership 0.14: Input 2 of Fuzzy Logic Controller 1 .2 0 3 2 1 0 Position 1 2 3 Figure 5.4 0.2 0 3 2 1 0 Delposition 1 2 3 Figure 5.4 0.6 0.13: Input 1 of Fuzzy Logic Controller 1 NB 1 NM NS ZE PS PM PB 0.
57 NB 1 NM NS ZE PS PM PB 0.25 0.2 0.15: Output of Fuzzy Logic Controller 1 Membership functions for each of the fuzzy subsets of the control angle FLC: NB 1 NM NS ZE PS PM PB 0.2 0 10 8 6 4 2 0 Force 2 4 6 8 10 Figure 5.8 D egree of m bership em 0.2 0 0.6 0.15 0.16: Input 1 of Fuzzy Logic Controller 2 .8 D g e o m m e ip e re f e b rsh 0.15 0.6 0.4 0.2 0.1 0.25 Figure 5.1 0.05 0.4 0.05 0 Angle 0.
8 D egree of m bership em 0.4 0.2 0 1 0.6 0.18: Output of Fuzzy Logic Controller 2 .6 0.8 1 Figure 5.8 0.2 0.2 0 Delangle 0.17: Input 2 of Fuzzy Logic Controller 2 NB 1 NM NS ZE PS PM PB 0.4 0.8 D egree of m bership em 0.6 0.4 0.58 NB 1 NM NS ZE PS PM PB 0.2 0 10 8 6 4 2 0 Force 2 4 6 8 10 Figure 5.6 0.4 0.
there are only 34 rules that are applied to the controllers. Table 5. However.59 5.6 Rule base Table 5. The total rules that should be given are 49 rules.5: Fuzzy rule matrix for control angle FLC ANGLE NB NB DELANGLE NM NM NM NS NS NS NS ZE NS NS NS ZE PS PS PS PS PS PS PS PS PS PS PS PM PM PM PB PB NB NM NS ZE PS PM PB NB NB NM NS NS PM PB NM NM NS NS PM .4 and Table 5.4: Fuzzy rule matrix for control position FLC POSITION NB NB DELPOSITION NM NM NM NS NS NS NS ZE NS NS NS ZE PS PS PS PS PS PS PS PS PS PS PS PM PM PM PB PB NB NM NS ZE PS PM PB NB NB NM NS NS PM PB NM NM NS NS PM Table 5. all the rules are the same.5 show the fuzzy rule matrix for controlling the position and fuzzy rule matrix for controlling the angle respectively. As can be seen from the tables.
The output response of the system will be discussed in Chapter 7. . The tuning process of the FLC is more difficult compared to PID and LQR controllers.6.60 5.19 shows the schematic diagram of the Nonlinear Inverted Pendulum System with two FLC controllers in Simulink. there are 2 FLC’s in the diagram. range values and etc. Each of them has a function to control the position of a cart and to control the angle of the pendulum respectively. As can be seen from the figure.4 Implementation in Simulink Figure 5. The output of the controllers is the forces which will be summed up together to produce equivalent force to the plant system. gains. This is because there are a lot of parameters need to be considered such as membership functions.
94 Gain Fuzzy Logic Controller (Position) Total Force 1 Gain1 Fuzzy Logic Controller (Angle) Mux R2D Radians to Degrees Mux simout angle tetadot Figure 5.61 Step1 animcp Manual Switch Mux Target Position Constant 1 Target Position (MouseDriven) Switch Mux 0.675 position simout1 Animation nonlinear inverted pendulum xdot x .19: Schematic diagram of the Nonlinear Inverted Pendulum system with two FLC controllers in Simulink .
.62 5. This can be verified through the output responses of the system which satisfy the design criteria. Fuzzy logic has provided a simple way without going through the mathematical approach as conventional controller in order to arrive at a definite conclusion based upon nonlinear and an unstable of inverted pendulum system. The controller design could stabilize the pendulum rod and keeping the cart in a desired position. the control objective in stabilizing the inverted pendulum has been achieved by using two block of Fuzzy logic controller.6 Conclusion As a conclusion.
These connections store the knowledge necessary to solve specific problems. . ANNs learn by example. trained using known input/output data sets to adjust the synaptic connections that exist between the neurons. the brain processes information [8]. The biological neuron can be illustrated in Figure 6. It is composed of a large number of highly interconnected processing elements (neurons) working in parallel to solve a specific problem.1.1 Introduction A neural network is an informationprocessing paradigm inspired by the way. Learning in biological systems involves adjustments to the synaptic connections that exist between the neurons. The biological neuron is composed of a large number of highly interconnected processing elements called neurons and is tied together with weighted connections or synapses.63 CHAPTER VI ARTIFICIAL NEURAL NETWORKS CONTROLLER 6.
Nonlinearity is a desired property if the generator of the input signal is inherently nonlinear [10]. This is achieved by presenting a training set of different examples to the network and using learning algorithms.2 Advantages of ANN’s There are several advantages of ANN as follows: 1. to train a neuron model to approximate a . which ideally gives a high fault tolerance. 6. The main advantage of neural networks is that it is possible to train a neural network to perform a particular function by adjusting the values of connections (weights) between elements. One encountered difficulty is how to guarantee generalization and to determine when the network is sufficiently trained. For example.64 Figure 6. A neural network offers nonlinearity.1: Biological neuron One of the most interesting features of NNs is their learning ability. The high connectivity of the network ensures that the influence of errors in a few terms will be minor. inputoutput mapping. adaptivity and fault tolerance. which changes the weights (or parameters of activation functions) in such a way that the network will reproduce a correct output with the correct input values.
Parallel processing allows increased speed of calculation compared to slower sequential processing. After training. Neural networks can be trained offline and then transferred into a process where adaptive learning takes place. . In this case. The main disadvantage of ANN is they operate as black boxes. The ANN is placed in a feedback loop with the actual process. Another disadvantage is the amount of time taken to train networks. The memory in neural networks corresponds to the weights in the neurons.2: Diagram of neuron model Artificial neural networks (ANN) have memory. Neural networks are composed of elements operating in parallel. It can take considerable time to train an ANN for certain functions. It is not possible to convert the neural structure into known model structures such as Armax. the network weights are set.65 specific function. The example of neuron model is illustrated in Figure 6. the weights that multiply each input signal will be updated until the output from the neuron is similar to the function. The rules of operation in neural networks are completely unknown. etc. The network will adapt the weights to improve performance as it controls the pendulum system. 2. a neural network controller could be trained to control an inverted pendulum system offline say in the simulink environment.2 Figure 6.
3 Types of Learning Neural networks have three main modes of operation – supervised. Other types of single layer networks are based on the perceptron model.3: Diagram of the Perceptron model Inputs to the perceptron are individually weighted and then summed.66 6. The perceptron computes the output as a function F of the sum. 6. the error signal is used to update the weights in the neural network. [7] The most common type of single layer feedforward network is the perceptron.4 Neural network structures There are three main types of ANN structures single layer feedforward network. the algorithm is given a grade of the ANN performance.3 The details of the Figure 6. In supervised learning the output from the neural network is compared with a set of targets. Reinforced learning is similar to supervised learning however there are no targets given. The ANN learns to cluster different input patterns into different classes. F is needed to . multilayer feedforward network and recurrent networks. Unsupervised learning updates the weights based on the input data only. reinforced and unsupervised learning [6]. perceptron is shown in Figure 6. The activation function.
6 Learning Algorithms In neural networks learning ability is achieved by presenting a training set of different examples to the network and using learning algorithm to changes the weights (or the parameters of activation functions) in such a way that the network . The effect of the linear function is to multiply by a factor a constant factor.5 Activation functions There are number of different types of activation functions such as step. The sigmoid function has an S shaped curve. logsigmoid and linear function as shown in Figure 6.67 introduce nonlinearities into the network. [5] 6. However the most commonly used activation functions are tansigmoid. ramp. sigmoid etc.4: Activation functions Linear function 6.4. This makes multilayer networks powerful in representing nonlinear functions. [9] Logsigmoid function Tansigmoid function Figure 6.
if present error is back propagated to have weight and bias changed. and unsupervised. learning is stopped. The difference is the error. there is a set of pairs of inputoutput patterns. Figure 6. A supervised learning scheme is illustrated in Figure 6.5. In the supervised learning procedure. This form of learning structure is a classic example of supervised learning.6. There are three main classes of learning reinforced.68 will reproduce a correct output with the correct input values. supervised. if this is absence.5: Supervised learning 6. . The latter two will be considered here. The network propagates the pattern inputs to produce its own output pattern and then compares this with the desired output. the error between the system and network outputs is calculated and subsequently used as the network training signal. The neural network model is placed in parallel with the system both receiving the same input.7 Forward Modeling of Inverted Pendulum Using Neural Networks A common structure for achieving system identification using neural networks is forward modeling as shown in Figure 6.
6 and Figure 6. it can be seen that the output of the inverted pendulum system is compared to the desired response so that the error signal will be produced.6: Forward modeling of inverted pendulum using neural networks The block diagram of Figure 6.6 can be simplified into another form as shown in Figure 6. The error signal is then back propagated so that weight and bias is changed as stated in the previous section. .69 ` Supervised Learning INPUT u INVERTED PENDULUM x x SYSTEM ARCHITECTURE x u x ADJUST WEIGHT LEARNING ALGORITHM DESIRED RESPONSE Figure 6.7. From Figure 6.7.
the difference .7: Rearranged forward modeling of inverted pendulum using neural networks 6. The net simply propagates the pattern inputs to outputs to produce its own patterns comparing this with the desired output. It should also be noted that the size of the neighborhood may adjust during this training period.70 System with NN x SYSTEM I/P u INVERTED PENDULUM x SYSTEM O/P NEURAL NETWORK Figure 6.8 Learning rules Hebb’s Rule was the first rule developed. and if both are highly active. The Back propagation learning algorithm is perhaps the most popular learning algorithm. furthermore this element plus its adjacent neighbors are permitted to adjust their connection weights. Kohonen’s learning rule is a procedure whereby competing processing elements contend for the opportunity to learn. The only permitted output is from the winning element. then the weight between the neurons should be strengthened. The rule declares that when a neuron receives an input from another neuron.
9 Implementation in Simulink Figure 6. The ANN controller block was then imported to the simulink diagram. 6. the tuning process is difficult to do. However. it is back propagated to change weights and biases. As can be seen from the figure.71 being the error. Therefore. The drawback of this approach is the online training using the simulink diagram could not be done. The output response will be discussed in Chapter 7. The design of the ANN in simulink is tedious to implement. The reason of doing this approach is that the ANN training method was done using mfile. In the task. the diagram is more complex compared to the other controllers that were discussed previously. a few parameter blocks such as gain and saturation blocks were added to the diagram. this recurs until no error is present. ANN is divided into 2 parts to get the equivalent force as the input to the plant. however if error is present. this would make the simulation into few limitations. . If no error is present learning stops. Controller one was used to control the angle of the pendulum while controller two was used to control the position of the cart simultaneously.8 show the block diagram of the Inverted Pendulum System with two ANN controllers in Simulink. In order to solve the problem.
72 S te p 1 a n im cp M anual S w i tc h M ux T a rg e t P o si t i o n C o n st a n t 1 S w i tc h 0 . 6 7 5 R2D Ra d ia n s t o D e g re e s n o n l i n e a r i n v e rt e d p e n d u l u m S a t u ra t i o n 3 A n i m a ti o n T a rg e t P o si t i o n (M o u se D ri v e n ) 1 .9 4 te ta G a in 1 T o W o rksp a c e 1 N e u ra l N e t w o rk2 0 .5 G a in 2 N e u ra l N e t w o rk1 f T o W o rksp a c e 5 Figure 6.5 S co p e si m o u t T o W o rksp a c e G a in S a t u ra t i o n S a t u ra t i o n 1 y {1 } p {1 } 0 .8: Block diagram of the inverted pendulum system with ANN in Simulink .8 G a in 4 te ta d o t T o W o rksp a c e 2 G a in 3 x T o W o rksp a c e 3 xd o t S a t u ra t i o n 2 T o W o rksp a c e 4 10 y {1 } p {1 } 0 .
1 Table 6.1: Properties of Neural Network Feedforward Architecture ANN Model All signals flow in one direction only. The net simply propagates the pattern inputs to outputs to produce its own patterns Activation Function TanSigmoid (Hidden Layer) Linear Function (Output Layer) Supervised learning: Learning Algorithm in ANNs Learning with teacher signals or targets Produce its own output pattern and then compares this with the desired output.73 In designing ANN controller. Some of the properties in designing ANN were summarized as in Table 6. 2 Layers Hornik and indeed other researchers have shown that even a twolayer network with a suitable number of nodes in the hidden layer can approximate any continuous function over a compact subset [1]. from lower layers (input) to upper layers (output) The Back propagation learning Learning Rule Most popular learning algorithm.e. feeddforward architecture and backpropagation learning algorithm were used as discussed in the previous chapter. i. . The difference is the error One hidden layer is suitable for the purpose of identification.
model can’t be updated directly from Simulink.9. Instead of that. In order to train a stable model.74 6. System identification is involved. Therefore. The model was build in mfile. Therefore. the neural network controller was not successfully designed due to the some limitations that were previously discussed. further improvement could be done to reach the better response as required by the design criteria. 6. the particular ANN block could not be used. Since this system involved multiple output response.10 Conclusion As a conclusion. 3. an The response of the identification of accurate response needs to be done. Online training can’t be done in Simulink block instead of mfile. then is was imported to the Simulink block. The tuning process was difficult to do. No appropriate Simulink block of multiple outputs for ANN. and the learning hardly be evaluated. pendulum system would depend on the training response. the training signal for the network model was satisfactorily achieved. Unlike the FLC. 2. . the block was generated from the mfile command. The generation of teaching signal for learning can not be easily realized. a lot of parameter values can be changed directly from Simulink blocks. However. 4. Some of the factors are as follows: 1.1 Problems and constraints in designing the ANN controller The design failure of the ANN controller because of some constrains and problems that have been faced during the design process.
From the Figure 7.2 OpenLoop Results As mentioned in Chapter 2. the mathematical model and equations using the transfer function and statespace of the inverted pendulum have been determined. it can be noticed that the inverted pendulum system is not stable without controller.1 till Figure 7. Therefore.1 Introduction This chapter discusses the results of the open loop system without controller.3. . the responses of the system with several controllers such as PID. 7. LQR. the following results could be seen. The curve of the pendulum’s angle and cart’s position were approached infinity as the time increases. FLC and ANN are being applied. By implementing all these equations into Matlab Mfile command.75 CHAPTER VII RESULTS AND DISCUSSION 7. some controllers need to be designed in order to stabilize the system.
5 0.2 0.1: Impulse response for pendulum’s angle using transfer function Figure 7.7 0.8 0.9 1 Figure 7.4 0.76 IMPULSE RESPONSE (ANGLE) 60 50 40 AMPLITUDE 30 20 10 0 0 0.1 0.3 0.6 TIME (SEC) 0.2: Impulse response for cart’s position using transfer function .
3.4 0.2 0.8 1 1.77 Pendulum's Angle Cart's Position RESPONSE TO A STEP INPUT 100 90 80 70 AMPLITUDE 60 50 40 30 20 10 0 0 0.4 1. As can be seen that both of the responses approaches infinity as time increases.8 2 Figure 7.3: Impulse response for pendulum’ angle and cart’s position using statespace From Figure 7.6 1.6 0. the green line is the response of the pendulum’s angle while the blue line is the response of the cart’s angle.2 TIME(SEC) 1. .
78
7.3 PID Control Method
The implementation of PID control method is done by adjusting the value of gain K, Ki, and Kd in order to get the best impulse response of the system.
7.3.1 PID Control Method
This section discusses the results of the pendulum’s angle as the value of gain K, Kd, Ki changes. From Figure 7.4 and Figure 7.5, it can be seen that the graph of the pendulum’s angle are not stable. However by using the suitable value of gain K=100, Kd=20, Ki=1, the pendulum’s angle is satisfactorily achieved as shown in Figure 7.6
Figure 7.4: Impulse response for pendulum’s angle for K=1, Kd=1, Ki=1
79
Figure 7.5: Impulse response for pendulum’ angle for K=100, Kd=1, Ki=1
IMPULSE RESPONSE PID CONTROL (K=100,Kd=20,ki=1) 0.2
0.15
0.1
X: 0.04 Y: 0.0417 X: 0.04 Y: 0.0417
0.05 AMPLITUDE
0
0.05
0.1
0.15
0.2 0 0.2 0.4 0.6 0.8 1 1.2 TIME (SEC) 1.4 1.6 1.8 2
Figure 7.6: Impulse response for pendulum’ angle for K=100, Kd=20, Ki=1
80
7.3.2 Cart’s Position
It is found that the pole/zero at the origin cancelled out of the transfer function for have been put back in for the closed loop transfer function of cart’s
position to the impulse input. So, denl = den2, and it is making calculations easier.
From Figure 7.7, it can be seen that the cart moves in the negative direction with a constant velocity. So although the PID controller stabilizes the angle of the pendulum, this control method would not be feasible to be implemented on an actual physical system that was presented of cart's position and pendulum's angle as the outputs of the system.
PID Controller
IMPULSE RESPONSE 0.1
0
0.1 POSITION OF CART
0.2
0.3
0.4
0.5
0.6 0 0.5 1 1.5 2 2.5 TIME (SEC) 3 3.5 4 4.5 5
Figure 7.7: Impulse response of cart’s position for K=100, Kd=20, Ki=1
The parameter values inside the PID controller 2 block are (P=0.7.9 respectively.3 Pendulum's Angle and Cart's Position Since one PID controller could not stabilize both of the angle and the position of the pendulum and the cart. the PID controller 1 controls the angle of the pendulum while the PID controller 2 controls the position of the cart. For the PID controller 1.81 7.3. .10 D=0. the parameter values inside the block are (P=50. By using the Ziegler and Nichols method. another PID controller is applied to the diagram as discussed in Chapter 3. the parameters of both PID controllers were determined successfully. I=.5).3). As stated in chapter III.8 and Figure 7. I=. The output responses of the system (angle and position) are shown in Figure 7.110 D=3.0001. The analysis of the output responses will be discussed in section 7.
08 108 Y : 0 .8 POSITION 0.4 .392 5 TIM E (S E C ) 6 7 8 9 10 Figure 7.5 Y=0.0 0 3 0.98 Y=0.02 2 Y : 0 .02059 Y=0.003 : 1.4 8 0 3 0. Ki=110 S TE P R E S P O N S E (P O S ITIO N ) 1.0 2 0 5 9 X : 8 0X=8.0001037 1 1 .3 9 2 3 4 Y=4.0 0 0 1 0 3 7 0 .48 Y : .9: Impulse response for cart’s position for K=0.5 450 Y Y=1. 5 3 3 .4803 S TE P R E S P O N S E (A N G L E ) 0 X: 448 X=4. 5 4 1 X : 26 4 1 YX=1. 5 ANGLE 2 2 .2 1 X: 360 X=3.6 Y : 0 .5.98 X :X=4.3.0001. Kd=0.6 0.0 . 5 Y=0.8: Impulse response for pendulum’ angle for K=50. Ki=10 .4 0.64 : . Kd=3.82 X : X=1.2 0 0 1 2 3 4 5 TIM E (S E C ) 6 7 8 9 10 Figure 7.
From Figure 7.4 LQR Control Method 7.10. x and y. it can be seen that both the pendulum’s angle and cart’s position satisfy the design requirement.1 Pendulum's Angle and Cart's Position Using statespace methods it is relatively simple to work with a multioutput system.83 7. The input weighting R will remain at 1. x is used to weight the cart's position and y is used to weight the pendulum's angle. There are two weighting elements for the Q matrix. it was determined that the controller could be tuned by changing the nonzero elements in the Q matrix to get a desirable response. a controller is designed with both the pendulum's angle and the cart's position consideration. so in this section. . From the previous LQR design. The K matrix was found and the response has been plotted all in one step so any changes could be made in the control and be seen automatically in the response.4. Therefore the consideration of cart's position is combined with the pendulum's angle part into a single section.
the response can be improved even more. As mentioned in the Chapter 4. Now. Therefore.4594 The Figure 7.6854 3. the steadystate error will be eliminated. It can be noted that even if the x and y are given higher.6567 18. Nbar( N ) after the reference.0000 1. the result is shown in Figure 7. But.10: Step response with LQR control for x=5000 and y=100 The following is the value for K: K = 1. using these values (x=5000 and y=100).10 is the best result or response (with x=5000 and y=l00) for this problem. its response are satisfied the design requirements while keeping x and y as small as possible.84 Figure 7. it was done by adding a constant gain.11 .
which most likely will not be a valid assumption. the controllaw design has been combined with this estimator design to be as a compensator. but it was found by assuming fullstate feedback.4594 .6854 3. Therefore.11: Step response with LQR and Nbar control for x=5000 and y= 100 Nbar = 70. It is needed to use an estimator to estimate those states. The best result is obtained as shown in Figure 7. It is found that the system is not observable because the rank shown is three.0000 1.7107 The steadystate error is within the limits. The response is good. the rise and settling times are met the desired requirements and the pendulum's overshoot is within range of the design criteria.85 Figure 7. not exactly four.6567 18.12 with K value: K = 1.
86
Figure 7.12: Step response with estimator for x=6000 and y=200
All of the design requirements have been met with the minimum amount of control effort, so no more iteration is needed. Therefore, LQR statespace method is better control method to control a multioutput system than the PID.
87
7.5 Fuzzy Logic Controller Control Method
7.5.1 Pendulum's Angle and Cart's Position
As discussed in Chapter 5, four inputs have been applied to the FLC. The FLC was divided into two FLC’s so that each FLC can receive two inputs from the system. The output of each of the FLC were summed up together to produce the equivalent force. This force was fired as the input to the system. Figure 7.13 and Figure 7.14 show the output responses (angle and position) of the pendulum and cart respectively. The analysis of the responses will be discussed in section 7.7.
S T E P R E S P O N S E (A N G L E )
X: 153 Y : 2 0 .2 2
20
X=1.53 Y=20.22
15
10
5 ANGLE
X: 828 Y : 0 .0 3 6
0
X=8.28 Y=0.036
5
1 0
1 5
2 0 1 2 3
X: 213 Y :  1 9 .5 2 4
X=2.13 Y=19.52
5 6 T IM E (S E C )
7
8
1
Figure 7.13: Impulse response for pendulum’s angle
88
S TE P RE S P O N S E (P O S ITIO N )
X: 302 X=3.02 Y : 1.036
Y=1.036
X: 489 X=4.89 Y : 1.02 Y=1.02
X=9.23 X: 923 Y : 1.011 Y=1.011
1
0.8
POSITION
0.6
0.4
0.2
0 0 1 2 3 4 5 TIM E (S E C) 6 7 8 9 10
Figure 7.14: Impulse response for cart’s position
7.6 Artificial Neural Network Control Method
In this section, the training and simulation results are shown. Recall that the control objective is to keep the pendulum in its up right position and the cart in the specified position. Using the backpropagation learning algorithm with one output layer and one input layer, the following training responses for the position and angle were achieved.
2 0 1 2 3 4 5 T IM E ( S E C ) 6 7 8 9 Figure 7.16 output training response for the pendulum’s angle and cart’s position were satisfactorily achieved.16: Training output response of pendulum’s angle . T R A IN IN G O U T P U T R E S P O N S E ( P O S IT IO N ) 1 .4 0 . However. an improvement of the training should be done so that both desired and actual response is coincidence each other.15 and Figure 7.15: Training output response of cart’s position T R A IN IN G O U T P U T R E S P O N S E ( A N G L E ) 16 14 12 10 ANGLE 8 6 4 2 0 0 100 200 300 400 T IM E ( S E C ) 500 600 700 800 Figure 7. for the sake of accuracy.6 0 .2 1 0 .8 POSITION 0 .89 As can be seen from the Figure 7.
5 3 3 . Figure 7.17: System output response of cart’s position S TE P R E S P O N S E (A N G L E ) 10 8 6 4 ANGLE (DEGREE) 2 0 2 4 6 8 1 0 0 10 20 30 40 50 T IM E ( S E C ) 60 0 10 20 30 Figure 7.90 Applying the mfile command into matlab.5 R E S P O N S E ( P O S IT IO N ) 0 10 20 30 40 T IM E 50 (S E C ) 60 0 10 20 Figure 7.17 and Figure 7. S TE P 1 .5 0 0 . an ANN controller block would be generated.18 show the system output response of cart’s position and the system output response of pendulum’s angle respectively. The block was exported into simulink diagram so that the simulation could be operated and the system response could be analyzed.18: System output response of pendulum’s angle .5 2 2 .5 1 0 .5 POSITION (m) 1 1 .
the red dotted line represents the cart’s position using the LQR controller.7 Comparative Assessment and Analysis of the Response In the previous chapter. it can be seen that the response goes down to infinity. It does not settle down to zero which again makes the system unstable. 7. For the pendulum’s angle response in Figure 7. .91 For the cart’s angle response Figure 7.19 shows the overall step responses of the cart’s position (meter) versus the time (second) are compared. it can be seen that the response oscillates within 10 to 10 degrees.18. blue dotted line represents cart’s position using PID controller and the solid green line represents cart’s position using fuzzy controller. three controllers were successfully designed. Notice that there are many differences between the characteristics of the responses.17. Therefore. Some modifications need to be done especially for the cart’s position controller. In this section. the system is not stable system. This could be concluded that the ANN controller design is not satisfactorily achieved as required by the design criteria. Figure 7. As can be seen.1. all the results of the controllers will be discussed. All the characteristics values of the responses are summarized in Table 7.
(Ts) of 2.8 0.0366 seconds while fuzzy has the largest value of settling time.1 summarized the comparison of output response of cart’s position. LQR also has the smallest value of settling time. it can be clearly seen the difference of the characteristics between the responses. The last characteristic is the steady state error.91 seconds.6 POSITION 0.2 0 0 . 4 0 1 2 3 4 T IM E (S E C ) 5 6 7 Figure 7. it can be stated that the LQR controller has the ability to response quickly compared to PID and Fuzzy controllers. 2 LQ R P ID F U ZZY 0 . (Ts) of 4. Among three controllers.19: Comparison of output response of cart’s position Table 7.57 %. Fuzzy is the only controller that has the steady state error (ess) of 0. In addition.50 seconds while the LQR controller has the slowest rising time (Tr) of 0. From this table. From both of these characteristics.01. (ess). For the overshoot percentage (%OS). PID has the fastest rising time (Tr) of 1.4 0.4121 seconds. .92 S T E P R E S P O N S E (P O S IT IO N ) 1 0. LQR does not has overshoot while the fuzzy controller has the largest overshoot percentage of 2.
.01 Comparing all the characteristics from Table 7.93 Table 7. LQR controller has the best performance among three controllers.91 s OVERSHOOT PERCENTAGE (%OS) 0.1.59 s 2.57 % STEADY STATE ERROR (ess) 0 0 0. all the characteristics have fulfilled the design criteria that were initially fixed. In fact.41 s 0.50 s 0.95 s SETTLING TIME (Ts) 3.04 s 4.1: Comparison of output response of cart’s position Controller PID Characteristics LQR FUZZY RISING TIME (Tr) 1.32 % 0% 2.
59 4. All the values in the bar chart are the same as in Table 7.32 0.5 4 3.5 0.5 3 2.41 2.95 3.94 Figure 7. 5 4.20: Output response of cart’s position .1.04 1.5 1 0.20 shows the comparison of the response of the cart’s position between PID. LQR and Fuzzy controllers in bar chart form.00 0.5 0 PERCENT OVERSHOOT RISING TIME 0.91 SETTLING TIME PID LQR FUZZY Figure 7.5 2 1.57 2.
21: Comparison of output response of pendulum’s angle .21 shows the overall output responses of the pendulum’s angle (degree) versus time (second) between the PID. All the characteristic values of the responses were summarized in Table 7. all the responses finally settled down to zero which stable the pendulum vertically upright position. As could be seen.2 S T E P R E S P O N S E (A N G L E ) 20 10 0 ANGLE 1 0 2 0 3 0 LQ R 4 0 P ID F U ZZY 0 1 2 3 4 T IM E ( S E C ) 5 6 7 Figure 7.95 Figure 7. LQR and Fuzzy controllers.
.82 s MAXIMUM OVERSHOOT RANGE 0. for the maximum overshoot range.52 ° STEADY STATE ERROR (ess) 0 0 0. However.46. LQR has the fastest settling time of 3. LQR controller has the best response and better performance which satisfy the design criteria very much. only fuzzy controller has the steady state error of 0. However. for the overall performance by considering both pendulum’s angle and cart’s position. PID controller has the best response for controlling the pendulum’s angle compared to Fuzzy and LQR.96 Table 7.48 s 3.34 seconds while fuzzy has the slowest settling time of 4. Finally.47 ° 20.50 ° 4.2.82 seconds. Both of the fuzzy and LQR controllers have exceeded the maximum range of 20 degrees.34 s 4.03 Based on the Table 7.2: Comparison of output response of pendulum’s angle Controller PID Characteristics LQR FUZZY SETTLING TIME (Ts) 4.03.57° .39 ° 19.22 ° 19. PID controller has the best range which is the lowest range among the three controllers. Based on this table. the last characteristic.
From the analysis.97 7. Two tasks are involved in controlling the inverted pendulum system which is the pendulum’s angle and cart’s position.8 Discussion The main objective of this project is to design Artificial Intelligence controller such as FLC and ANN. the block diagram of the system in Figure 3. The values of x and y have been used to describe the relative weight of the tracking error in the cart's . The best response is obtained by using the LQR control method. Both of these AI controllers will be compared to the Conventional controller such as PID and LQR controllers to see the performance of the controller in order to control an inverted pendulum system. The results displayed that the cart moves in the negative direction with a constant velocity when an impulse force is applied to move it. Another PID controller was added to the system so that two PID controllers could control both outputs such the angle and the position as discussed in section 3.4 was modified into the diagram shown in Figure 3. the PID alone cannot be used successfully to control the cart's pendulum and pendulum's angle simultaneously. So.5. However. this design would not be feasible to implement on an actual physical system due to its uncontrollability of cart's position.4. it was found that the PID controller is a good controller to control the singleinputsingleoutput (SISO) system. the system is successfully stabilized. The controlling of the inverted pendulum is implemented by using PID control method. By using this approach. although the PID controller stabilizes the angle of the pendulum. It was found that LQR statespace method is the best control method to control a multioutput system compared to the other methods described previously. All of the characteristics for the both responses of the system are met design criteria satisfactorily. Because of this reason.
FLC requires some numerical parameters in order to operate such as what is considered significant error and significant rateofchangeoferror. Since the AI controller can control the multi input – multi output system.98 position and pendulum's angle versus the control effort. the rise and settling times are met the design criteria and the pendulum's overshoot is within range specified. the steadystate error is reduced. different method will be done to control the cart’s position and the pendulum’s angle. As discussed in Chapter 5. A lot of parameters were needed to be changed. In this approach. In this case. but exact values of these numbers are not critical unless very responsive performance is required in which case empirical tuning would determine them. this controller is assumed to be practically done in real time application. For the fuzzy logic controller and the artificial neural network controller. This response was transform into fuzzy rules using the following formula: e( k ) r (k ) y (k ) e( k ) e(k ) e(k 1) . two parameters gave a major effect of the response. Then by adding a reference input. By applying a designed estimator and a combination of the controllaw design and estimator design as a compensator. This problem was solved by applying the standard fuzzy rules generated from the under damped response curve. First was the scale of the membership function or the universe of discourse. However the tuning process was the difficult part to do. the nonlinear system of inverted pendulum will be controlled. FLC incorporates a simple rulebased IF X AND Y THEN Z approach to a solving control problem rather than attempting to model a system mathematically. and the second parameter was the fuzzy rules. it is determined that all of the design requirements were met successfully.
ANN was discussed in detail.1. It was involved the identification. the design criteria were successfully satisfied.5 were determined. From the characteristics of both responses. After doing the parameter tuning and operating the fuzzy controllers. However when it goes to the control part. training and control approaches. the response are not successfully stabilized. One encountered difficulty is how to guarantee generalization and to determine when the network is sufficiently trained. There were several constraints and problems in designing the ANN controller which has been discussed in section 6. the diagram was simulated. In this project. adaptivity and fault tolerance. inputoutput mapping. the identification and training parts were satisfactorily achieved. One of the most interesting features of NNs is their learning ability. In Chapter VI.4 and Table 5.99 Then. the rules as summarized in Table 5.9. Implementing neural network for control is not easy task to do. Neural networks offer nonlinearity. . This is achieved by presenting a training set of different examples to the network and using learning algorithms. which changes the weights (or parameters of activation functions) in such a way that the network will reproduce a correct output with the correct input values.
Simulation results show that LQR controller has better performance compared to PID in controlling the linear system. All the successfully design controller were compared. The responses of each controller were plotted in one window and summarized in table. The PID control approach that was proposed in the reference number [10] was modified and solved successfully. New control approach of the fuzzy logic is capable of controlling the inverted pendulum's angle and the cart's position of the nonlinear system.100 CHAPTER VIII CONCLUSION & SUGGESTION 8. FLC could stabilize the system with some limitation as discussed in the previous chapter.1 Conclusion From the early discussion. The response characteristics have satisfied the design criteria. . it can be concluded that both of control methods of the conventional controllers (PID and LQR) are capable of controlling the inverted pendulum's angle and the cart's position of the linearized system.
Each controller provide three types of input such as step input. it is expected that the FLC will work well if it is .1. and user define input.101 Finally.1: Graphical User Interface front panel of Inverted Pendulum System 8. Since FLC could stabilize the nonlinear system. the user can operate and simulate the system as well as the output response. By clicking one of the buttons. As can be seen from the figure. The front panel of the GUI is shown in Figure 8. GUI for Inverted Pendulum system is successfully designed.2 Suggestion for the Future Work Although the controllers has been successfully stabilized the system. Figure 8. square wave input. implementation of the algorithm into real hardware is very important. four controllers button has been provided.
The neural network controller also should be designed based on the input training signal that is successfully achieved. AI controller technique should be improved so that a robust controller and a better response can be achieved. The limitation in a FLC design should be eliminated. further work for the proposed approaches will have great advantage. . Therefore. A lot of techniques can be figure out from the previous paper and research that were successfully done.102 implemented into real system.
Maeda. “Learning Control of an Inverted Pendulum Using a Neural Network”. Hornik and M. University of Ryukyus. Kumamoto University. N. La Lolla. “Fuzzy Logic Controller for an Inverted Pendulum System” [5] Tsutomu Ishida. Computer Science Department. Tsutomu Nagado.103 REFERENCES [1] K. November 27. Fang Lei. T. “Fuzzy Logic Controller for an Inverted Pendulum System” Faculty of Science and Technology. CA.Okinawa Japan [6] S. San Diego.K [3] Chen Wei Ji Fang Lei Lei Kam Kin. Japan [7] Charles W. U. Naofumi Shiokawa. Rensselaer Polytechnic Institute.31. Stinchcombe and H. 2001 . Department of Encomics. “Learning to Control an Inverted Pendulum Using Neural Networks” [8] Lawrence Bush. University of California. 1988 [2] NOVAK V. University of Macau [4] Chen Wei Ji. Troy New York. Matsunaga. “Fuzzy Sets and Their Applications “Adam Hilger Imprint by IOP Publishing Ltd. London. Lei Kam Kin. Fuzzy Logic Controller for the Inverted Pendulum Problem. Anderson. Kawaji. I997 IEEE International Conference on Intelligent Processing System October 28 ..White. “Learning Control of an Inverted Pendulum Using a Neural Network”. “Multilayer FeedForward Networks Are Universal Approximators”. 1986.
University of Michigan www. Middle East Technical University: Master's Thesis [13]Malcolm Jeffers (2001) “A Genetic Algorithm based Fuzzy Logic Controller”.umich. “Learning to Balance the Inverted Pendulum using Neural Network”.seattlerobotics.html#WHAT%20IS%20F UZZY%20LOGIC? [12] Mehmet Emin ARI (1995) “Stabilization of an Inverted Pendulum by Using a Fuzzy Controller”. Dublin City University .engin. Kitakushu Japan [10] Carnegie Mellon.104 [9] Victor Williams.org/encoder/mar98/fuz/fl_part1.edu/group/ctm/examples [11] http://www. Kiyotoshi Matsuoka.
end mz=length(long)length(short).5.1818 4.3. 9.2.0000 0 0. 0.5455 den = 1.1. 0.poly2) %Copyright 1996 Justin Shriver %polyadd(poly1. %simplifies input q = (M+m)*(i+m*l^2)(m*l)^2. else poly=long+short.poly2) adds two polynominals possibly of uneven length if length(poly1)<length(poly2) short=poly1. long=poly2.4545 A1: Matlab command to find open loop transfer function of the system function[poly]=polyadd(poly1.short]+long. 0. if mz>0 poly=[zeros(1.006. 0. end A2: Matlab command for Polyadd function .8.1818 31.mz). else short=poly2.105 APPENDICES M m b i g l = = = = = = . num = [m*l/q 0] den = [1 b*(i+m*l^2)/q (M+m)*m*g*l/q b*m*g*l/q] Output should be: num = 4. long=poly1.
denPID = [1 0]. numc = conv(num2. 0.denPID).2. k = 100. impulse(numc. den1 = [1 b*(i+m*l^2)/q 0]. 0. t=0:0.num1)).denc.8. num1 = [m*l/q 0 0]. %simplifies input q = (M+m)*(i+m*l^2)(m*l)^2. 9.t) A4: PID control method for cart’s position .3.01:5. ki = 1. denc = polyadd(conv(denPID. 0. denPID = [1 0]. 0.1. numc = conv(num. k = 1. ki = 1.denc.5.t) axis([0 1. num2 = [(i+m*l^2)/q den2 = den1 kd = 20. 0 (M+m)*m*g*l/q b*m*g*l/q m*g*l/q].den2).006.conv(numPID.den).01:5.conv(numPID.num)) t=0:0.denPID) denc = polyadd(conv(denPID.5 0 40]) A3: PID control method for pendulum’s angle M m b i g l = = = = = = .106 kd = 1. numPID = [kd k ki]. numPID = [kd k ki]. impulse(numc.
0]. 0 0 1 0]. 0 (i+m*l^2)*b/p (m^2*g*l^2)/p 0. (i+m*l^2)/p. U=0.X]=lsim(Ac.8. 0.2*ones(size(T)). 0. %denominator [0 1 0 0. 0.107 M m b i g l p A 0. m*l/p]. p = eig(A) C'*C x=1.R) Ac = [(AB*K)].3. 0. plot(T.1. = = = = = = = = y=1 R = 1.2. 0 (m*l*b)/p m*g*l*(M+m)/p 0].006.U. D = [0. T=0:0. i*(M+m)+M*m*l^2.T).5.Dc.01:5.Y) legend('Cart'. K = lqr(A. Bc = [B]. 0.'Pendulum') A5: Matlab command for LQR design . [Y.B. 9. C = [1 0 0 0.Q. Cc = [C].Bc. 0 0 0 1.Cc. B = [0. Dc = [D].
place(A'.B.X] = lsim(Ace.Cce. [Y.Dc.Y) legend('Cart'.0.U. plot(T.Cc.01:5.2*ones(size(T)).'Pendulum') p = P = L = Ace A7: Matlab command to design a FullOrder Estimator . [Y.Y) legend('Cart'. U = 0. T = 0:0.C'. Dce = [0. zeros(size(B))].X]=lsim(Ac. Nbar=rscale(A.T). Bce = [ B*Nbar.'Pendulum') A6: Matlab command for adding the reference input eig(Ac) [40 41 42 43]. Cce = [Cc zeros(size(Cc))].0].Cn.Bce.K) Bcn=[Nbar*B].Bcn.U. plot(T. zeros(size(A)) (AL*C)].Dce.T).P)' = [AB*K B*K.108 Cn=[1 0 0 0].
This action might not be possible to undo. Are you sure you want to continue?