Professional Documents
Culture Documents
PENDULUM SYSTEM
SESI PENGAJ
IAN:
2006/2007
Saya
AHMAD NOR KASRUDDIN IBN NASIR
(HURUF E
BSAR)
TIDAK TERHAD
Disahkan oleh
Alamat Tetap:
496 (F) KERATONG SATU
A
B NDAR TUN ABDUL RAZAK P.M DR. MOHD FUA’AD B
IN HJ.RAHMAT
26900 PAHANG DARUL MAKMUR Nama Penyelia
Signature : …………………………………….
Supervisor’s Name: ASSOC. PROF. DR. MOHD FUA’AD BIN HJ. RAHMAT
Date : 30th APRIL 2007
MODELING AND CONTROLLER DESIGN FOR AN INVERTED PENDULUM
SYSTEM
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 :AHMAD NOR KASRUDDIN BIN NASIR
Date :30 th APRIL, 2007
iii
ACKNOWLEDGEMENT
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.
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. proportional-integral-derivative
(PID), linear quadratic regulator (LQR) for controlling the linear system of inverted
pendulum and fuzzy logic controller (FLC) for controlling the non-linear 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
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
REFERENCES 103
Appendices 105-108
xi
LIST OF TABLES
LIST OF FIGURES
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 3 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
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
T - 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
LIST OF APPENDICES
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 air-flow, stabilization of a cabin in a ship etc. To solve
such problem with non-linear time variant system, there are alternatives such as real
time computer simulation of these equations or linearization.
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 Proportional-Integral-Derivative (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]
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.
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
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
Literature Review
Mathematical Model
Design Requirement
Transfer function
State-Space Form
Controller Design
Conventional Artificial Intelligence
Evaluate Performance
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 state-space
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 state-space 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 state-space 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
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, Ts, is to be less than five seconds. Ts < 5secs
2. The system overshoot value is to be at most 22.5%. os < 22.5%
To get rid of the P and N terms in the equation above, sum the moments around the
centroid of the pendulum
Since Matlab can only work with linear functions, this set of equations should be
linearized about T = S . Assume that T = S + ø (ø represents a small angle from the
dT
vertical upward direction). Therefore, cos ( T ) = -1, sin ( T ) = -ø, and = 0.
(dt ) 2
After linearization the two equations of motion become (where u represents the
input):
( M m) X ( s ) s 2 bX ( s) s mlI ( s ) s 2 U ( s) (2.10)
Since the angle ø is the output of interest, solving equation 2.9 for X(s),
13
2
ª ( I ml ) g º
X (s) « 2 »I ( s ) (2.11)
¬ ml s ¼
ª (I ml2 ) g º 2 ª (I ml2 ) g º
(M m)« »I(s)s b« »I(s)s mlI(s)s 2 U (s) (2.12)
¬ ml s¼ ¬ ml s¼
ml 2
s
)(s) q
(2.13)
U (s) b( I ml 2 ) 3 ( M m)mgl 2 bmgl
s4 s s s
q q 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
ml
s
)( s) q
(2.14)
U ( s) b( I ml 2 ) 2 ( M m)mgl bmgl
s3 s s
q q q
)( s) 4.5455s
3 2
(2.15)
U ( s) s 0.1818s 31.1818s 4.4545
Solving for the transfer function of the position, the following equation 2.16 will be
derived
X ( s) 1.8182s 44.5455
(2.16)
U (s) s 0.1818s 2 31.1818s 4.4545
3
14
2.2.2 State-Space
ª0 1 0 0º
ª x(t)º « (I ml2 )b m2 gl 2 »ªx(t)º
«x(t)» «0 0»« »
2
I (M m) Mml2 x(t)
« » « I (M m) Mml »« » (2.17)
«I(t)» «0 0 0 1»«I(t)»
« » mlb mgl(M m) « »
¬I (t)¼
«0 0»¬I(t)¼
« I (M m) Mml2 I (M m) Mml2 »
¬ ¼
ª 0 º
« I ml 2 »
« I ( M m) Mml 2 »
« »u (t )
« 0 »
« ml »
«¬ I ( M m) Mml 2 »¼
Substituting all the parameter values into the equation 2.17 yielding equation 2.18
and equation 2.19
ª x (t ) º ª0 1 0 0º ª x(t ) º ª 0 º
« x(t ) »
« »
«0 0.1818 2.6727
« 0»» «« x (t ) »» ««1.8182 »»
u (t ) (2.18)
«I(t ) » «0 0 0 1» «I (t )» « 0 »
« » « »« » « »
¬I (t )¼ ¬0 0.4545 31.1818 0¼ ¬I(t )¼ ¬4.5455¼
ª x(t ) º
« »
ª1 0 0 0º « x (t ) » ª0º
y (t ) «0 0 1 0» «I (t )» «0»u (t ) (2.19)
¬ ¼ ¬ ¼
« »
¬I (t ) ¼
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 state-space design, a multi-output 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
An m-file, 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 m-file names must
end with the extension '.m' (e.g. plot.m). By creating a new m-file with the same
name as an existing m-file, 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.
Current
i
+
-
Current Voltage
Z source Scope
Measurement
?
Conti nuous
Double click here for detai ls
CHAPTER III
PID CONTROLLER
3.1 Introduction
Tuning of a PID involves the adjustment of Kp, Ki, and Kd to achieve some user-
defined "optimal" character of system response.
ml 2
s
)(s) q
(3.1)
U (s) b( I ml 2 ) 3 ( M m)mgl 2 bmgl
s4 s s s
q q q
where,
q [( M m)( I ml 2 ) (ml ) 2 ]
PLANT 1 X (s )
G2(S)
f(s)=F
+ T (s)
PID PLANT 1
r(s)=0 ¦ e(s) CONTROLLER + ¦ u(s)
G1(S)
+
-
T (s)
Figure 3.1: The schematic diagram for the closed-loop 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 closed-loop 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 closed-loop transfer function of the diagram can be found as shown by
the equation 3.2.
num
G ( s) den
y ( s) F (s) (3.2)
1 KD ( s )G ( s ) k (numPID)(num)
1
(denPID)(den)
num(denPID)
F ( s)
(denPID)(den) k (numPID)(num)
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
Rearranging the block diagram above, a simpler block diagram of inverted pendulum
system is produced as shown in Figure 3.4.
where,
X(s) = cart's position signal; e (s) = pendulum's angle signal
G(s) = pendulum's angle; 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.
num2
G 2( s ) den2
X ( s) F ( s) (3.3)
1 KD ( s )G1( s ) k (numPID)(num1)
1
(denPID)(den1)
24
(num2)(denPID)(den1)
X ( s) F ( s) (3.4)
(denPID)(den1)(den2) k (numPID)(num1)(den2)
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.
(num2)(denPID)
X (s) (3.5)
(denPID)(den) k (numPID)(num1)
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.
( I ml 2 ) 2 mgl
s
X (s) q q
2
(3.6)
U (s) b( I ml ) 2 ( M m)mgl bmgl
s3 s s
q q q
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
Zero Angle
PID
Controller 1 I (s)
+ (Angle)
-
Figure 3.5: Schematic diagram of the inverted pendulum system with two PID
controllers
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
Step1
animcp
Manual
Switch Animation
Mux
Target Position Switch
Constant 1
Mux
Target Position
-0.65357
(Mouse-Driven)
teta1
x
PID In1
x1
PID Controller2
Subsystem
R2D
PID
Radians
PID Controller1 to Degrees
Figure 3.6: Schematic diagram of the inverted pendulum system with two PID
controllers in Simulink
3.5 Conclusion
CHAPTER IV
4.1 Introduction
The model of inverted pendulum system can be represented in state space as shown
in equation 4.1.
ª x (t ) º ª0 1 0 0º ª x(t ) º ª 0 º
« x(t ) » «0 0.1818 2.6727 0»» «« x (t ) »» ««1.8182 »»
« » « u (t )
«I(t ) » «0 0 0 1» «I (t )» « 0 »
« » « »« » « »
¬I (t )¼ ¬0 0.4545 31.1818 0¼ ¬I(t )¼ ¬4.5455¼
(4.1)
ª x(t ) º
« »
ª1 0 0 0º « x (t ) » ª0º
y (t ) «0 0 1 0» «I (t )» «0»u (t )
¬ ¼ ¬ ¼
« »
¬I (t ) ¼
The design criteria for this system with the cart receiving a step input are as follows:
For the PID controller, two controllers are needed to control both the carts’ position
and pendulum’s angle simultaneously. Using state-space method, it is relatively
simple to work with a multi-output 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.
y
R
+ x(t) Ax(t) By(t)
- y(t) Cx(t)
x
K
where,
In this problem, R represents the commanded step input to the cart. The four states,
( x, x , I , I ) 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
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 open-loop poles of the
system. The Matlab command of this step can be referred to the Appendix A5. There
is one right-half-plane pole at 5.57. This proved that the system is unstable in open
loop.
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 closed-loop 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 column-l, row-1) will be used to
weight the cart's position and the element in the (3, 3) position (i.e. at column-3, 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 m-file 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 (Tr) needs to go down. This error will be dealt
with in the next section by adding a reference input to the system block diagram.
In contrast to the other design methods, where the output is feedback and
compared to the reference input to compute an error, with a full-state feedback
controller, all the states are feedback so that it can be multiplied with the K matrix.
33
It is required to compute the steady-state 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.
y
R N + x Ax By
- y Cx
K x
*
Nbar,( N ) can be found using the user-defined function rscale. This function
is not a standard function provided in the Matlab control system toolbox. This
function is built in m-file code as shown in Appendix A6. In order to use rscale
function, the m-file 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 m-file 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 steady-state error is within limit, the rise and settling times are met
and the pendulum's overshoot is within range of the design criteria.
This response can be consider as a good response, but was found assuming
full-state feedback, which most likely will not be a valid assumption. To compensate
this problem, the next design is a full-order estimator to estimate those states that are
not measured. A schematic of this kind of system without Nbar is shown in Figure
4.3
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 m-file
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 m-file 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 control-law design and the
estimator design is proposed to get the compensator. The response should be similar
to the one from the control-law 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 m-file, 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
CHAPTER V
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 non-membership. This approach to set theory
was not applied to control systems until the 70's due to insufficient small-computer
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]
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.
REASONING WITH
FUZZY CONTROL RULES
FUZZIFY DEFUZZIFY
CONTROL SIGNAL
T
STABILISE AN F INVERTED
INVERTED PENDULUM PENDULUM IS
PENDULUM STABILISED
X
APPLY PID
LINEARISE CONTROLLER
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
The above expression can be simplified into another statement as shown in Figure
5.2.
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.
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
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 analogue-digital 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;
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.
The complete inference result yo is constructed from the w1B1 and w2B2,
B*=w1B1 w2B2
¦ B * ( y ) ydy
y0
¦ B * ( y )dy
(1) Calculate the compatibility for the inputs and antecedent of the rules
(3) Find the complete inference result as a weighted mean of the inference results for
each rule with respect to compatibility
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.
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.
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
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.
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 non-linear input-output 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.
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.
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.
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, hand-held
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 non-linearity, 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.
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 rules-based 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 rules-based
Define inference engine
Choose Defuzzification method
No
OK
Yes
End
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.
T
ªX º
«'X »
INVERTED « »
F «I »
PENDULUM « »
(NONLINEAR) ¬ 'I ¼
FLC
F
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
+
Reference (Control
position Position)
ǻx Position x
+
Force
ǻĮ + Angle
+ FLC 2 Į
(Control
Reference
- Angle)
Angle
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
FUZZY CONTROLLER
KNOWLEDGE
BASE
4 Inputs Mamdani
FUZZY FUZZY Sugeno
INFERENCE
FUZZIFIER ENGINE DEFUZZIFIER
Through observations the input and output fuzzy variables has been identified. This
is shown in Table 5.2.
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.
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
NB NM NS ZE PS PM PB
1
0.8
Degree of membership
0.6
0.4
0.2
-3 -2 -1 0 1 2 3
Position
NB NM NS ZE PS PM PB
1
0.8
Degree of membership
0.6
0.4
0.2
-3 -2 -1 0 1 2 3
Del-position
NB NM NS ZE PS PM PB
1
0.8
Degree of membership
0.6
0.4
0.2
-10 -8 -6 -4 -2 0 2 4 6 8 10
Force
Membership functions for each of the fuzzy subsets of the control angle FLC:
NB NM NS ZE PS PM PB
1
0.8
Degree of membership
0.6
0.4
0.2
-0.25 -0.2 -0.15 -0.1 -0.05 0 0.05 0.1 0.15 0.2 0.25
Angle
NB NM NS ZE PS PM PB
1
0.8
Degree of membership
0.6
0.4
0.2
NB NM NS ZE PS PM PB
1
0.8
Degree of membership
0.6
0.4
0.2
-10 -8 -6 -4 -2 0 2 4 6 8 10
Force
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.
NS NS NS PS
ZE NB NM NS ZE PS PM PB
PS NS PS PS
PM NM NS PS PS
PB NB NM NS PS PS PM
NS NS NS PS
ZE NB NM NS ZE PS PM PB
PS NS PS PS
PM NM NS PS PS
PB NB NM NS PS PS PM
60
5.6.4 Implementation in Simulink
Step1
animcp
Manual
Switch Animation
Mux
Target Position Switch
Constant 1
Mux simout1
Target Position
-0.675
(Mouse-Driven)
position
xdot
R2D
.94 Mux
Radians
Gain to Degrees
Fuzzy Logic
Controller
(Position)
Total
Force
simout
1 Mux
angle
Gain1
Fuzzy Logic
Controller
(Angle)
tetadot
Figure 5.19: Schematic diagram of the Nonlinear Inverted Pendulum system with
two FLC controllers in Simulink
62
5.6 Conclusion
CHAPTER VI
6.1 Introduction
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
non-linearity, input-output mapping, adaptivity and fault tolerance. Non-linearity is
a desired property if the generator of the input signal is inherently non-linear [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.
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
There are three main types of ANN structures -single layer feedforward
network, multi-layer 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
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 multi-layer networks powerful in
representing nonlinear functions. [5]
ARCHITECTURE
x
u x
I
I
DESIRED
ADJUST WEIGHT LEARNING RESPONSE
ALGORITHM
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
System with NN
x
SYSTEM I/P u INVERTED x SYSTEM O/P
PENDULUM I
I
NEURAL NETWORK
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.
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 m-file. 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
S te p 1
a n im cp
M anual
S w i tc h A n i m a ti o n
M ux
T a rg e t P o si t i o n 1 S w i tc h
C o n st a n t
T a rg e t P o si t i o n
-0 . 6 7 5
(M o u se -D ri v e n )
R2D
1 .5 Ra d ia n s
t o D e g re e s S co p e
G a in
n o n l i n e a r i n v e rt e d p e n d u l u m si m o u t
S a t u ra t i o n 3 T o W o rksp a c e
S a t u ra t i o n
S a t u ra t i o n 1
y {1 } p {1 } 0 .9 4
te ta
G a in 1
N e u ra l N e t w o rk2
T o W o rksp a c e 1
0 .8
G a in 4
te ta d o t
T o W o rksp a c e 2
G a in 3 x
10
T o W o rksp a c e 3
xd o t
y {1 } p {1 } 0 .5
T o W o rksp a c e 4
G a in 2 S a t u ra t i o n 2
N e u ra l N e t w o rk1
T o W o rksp a c e 5
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
Feedforward Architecture
ANN Model All signals flow in one direction only,
i.e. from lower layers (input) to upper layers (output)
The Back propagation learning
Most popular learning algorithm.
Learning Rule
The net simply propagates the pattern inputs to outputs to
produce its own patterns
Activation Tan-Sigmoid (Hidden Layer)
Function Linear Function (Output Layer)
Supervised learning:
Learning Learning with teacher signals or targets
Algorithm in Produce its own output pattern and then compares this
ANNs with the desired output.
The difference is the error
One hidden layer is suitable for the purpose of
identification.
Hornik and indeed other researchers have shown that even
2 Layers
a two-layer 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:
6.10 Conclusion
CHAPTER VII
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.
50
40
AMPLITUDE
30
20
10
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
TIME (SEC)
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
Pendulum's Angle
Cart's Position
90
80
70
60
AMPLITUDE
50
40
30
20
10
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
TIME(SEC)
Figure 7.3: Impulse response for pendulum’ angle and cart’s position using
state-space
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
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.
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
0.05 X: 0.04
AMPLITUDE
Y: 0.0417
0
-0.05
-0.1
-0.15
-0.2
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
TIME (SEC)
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 I 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.1
POSITION OF CART
-0.2
-0.3
-0.4
-0.5
-0.6
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
TIME (SEC)
Figure 7.7: Impulse response of cart’s position for K=100, Kd=20, Ki=1
81
7.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 pendulum and the cart, another PID controller is applied to the diagram as
discussed in Chapter 3.
By using the Ziegler and Nichols method, the parameters of both PID
controllers 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
X : X=1.08
108
Y : 0 .4 8 0 3 S TE P R E S P O N S E (A N G L E )
0.5 Y=0.4803
0
X: 448 X : 8 0X=8.02
2
X=4.48 Y : 0 .0 0 0 1 0 3 7
Y : - 0 .0 2 0 5 9 Y=0.0001037
-0 . 5 Y=-0.02059
-1
ANGLE -1 . 5
-2
-2 . 5
-3
-3 . 5
-4
1 X: 2
164 3 4 5 6 7 8 9 10
YX=1.64
: - 4 .3 9 2
TIM E (S E C )
Y=-4.392
Figure 7.8: Impulse response for pendulum’ angle for K=-50, Kd=-3.5, Ki=-110
S TE P R E S P O N S E (P O S ITIO N )
1.2
1
X :X=4.5
450
XX=3.6
: 360
Y Y=1.003
: 1.0 0 3
Y : 0 .98
Y=0.98
0.8
0.6
POSITION
0.4
0.2
0 1 2 3 4 5 6 7 8 9 10
TIM E (S E C )
Figure 7.9: Impulse response for cart’s position for K=-0.0001, Kd=0.3, Ki=-10
83
7.4 LQR Control Method
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 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.
Figure 7.11: Step response with LQR and Nbar control for x=5000 and y= 100
Nbar = -70.7107
The steady-state 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.
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 state-space method is better
control method to control a multi-output system than the PID.
87
7.5 Fuzzy Logic Controller Control Method
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=1.53
X: 153
Y : 2 0 .2 2
Y=20.22
20
15
10
5
X=8.28
X: 828
ANGLE
Y : 0 .0 3 6
0
Y=0.036
-5
-1 0
-1 5
-2 0
X=2.13
X: 213
1 2 3 Y : - 1 9 .5 2 4 5 6 7 8 1
Y=-19.52 T IM E (S E C )
X: 302
X=3.02
Y : 1.036
X=9.23
X: 923
Y=1.036 Y=1.011
Y : 1.011
1
X: 489
X=4.89
Y : 1.02
Y=1.02
0.8
POSITION
0.6
0.4
0.2
0
0 1 2 3 4 5 6 7 8 9 10
TIM E (S E C)
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 back-propagation learning algorithm with one output
layer and one input layer, the following training responses for the position and angle
were achieved.
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.
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 .2
0 .8
POSITION
0 .6
0 .4
0 .2
0
1 2 3 4 5 6 7 8 9
T IM E ( S E C )
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
S TE P R E S P O N S E ( P O S IT IO N )
1 .5
0 .5
-0 .5
POSITION (m)
-1
-1 .5
-2
-2 .5
-3
-3 .5
0 10 20 30 40 50 60 0 10 20
T IM E (S E C )
S TE P R E S P O N S E (A N G L E )
10
4
ANGLE (DEGREE)
-2
-4
-6
-8
-1 0
0 10 20 30 40 50 60 0 10 20 30
T IM E ( S E C )
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.
0.8
0.6
POSITION
0.4
0.2
LQ R
-0 . 2
P ID
F U ZZY
-0 . 4
0 1 2 3 4 5 6 7
T IM E (S E C )
Controller
PID LQR FUZZY
Characteristics
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.
4.91
5
4.5
4 3.59
3.5
3 2.57
2.5 2.04
2 1.5
1.5
0.95
1
0.32 0.41
0.5 0.00
0
PERCENT RISING TIME SETTLING TIME
OVERSHOOT
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 5 6 7
T IM E ( S E C )
Controller
PID LQR FUZZY
Characteristics
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
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 state-space method is the best control method to control a multi-output
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 steady-state 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 control-law 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.
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:
e( k ) r (k ) y (k )
'e(k ) e(k ) e(k 1)
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 non-linearity, input-output 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
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
REFERENCES
[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”
[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
[11]
http://www.seattlerobotics.org/encoder/mar98/fuz/fl_part1.html#WHAT%20IS%20F
UZZY%20LOGIC?
M = .5;
m = 0.2;
b = 0.1;
i = 0.006;
g = 9.8;
l = 0.3;
num = [m*l/q 0]
den = [1 b*(i+m*l^2)/q -(M+m)*m*g*l/q -b*m*g*l/q]
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
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])
M = .5;
m = 0.2;
b = 0.1;
i = 0.006;
g = 9.8;
l = 0.3;
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)
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 = [(A-B*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')
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')
p = eig(Ac)
P = [-40 -41 -42 -43];
L = place(A',C',P)'
Ace = [A-B*K B*K;
zeros(size(A)) (A-L*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')