# Modelling of fuzzy logic control system using the MATLAB SIMULINK program

**ABSTRACT** Celem pracy było zbudowanie modelu regulatora w logice rozmytej dla układu dynamicznego na przykładzie odwróconego wahadła. Postawione zadanie zostało wykonane przy wykorzystaniu środowiska Matlab 2008 z modułami Simulink oraz Fuzzy Logic Toolbox. Uzyskane wyniki symulacji pokazują, że układ w logice rozmytej może zostać efektywnie wykorzystany do sterowania nieliniowym układem dynamicznym.

**5**Bookmarks

**·**

**952**Views

- Citations (0)
- Cited In (0)

Page 1

GRZEGORZ FILO∗

MODELLING OF FUZZY LOGIC CONTROL SYSTEM

USING THE MATLAB SIMULINK PROGRAM

MODELOWANIE UKŁADU STEROWANIA W LOGICE

ROZMYTEJ PRZY U?YCIU PAKIETU MATLAB SIMULINK

A b s t r a c t

The main aim of this work was building model of fuzzy logic controller for dynamic system

on example of inverted pendulum. This problem was solved using Matlab 2008 environment

with Simulink module and Fuzzy Logic Toolbox. Obtained results of simulations show that

regulator based on fuzzy logic can be efficiently used for controlling non linear dynamic

system.

Keywords: control, fuzzy logic, inverted pendulum, simulation, Matlab, Simulink

S t r e s z c z e n i e

Celem pracy było zbudowanie modelu regulatora w logice rozmytej dla układu dynamicznego

na przykładzie odwróconego wahadła. Postawione zadanie zostało wykonane przy wykorzy-

staniu ?rodowiska Matlab 2008 z modułami Simulink oraz Fuzzy Logic Toolbox. Uzyskane

wyniki symulacji pokazuj?, ?e układ w logice rozmytej mo?e zosta? efektywnie wykorzy-

stany do sterowania nieliniowym układem dynamicznym.

Słowa kluczowe: sterowanie, logika rozmyta, odwrócone wahadło, symulacja, Matlab,

Simulink

∗ PhD. Grzegorz Filo, Institute of Applied Infomatics, Faculty of Mechanical Engineering, Cracow

University of Technology.

Page 2

74

1. Introduction

Nowadays, in research centers all over the world are undertaken efforts in order to

design control systems for more and more complex devices and processes. In connection

with this fact new control methods and algorithms are required. Especially significant are

studies on fuzzy logic control systems [1]. Fuzzy logic controllers are designed particularly

for non-linear dynamic systems with many inputs and outputs which are so complex, that it

is very difficult or even impossible to build exact mathematical model. Controllers of this

type are characterized by large number of parameters, like: number and form of fuzzy sets

used for division of computational domain of input and output signals, selection of

operators for realizing fuzzy operations as sum, product and negation, selection of

conclusion algorithm, choice of function for computing numerical values of output

signals [5]. These parameters must be adjusted and given the correct values in order to the

controller work properly. The main aim of work presented in this paper was to analyze,

create models and carry out simulations of fuzzy logic controller for non-linear dynamic

system on the example of inverted pendulum [4, 7]. Model of both inverted pendulum and

fuzzy logic controller were created in Matlab – Simulink system.

2. Application of Fuzzy Logic in control systems

Application of fuzzy logic in control process requires using the following elements:

definitions of fuzzy sets, fuzzy logic operators, fuzzy rules (rule database), inference

mechanism and algorithm of computing numerical values of output signal.

2.1. Definitions of fuzzy sets

The following kinds of fuzzy sets were used in model of fuzzy logic controller:

trapezoidal, built of line segments and defined by continuous functions: Gauss-shaped and

bell-shaped. Trapezoidal function defined at range

defined using formula (1):

ba

with nucleus

dc

can be

0,for()()

for

( )

x

1for

for

F

xaxb

xa

axb

ba

bxc

dx

cxd

dc

???

?

?

?

? ?

??

?

?

?

?

?

??

?

??

?

?

??

(1)

Equations (2) and (3) describe Gauss and bell-shaped functions, respectively:

()/

( )

F

x C

?

w

Fxe?

??

, (2)

2

1

?

( )

x

1 (

?

)

F

F

xC

??

, (3)

Page 3

75

where:

CF

w

–

– parameter.

to nucleus of fuzzy set ?:

??

nuc( ): ( )

?

1

FxXx

???

,

2.2. Fuzzy relational operators

Several different versions of fuzzy sum and product operators can be used in model of

fuzzy regulator [5]. The most commonly used fuzzy sum operators are MAX or SUM,

while product operators are MIN or PROD. Operators of sum of two fuzzy sets A and B

can be described using formulas (4) and (5). Notations of product operators of the same

fuzzy sets are presented using formulas (6) and (7):

( )

x

MAX( ( ),

x

( ))

x

A B

?

AB

????

, (4)

( )

x

( )

x

( )

x

( )

x

( )

x

A B

?

ABAB

? ? ????? ??

, (5)

( )

x

( ( ),

x

( ))

x

A B

?

AB

MIN

????

, (6)

( )

x

( )

x

( )

x

A B

?

AB

? ? ???

, (7)

2.3. Construction of rule database

A rule can be formulated using fuzzy operators in IF – THEN statement. The general

form of the fuzzy rule is:

12

THEN ( ,

x x

, ...,)

ijjn

IF Rufx

?

, (8)

where:

Ri – relation between fuzzy sets of input parameters defined using fuzzy

operators,

output signal,

function,

numerical values of input signals.

According to Takagi – Sugeno model fi is usually a polynomial function. If a function is

reduced to constant value, a zero-order fuzzy controller is obtained. This type of controller

is called a Mamdani model. In this case fuzzy rule can be formulated as:

Uj

Fj

x1 … xn –

–

–

THEN

ij jk

IF RuA

?

, (9)

where:

Ajk – singular fuzzy set of output value j.

2.4. Methods of generating output signals

Each fuzzy rule describes influence of individual fuzzy set of input signals on the

individual fuzzy set of output signal. Numerical procedure which allows for determining

Page 4

76

this influence is called fuzzy implication. The implication can be defined in many ways [3]

but the most common use is previously mentioned product operators MIN or PROD [2].

The influences produced by all rules applying to individual fuzzy set of output signal

should be then combined together in order to obtain the total assessment of this signal. This

process is called fuzzy inference. The result of inference process is a fuzzy set of output

signal. In practice, each controller should generate a non-fuzzy (crisp) numerical output

signal. Procedure which generates numerical value from fuzzy set of output signal is known

as defuzzification process. The output signal can be calculated using several methods [6].

One of the most common is CoS (Center of Sum). It uses the following formula [2]:

111

11

( ... )

U x

( ... ,

x

)( ... ,

x

)

nn

niuniuni

ii

xu x ux u

??

????

??

, (10)

where:

U

n

ui

?u

– crisp value of output signal,

– number of fuzzy sets of output signal,

– individual element of fuzzy set of output signal,

– membership function of element ui.

Output signal can be also calculated using the COG method (Center of Gravity). For

discrete computational domain this method can be written as [2]:

111

1111

( ... )

U x

( ... ,

x

) ( ... ,

x

)

nmnm

niR jni R jni

ijij

xu x u x u

????

?

?

?

?

?

?

????

????

, (11)

where:

m – number of fuzzy rules activated by inputs x1 … xn.

Continuous computational domain requires exchange of sum operators in equations (10)

and (11) to integrals.

3. Model of the system

Considered system consists of mathematical model of inverted pendulum and model of

fuzzy logic controller. Model of the pendulum was created in Matlab – Simulink program,

while fuzzy logic controller was built using Matlab Fuzzy Logic Toolbox. Simulations

were carried out in Simulink.

3.1. Mathematical model of inverted pendulum

Application of fuzzy logic controller will be shown on example of inverted pendulum

system. It is commonly known, that inverted pendulum is inherently unstable and has

strongly non-linear properties [4, 7], so it is difficult to control. Diagram of considered

pendulum is shown in Fig. 1.

Page 5

77

a)

b)

Fig. 1. Diagram of inverted pendulum a) system, b) subsystems of frame and pendulum

Rys. 1. Schemat pogl?dowy odwróconego wahadła: a) układ, b) podukłady wózka i wahadła

Parameters defined in fig. 1 are as follows: x – horizontal position of pendulum frame [m],

x ? - horizontal velocity of pendulum frame [m/s], ? – rotation angle of pendulum [rad],

? ? ?

?

– angular velocity, ? ? ?

?

– angular acceleration, M, m – mass of frame and

pendulum, b, b1 – coefficient of viscous friction of frame and pendulum [Ns/m], I - moment

of inertia

4 3 m

IL

???

[kg m2], 2L – length of pendulum [m], N, P – horizontal and

vertical component of reactive force [N], g – acceleration of gravity: 9.81 [m/s2],

F - control force [N].

Mathematical model of this system is made up of four equations: sum of forces acting on

frame projected on horizontal axis, sum of forces acting on pendulum projected on

horizontal axis, sum of forces acting on pendulum projected on axis perpendicular to it and

sum of moments acting on pendulum around its center:

2

2

1

sin( )

sin( )

sin( )

P L

? ?

cos( )

? ?? ? ?

? ?

cos( )cos( )sin( )

cos( )

M x

? ?? ?

? ?? ?

?? ? ? ???

FN

? ?

? ??

? ?

b x

? ?

m x

? ?

? ?

N m L m L

? ???

?

m x

? ?

m LPN m g

?

IbN L

? ?

??

?

?

?

?

?

?

?

?

??

??

?

??

??

, (12)

Presented equations can be easily converted by eliminating N and P parameters. Final

system consists of two equations:

?

?

?

?

2

2

1

sin( )cos( )

sin( )cos( )

Mm x b x

? ? ? ?

??

m L

? ?? ?

m L

? ???

F

I m L

?

b m g L

? ? ?

m L x

?

?

?

? ?

?? ?? ?

???????? ? ? ? ? ??

?

??

, (13)

Equations (13) were used to create model in Simulink. The model is presented in Fig. 2.

Page 6

78

Fig. 2. Model of inverted pendulum created in Simulink

Rys. 2. Model odwróconego wahadła zbudowany w Simulinku

3.2. Model of fuzzy logic controller

To control inverted pendulum a mamdani type fuzzy logic controller was used. The

structure of the controller in Fuzzy Logic Toolbox window is presented in Fig. 3.

Fig. 3. Structure of fuzzy logic controller in Fuzzy Logic Toolbox window: 1) input signals, 2) rule

database and inference algorithm, 3) output signal

Rys. 3. Struktura regulatora rozmytego w oknie pakietu Fuzzy Logic Toolbox: 1) sygnały wej?ciowe,

2) baza reguł i algorytm wnioskuj?cy, 3) sygnał wyj?ciowy

As it comes from the figure, controller has three input signals: rotation angle of

pendulum called Psi, rotation velocity dPsi and position of pendulum frame X. Output

signal U is proportional to force acted at pendulum frame.

3.3. Control process strategy

Controller was applied in a regulation system using feedback of rotation angle value and

pendulum frame position. Regulation system is shown in Fig. 4. The system consists of the

following blocks: required angle of inverted pendulum equal to ? rad, subsystem which

computes input values for the controller Inputs, fuzzy logic controller FLC, saturation block

Page 7

79

keeping the control signal within given bounds, switch which allows for carrying out

simulation without controller and subsystem of pendulum. Values of control signal, rotation

angle of pendulum and position of pendulum frame are presented in graphical form as time

courses and saved into file using the Results subsystem.

Fig. 4. Regulator of inverted pendulum with application of fuzzy logic

Rys. 4. Układ regulacji odwróconego wahadła z zastosowaniem logiki rozmytej

4. Simulation tests and results

The following values of physical system parameters were assigned:

0.3 kg

m ?

,

0.5m

L ?

,

0.1Ns/m

b ?

,

with various initial conditions of rotation angle

0.9kg

M ?

,

1

0.05Ns/m

) 0 (

Θ

b ?

. Simulation tests were carried out

and the other initial conditions set to

zero:

0) 0 (

x

?

) 0 (

x

) 0 (

Θ

?

===

.

Example simulation results are shown in table 1.

In case a), when no controller is applied, rotation angle oscillated around zero. It means

that pendulum was reaching vertically down position. Fuzzy logic controller was applied in

cases b) to e) in order to obtain vertically up position of pendulum, regardless the initial

position. In cases b) and c) at starting point of simulation the pendulum is got out of plumb

by 30 degrees in plus and in minus. It comes from the results, that in both cases fuzzy logic

controller allowed for obtaining desired position of pendulum. In case d) starting angle of

pendulum was increased to 75 degrees in minus. Despite the control signal, pendulum goes

down, crosses the zero angle, deflects in the opposite direction. Then it goes back, finally

reaching the required position. The similar situation appears in case e), when starting

position of pendulum is vertically down. At first pendulum deflects in the opposite

direction, but fuzzy logic controller allows for obtaining the assumed position.

Page 8

80

T a b l e 1

Example results of simulations

Params Control signal Rotation angle of pendulum

a)

(0)

2.617rad

(-300 out of

plumb)

No control

??

b)

(0)

2.617rad

(-300 out of

plumb)

FLC

controller

??

c)

(0)

3.664rad

(+300 out

of plumb)

FLC

controller

??

d)

(0)

1.831rad

(-750 out of

plumb)

FLC

controller

??

e)

0 ) 0 (

Θ

(vertically

down)

FLC

controller

=

Page 9

81

5. Conclusions

The objective of this work was building model of fuzzy logic controller for non linear

dynamic system on example of inverted pendulum system. Model of the inverted pendulum

system was built in Matlab – Simulink. Model of fuzzy logic controller was designed using

the Fuzzy Logic Toolbox. Results of simulations confirm, that regardless of initial position

of pendulum, fuzzy logic controller is always capable for obtaining desired vertically up

position.

R e fe r e nc e s

[1] K i ng P., Ma m d an i E., The application of fuzzy control systems to industrial

processes, Automation vol. 13, No. 3, 1977.

[2] K o va c i? Z., B ogd an S., Fuzzy Controler Design. Theory and applications,

Taylor & Francis Group, New York, 2006.

[3] M i z um o t o M., Fuzzy controls under various fuzzy reasoning methods, Information

Sciences, No. 45, 1988.

[4] M o ri S., N i s hi ha ra H., F u ru t a H., Control of unstable mechanical system:

control of pendulum, International Journal of Control, vol. 23, 1976.

[5] P i e ga t A., Modelowanie i sterowanie rozmyte, Akademicka Oficyna Wydawnicza

EXIT, Warszawa 1999.

[6] R u nk l er T.A., Selection of appropriate defuzzification methods using application

specific properties, IEEE Transactions on Fuzzy Systems, No. 5, 1997.

[7] Y a m ak a wa T., Stabilization of an inverted pendulum by a high speed fuzzy logic

controller hardware system, Fuzzy Sets and System, vol. 32, 1989.

#### View other sources

#### Hide other sources

- Available from Grzegorz Filo · May 29, 2014
- Available from pk.edu.pl