129
MODELING AND CONTROLLER DESIGN FOR AN INVERTED PENDULUM SYSTEM AHMAD NOR KASRUDDIN BIN NASIR UNIVERSITI TEKNOLOGI MALAYSIA

Inverted Pendulum 1

  • Upload
    namdvp

  • View
    1.689

  • Download
    7

Embed Size (px)

Citation preview

Page 1: Inverted Pendulum 1

MODELING AND CONTROLLER DESIGN FOR AN INVERTED

PENDULUM SYSTEM

AHMAD NOR KASRUDDIN BIN NASIR

UNIVERSITI TEKNOLOGI MALAYSIA

Page 2: Inverted Pendulum 1

PSZ 19:16 (Pind. 1/97)

UNIVERSITI TEKNOLOGI MALAYSIA

BORANG PENGESAHAN STATUS TESIS

MODELING AND CONTROLLER DESIGN FORJUDUL: AN INVERTED PENDULUM SYSTEM

2006/2007SESI PENGAJIAN:

AHMAD NOR KASRUDDIN BIN NASIR Saya (HURUF BESAR)

mengaku membenarkan tesis (PSM/Sarjana/Doktor Falsafah)* ini disimpan di Perpustakaan Universiti Teknologi Malaysia dengan syarat-syarat 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

BANDAR 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).

Page 3: Inverted Pendulum 1

“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 : 30th APRIL 2007

Page 4: Inverted Pendulum 1

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

Page 5: Inverted Pendulum 1

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 NASIRDate : 30 th APRIL, 2007

Page 6: Inverted Pendulum 1

iii

To my dearest father, mother and family, for their encouragement, blessing and inspiration …

Page 7: Inverted Pendulum 1

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.

Page 8: Inverted Pendulum 1

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

Page 9: Inverted Pendulum 1

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.

Page 10: Inverted Pendulum 1

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 State-Space 14

Page 11: Inverted Pendulum 1

viii

2.3 What is Matlab 15

2.3.1 What is an m-file 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 States-Space Design 29

4.2.1 LQR Control Method 31

4.2.2 Adding a Reference Input 32

4.2.3 Full-Order 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

Page 12: Inverted Pendulum 1

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 Open-Loop Results 75

7.3 PID Control Method 78

7.3.1 PID Control Method 78

Page 13: Inverted Pendulum 1

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 105-108

Page 14: Inverted Pendulum 1

xi

LIST OF TABLES

TABLE TITLE PAGE

3.1 Zeigler-Nichols 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

Page 15: Inverted Pendulum 1

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 closed-loop system 20

with force as disturbance

3.2 The rearranged schematic diagram for the closed-loop 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

State-Space form

4.2 Schematic diagram of system with NBar 33

4.3 Schematic diagram of system in State-Space 35

Page 16: Inverted Pendulum 1

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

Page 17: Inverted Pendulum 1

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 State-Space

7.4 Impulse response for pendulum’s angle for 78

K=1, Kd=1, Ki=1

7.5 Impulse response for pendulum’s angle for 79

K=100, Kd=1, Ki=1

7.6 Impulse response for pendulum’s angle for 79

K=100, Kd=20, Ki=1

7.7 Impulse response of cart’s position for 80

K=100, Kd=20, Ki=1

7.8 Impulse response for pendulum’s angle for 82

K=-50, Kd=-3.5, Ki=-110

7.9 Impulse response for cart’s position for 82

K=-0.0001, Kd=0.3, Ki=-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

Page 18: Inverted Pendulum 1

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

Page 19: Inverted Pendulum 1

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

- 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

Page 20: Inverted Pendulum 1

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 - Single-input-single-output

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

Page 21: Inverted Pendulum 1

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 Full-Order 109

Estimator

Page 22: Inverted Pendulum 1

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 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 a highly nonlinear and open-loop 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

Page 23: Inverted Pendulum 1

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 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]

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 non-linearized 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)

Page 24: Inverted Pendulum 1

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 non-linear 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.

Page 25: Inverted Pendulum 1

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

Page 26: Inverted Pendulum 1

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

Page 27: Inverted Pendulum 1

6

Mathematical Model

Transfer function

LQR ControllerPID Controller Fuzzy Logic

State-Space 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

Page 28: Inverted Pendulum 1

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

Page 29: Inverted Pendulum 1

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.

Page 30: Inverted Pendulum 1

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 non-linearities 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

Page 31: Inverted Pendulum 1

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, 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%

Properties of the Cart and Pendulum:

M – Mass of cart 0.5kg

m – Mass of pendulum 0.2kg

b – Friction or cart 0.1Nm-1s-1

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 co-ordinate

– Pendulum angle from the vertical

Page 32: Inverted Pendulum 1

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) FNbM

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

cossincossin xmmlmgNP (2.4)

To get rid of the P and N terms in the equation above, sum the moments around the

centroid of the pendulum

IlNPl cos.sin (2.5)

xx

cos 2

xM cos)( 2

NsinmlmlxM

Fmlmlbm sinx

Page 33: Inverted Pendulum 1

12

Combining equation 2.4 and equation 2.5

cossin)( 2 xmlmglmlI (2.6)

Since Matlab can only work with linear functions, this set of equations should be

linearized about = . Assume that = + ø (ø represents a small angle from the

vertical upward direction). Therefore, cos ( ) = -1, sin ( ) = -ø, and 2)(dt

d = 0.

After linearization the two equations of motion become (where u represents the

input):

xmlmglmlI )2( (2.7)

umlxbxmM )( (2.8)

2.2.1 Transfer Function

Laplace transform of the system equations

(2.9) 22 ((()( mglml 2

(2.10) (((( UmlbXXm

))) ssmlXsssI

))) 22 sssssssM )()

Since the angle ø is the output of interest, solving equation 2.9 for X(s),

Page 34: Inverted Pendulum 1

13

)()(

)(2

2

ss

g

ml

mlIsX (2.11)

Substituting equation 2.11 into equation 2.10

)()()()(

)()(

)( 22

22

sUssmlsss

g

ml

mlIbss

s

g

ml

mlImM (2.12)

Re-arranging, the transfer function is

sq

bmgls

q

mglmMs

q

mlIbs

sq

ml

sU

s

232

4

2

)()()(

)( (2.13)

where, ])())([( 22 mlmlImMq

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

bmgls

q

mglmMs

q

mlIbs

sq

ml

sU

s

)()()(

)(

22

3

(2.14)

4545.41818.311818.0

5455.4

)(

)(23 sss

s

sU

s (2.15)

Solving for the transfer function of the position, the following equation 2.16 will be

derived

4545.41818.311818.0

5455.448182.1

)(

)(23 sss

s

sU

sX (2.16)

Page 35: Inverted Pendulum 1

14

2.2.2 State-Space

The linearized system equations can also be represented in state-space form

as shown in equation 2.17 till equation 2.19.

)(

)(

)(

)(

0)(

)(

)(0

1000

0)()(

)(0

0010

)(

)(

)(

)(

22

2

22

2

2

t

t

tx

tx

MmlmMI

mMmgl

MmlmMI

mlb

MmlmMI

glm

MmlmMI

bmlI

t

t

tx

tx

(2.17)

)(

)(

0)(

0

2

2

2

tu

MmlmMI

ml

MmlmMI

mlI

Substituting all the parameter values into the equation 2.17 yielding equation 2.18

and equation 2.19

)(

5455.4

0

8182.1

0

)(

)(

)(

)(

01818.314545.00

1000

06727.21818.00

0010

)(

)(

)(

)(

tu

t

t

tx

tx

t

t

tx

tx

(2.18)

)(0

0

)(

)(

)(

)(

0100

0001)( tu

t

t

tx

tx

ty (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 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.

Page 36: Inverted Pendulum 1

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 user-friendly 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 M-File

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.

Page 37: Inverted Pendulum 1

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 steady-state operation of a linear electrical circuit

Continuous

Z source

v+-

Voltage Measurement

Scope

Z

Impedance Measurement

I source300 Hz

?

Double click here for details

i+ -

Current Measurement

5th Harm.Filter

100 V60 Hz

Current

Voltage

Figure 2.3: Simulink block in Matlab

Page 38: Inverted Pendulum 1

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

FIG-file. GUIDE automatically generates an M-file that controls how the GUI

operates. The M-file 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 M-file 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

Page 39: Inverted Pendulum 1

18

CHAPTER III

PID CONTROLLER

3.1 Introduction

PID stands for Proportional-Integral-Derivative. This is a type of feedback

controller whose output, a control variable (CV), is generally based on the error (e)

between some user-defined 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.

Page 40: Inverted Pendulum 1

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

sq

bmgls

q

mglmMs

q

mlIbs

sq

ml

sU

s

232

4

2

)()()(

)( (3.1)

where,

])())([( 22 mlmlImMq

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.

Page 41: Inverted Pendulum 1

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

PLANT 1 G2(S)

PLANT 1 G1(S)

PIDCONTROLLER r(s)=0 e(s)

f(s)=F

)(sX

)(su(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

Page 42: Inverted Pendulum 1

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.

))((

))((1

)()()(1

)()(

dendenPID

numnumPIDkden

num

sFsGsKD

sGsy (3.2)

)())(())((

)(sF

numnumPIDkdendenPID

denPIDnum

3.2.1 PID controller

The closed-loop transfer function in equation 3.2 can be implemented into

Matlab by using the m-file 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.

Page 43: Inverted Pendulum 1

22

This closed-loop transfer function can be modeled in Matlab by copying the

code from Appendix A3 for this section to the end of m-file. The function polyadd is

not originally in the Matlab toolbox. It has to be copied to a new m-file 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

steady-state 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 Kd variable. With Kd = 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.

Page 44: Inverted Pendulum 1

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

)(

)1)((

)1)((1

2

2

)(1)(1

)(2)( sF

dendenPID

numnumPIDkden

num

sGsKD

sGsX (3.3)

Page 45: Inverted Pendulum 1

24

)()2)(1)(()2)(1)((

)1)()(2()( sF

dennumnumPIDkdendendenPID

dendenPIDnumsX (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()(

numnumPIDkdendenPID

denPIDnumsX (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

bmgls

q

mglmMs

q

mlIbs

q

mgls

q

mlI

sU

sX

)()(

)(

)(

)(

22

3

22

(3.6)

where,

])())([( 22 mlmlImMq

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.

Page 46: Inverted Pendulum 1

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)

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

Page 47: Inverted Pendulum 1

26

Table 3.1 shows the Zeigler-Nichols 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: Zeigler-Nichols tuning method

Controller Type Proportional

Gain, Kc

Integral Time,

Ti

Derivative

Time, Td

Proportional (P) gp KK 5.0 - -

Proportional-Integral (PI) gp KK 45.0

g

gI

KK

54.0 -

Proportional-Integral-

Derivative (PID)

gK6.0

g

gI

KK

2.1

4

3.0 ggD

KK

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

Page 48: Inverted Pendulum 1

27

x

-0.65357Target Position(Mouse-Driven)

Target Position Switch

In1

teta1

x1

Subsystem

Step1

R2D

Radiansto Degrees

PID

PID Controller2

PID

PID Controller1

Mux

Mux

Manual Switch

1Constant

animcp

Animation

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

single-input-single-output (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.

Page 49: Inverted Pendulum 1

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 state-space 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 first-order differential equations, which

may be combined into a first order vector-matrix differential equation.

Page 50: Inverted Pendulum 1

29

4.2 States-Space 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

)(

)(

)(

)(

01818.314545.00

1000

06727.21818.00

0010

)(

)(

)(

)(

tu

t

t

tx

tx

t

t

tx

tx

(4.1)

)(0

0

)(

)(

)(

)(

0100

0001)( tu

t

t

tx

tx

ty

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

Steady-state error within 2%.

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.

Page 51: Inverted Pendulum 1

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

Ry

x

+

- )()(

)()()(

tCxty

tBytAxtx

Figure 4.1: Schematic diagram for inverted pendulum in state-space 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

,,, xx

Page 52: Inverted Pendulum 1

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.

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

Page 53: Inverted Pendulum 1

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.

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 A-5 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 full-state feedback

controller, all the states are feedback so that it can be multiplied with the K matrix.

Page 54: Inverted Pendulum 1

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.

K

NRy

x

+- Cxy

ByAxx

Figure 4.2: Schematic diagram of system with constant gain, Nbar

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

Page 55: Inverted Pendulum 1

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.

4.2.3 Full-Order Estimator

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

Figure 4.3: Schematic diagram of system in state-space 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 m-file

p = eig(Ac)

Page 56: Inverted Pendulum 1

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.

Page 57: Inverted Pendulum 1

36

4.3 Conclusion

As a conclusion, it is found that LQR state-space method is the best control

method to control a multi-output 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

control-law 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.

Page 58: Inverted Pendulum 1

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 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]

5.2 What Is Fuzzy Logic

In this context, FLC is a problem-solving control system methodology that

lends itself to implementation in systems ranging from simple, small, embedded

micro-controllers to large, networked, multi-channel PC or workstation-based data

Page 59: Inverted Pendulum 1

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.

INVERTEDPENDULUM

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]

Page 60: Inverted Pendulum 1

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

Page 61: Inverted Pendulum 1

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 Type membership function

Page 62: Inverted Pendulum 1

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.

Page 63: Inverted Pendulum 1

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, single-output 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.

Page 64: Inverted Pendulum 1

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;

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

dyyB

ydyyBy

)(*

)(*0

It is also shown graphically in Figure 5.6.

Page 65: Inverted Pendulum 1

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

Page 66: Inverted Pendulum 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.

Page 67: Inverted Pendulum 1

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.

Page 68: Inverted Pendulum 1

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.

Page 69: Inverted Pendulum 1

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.

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

Page 70: Inverted Pendulum 1

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, rule-based IF X AND Y THEN Z approach to a

solving control problem rather than attempting to model a system mathematically.

The FLC model is empirically-based, 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.

Page 71: Inverted Pendulum 1

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 rate-of-change-of-error, 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 rate-of-change-of-error, hereafter called

"error-dot". Error might have units of degs F and a small error considered to be 2F

while a large error is 5F. The "error-dot" might then have units of degs/min with a

small error-dot 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, 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

Page 72: Inverted Pendulum 1

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

Parameter Tuning Mapping of membership functions

Fuzzy inference rules Scaling factors

Fuzzy Logic Controller Operation

FuzzificationFuzzy inference Defuzzification

Simulation & Testing

OK

Yes

No

End

Figure 5.9: Fuzzy Logic controller design flow chart

Page 73: Inverted Pendulum 1

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.

INVERTED

PENDULUM

(NONLINEAR)

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

Page 74: Inverted Pendulum 1

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.

Page 75: Inverted Pendulum 1

54

INFERENCE ENGINEFUZZIFIER DEFUZZIFIER

KNOWLEDGE BASE

PROCESS

FUZZY CONTROLLER

FUZZY FUZZY

PROCESS OUTPUT & STATES

CRISP CONTROLSIGNAL

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

Page 76: Inverted Pendulum 1

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.

Page 77: Inverted Pendulum 1

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

Deg

ree

of m

embe

rship

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

Del-position

Deg

ree

of m

embe

rshi

p

NB NM NS ZE PS PM PB

Figure 5.14: Input 2 of Fuzzy Logic Controller 1

Page 78: Inverted Pendulum 1

57

-10 -8 -6 -4 -2 0 2 4 6 8 10

0

0.2

0.4

0.6

0.8

1

Force

Deg

ree

of m

embe

rship

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

Deg

ree

of m

embe

rshi

p

NB NM NS ZE PS PM PB

Figure 5.16: Input 1 of Fuzzy Logic Controller 2

Page 79: Inverted Pendulum 1

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

Del-angle

Deg

ree

of m

embe

rshi

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

Deg

ree

of m

embe

rshi

p

NB NM NS ZE PS PM PB

Figure 5.18: Output of Fuzzy Logic Controller 2

Page 80: Inverted Pendulum 1

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

DE

LP

OS

ITIO

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

DE

LA

NG

LE

PB NB NM NS PS PS PM

Page 81: Inverted Pendulum 1

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.

Page 82: Inverted Pendulum 1

61

xdot

x

tetadot

simout1

position

nonlinear inverted pendulum

simout

angle

TotalForce

-0.675Target Position(Mouse-Driven)

Target Position Switch

Step1

R2D

Radiansto Degrees

Mux

Mux

Mux

Mux

Manual Switch

1

Gain1

.94

GainFuzzy LogicControl ler(Position)

Fuzzy LogicControl ler

(Angle)

1Constant

animcp

Animation

Figure 5.19: Schematic diagram of the Nonlinear Inverted Pendulum system with

two FLC controllers in Simulink

Page 83: Inverted Pendulum 1

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.

Page 84: Inverted Pendulum 1

63

CHAPTER VI

ARTIFICIAL NEURAL NETWORKS CONTROLLER

6.1 Introduction

A neural network is an information-processing 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.

Page 85: Inverted Pendulum 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

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.

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

Page 86: Inverted Pendulum 1

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.

Page 87: Inverted Pendulum 1

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, 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

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

Page 88: Inverted Pendulum 1

67

introduce nonlinearities into the network. This makes multi-layer 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, log-sigmoid 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]

Log-sigmoid function Tan-sigmoid 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

Page 89: Inverted Pendulum 1

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 input-output

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.

Page 90: Inverted Pendulum 1

69

`Supervised Learning

INVERTEDPENDULUM

INPUT SYSTEMx

x

u

LEARNINGALGORITHM

ADJUST WEIGHT

ARCHITECTURE

u

x

x

DESIREDRESPONSE

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.

Page 91: Inverted Pendulum 1

70

INVERTED

PENDULUM

SYSTEM I/P SYSTEM O/Px

xu

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

Page 92: Inverted Pendulum 1

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

Page 93: Inverted Pendulum 1

72

n o n l i n e a r i n v e rte 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 W o rksp a c e 4

x

T o W o rksp a c e 3

te ta d o t

T o W o rksp a c e 2

te ta

T o W o rksp a c e 1

si m o u t

T o W o rksp a c e

-0 .6 7 5T 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 te p 1

S c o p e

S a tu ra t i o n 3

S a tu ra t i o n 2

S a tu ra t i o n 1S a tu ra t i o n

R 2 D

R a d i a n sto D e g re e s

p {1 }y {1 }

N e u ra l N e tw o rk2

p {1 }y {1 }

N e u ra l N e tw o rk1

M u x

M a n u a l S w i t c h

0 .8G a i n 4

1 0G 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

1C o n sta 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

Page 94: Inverted Pendulum 1

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

Tan-Sigmoid (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 two-layer network with a suitable number of nodes in

the hidden layer can approximate any continuous function

over a compact subset [1].

Page 95: Inverted Pendulum 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 m-file. Therefore,

model can’t be updated directly from Simulink. The model was build in m-file,

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 m-file 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.

Page 96: Inverted Pendulum 1

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 Open-Loop Results

As mentioned in Chapter 2, the mathematical model and equations using the

transfer function and state-space of the inverted pendulum have been determined. By

implementing all these equations into Matlab M-file 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.

Page 97: Inverted Pendulum 1

76

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

10

20

30

40

50

60IMPULSE RESPONSE (ANGLE)

TIME (SEC)

AM

PLI

TU

DE

Figure 7.1: Impulse response for pendulum’s angle using transfer function

Figure 7.2: Impulse response for cart’s position using transfer function

Page 98: Inverted Pendulum 1

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 20

10

20

30

40

50

60

70

80

90

100

TIME(SEC)

AM

PLI

TU

DE

RESPONSE TO A STEP INPUT

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.

Page 99: Inverted Pendulum 1

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, Kd,

7

T

Ki, and Kd in order to get the best impulse response of the system.

7

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

Page 100: Inverted Pendulum 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)

AM

PLI

TU

DE

E

X: 0.04Y: 0.0417

X: 0.04Y: 0.0417

Page 101: Inverted Pendulum 1

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 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.1IMPULSE RESPONSE

TIME (SEC)

PO

SIT

ION

OF

CA

RT

Page 102: Inverted Pendulum 1

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.

Page 103: Inverted Pendulum 1

82

1

Figure 7.8: Impulse response for pendulum’ angle for K=-50, Kd=-3.5, Ki=-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: 450Y : 1.003

X: 360Y : 0.98

TIM E (S E C)

PO

SIT

ION

S TE P RE S P O NS E (P O S ITIO N)

2 3 4 5 6 7 8 9 1 0

-4

-3 .5

-3

-2 .5

-2

-1 .5

-1

-0 .5

0

X :Y

1 0 8: 0 .4 8 0 3

0 .5

X : 4Y : -

4 80 .0 2 0 5 9

XY

: 1 6 4: -4 .3 9 2 TIM E (S E C )

AN

GLE

S TE P R E S P O N S E (A N G L E )X=1.08Y=0.4803

X : 8 0Y : 0 .

2X=8.020 0 0 1 0 3 7Y=0.0001037

X=4.48Y=-0.02059

X=1.64Y=-4.392

X=4.5Y=1.003X=3.6

Y=0.98

Page 104: Inverted Pendulum 1

83

7.4 LQR Control Method

7.4.1 Pendulum's Angle and Cart's Position

Using state-space methods it is relatively simple to work with a multi-output

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.

Page 105: Inverted Pendulum 1

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 steady-state 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

Page 106: Inverted Pendulum 1

85

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.

The response is good, but it was found by assuming full-state 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 control-law 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

Page 107: Inverted Pendulum 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 state-space method is better

control method to control a multi-output system than the PID.

Page 108: Inverted Pendulum 1

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 3Y : 2 0 .2 2

2 0

XY

: 8 2 8: 0 .0 3 6

XY

: 2 1 3: - 1 9 .5 2

T IM E (S E C )

AN

GLE

S T E P R E S P O N S E (A N G L E )X=1.53Y=20.22

X=8.28Y=0.036

X=2.13Y=-19.52

Page 109: Inverted Pendulum 1

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 back-propagation 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: 923Y : 1.011

TIM E (S E C)

PO

SIT

ION

S TE P RE S P ONS E (P OS ITION)

X=3.02Y=1.036

X=9.23Y=1.011

X: 489X=4.89Y : 1.02Y=1.02

Page 110: Inverted Pendulum 1

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 )

PO

SIT

ION

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 IM E ( S E C )

AN

GLE

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 )

Figure 7.16: Training output response of pendulum’s angle

Page 111: Inverted Pendulum 1

90

Applying the m-file 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 IM E ( S E C )

PO

SIT

ION

(m

)

S T E P R E S P O N S E ( P O S IT IO 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 IM E ( S E C )

AN

GLE

(D

EG

RE

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

Page 112: Inverted Pendulum 1

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.

Page 113: Inverted Pendulum 1

92

0 1 2 3 4 5 6 7-0 . 4

-0 . 2

0

0 . 2

0 . 4

0 . 6

0 . 8

1

T IM E (S E C )

PO

SIT

ION

S TE P R E S P O N S E (P O S IT IO 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 (Tr) 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.

Page 114: Inverted Pendulum 1

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.

Page 115: Inverted Pendulum 1

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

2.04

2.57

0.95

4.91

0

0.51

1.5

2

2.53

3.5

44.5

5

PERCENTOVERSHOOT

RISING TIME SETTLING TIME

PID LQR FUZZY

Figure 7.20: Output response of cart’s position

Page 116: Inverted Pendulum 1

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

T IM E (S E C )

AN

GLE

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

Page 117: Inverted Pendulum 1

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.

Page 118: Inverted Pendulum 1

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 single-input-single-output (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 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

Page 119: Inverted Pendulum 1

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.

As discussed in Chapter 5, FLC incorporates a simple rule-based 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 rate-of-change-of-error,

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:

)()()( kykrke

)1()()( kekeke

Page 120: Inverted Pendulum 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.

Page 121: Inverted Pendulum 1

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.

Page 122: Inverted Pendulum 1

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

Page 123: Inverted Pendulum 1

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.

Page 124: Inverted Pendulum 1

103

REFERENCES

[1] K. Hornik and M. Stinchcombe and H.White. “Multilayer Feed-Forward

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

Page 125: Inverted Pendulum 1

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

Page 126: Inverted Pendulum 1

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; endmz=length(long)-length(short); if mz>0 poly=[zeros(1,mz),short]+long; else poly=long+short; end

A2: Matlab command for Polyadd function

Page 127: Inverted Pendulum 1

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

Page 128: Inverted Pendulum 1

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 = [(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')

A5: Matlab command for LQR design

Page 129: Inverted Pendulum 1

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 = [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')

A7: Matlab command to design a Full-Order Estimator