You are on page 1of 6

2014 International Conference on Circuit, Power and Computing Technologies [ICCPCT]

Tuning and Implementation of Fuzzy Logic


Controller using Simulated Annealing in a Nonlinear Real-time System
Tharun Kumar S

B. Jaganatha Pandian

School of Electrical Engineering


Vellore Institute of Technology,
(VIT) University, Vellore, India.
tharun.raju19@gmail.com

School of Electrical Engineering


Vellore Institute of Technology,
(VIT) University Vellore, India.
jaganathapandian@vit.ac.in

mathematical modeling of our ball and beam system, followed


by the algorithm to tune the fuzzy parameters using the
simulated annealing algorithm and have shown the necessary
results obtained.

AbstractTuning a controller for any process purely depends


on the process dynamics. Improper selection of controller
parameters could spoil the entire design. Selecting a tuning
technique to achieve a desired response could be dealt as an
optimization problem. This paper deals with the tuning of a fuzzy
logic controller using Simulated Annealing to minimize the Mean
Square Error between the desired and actual output of a nonlinear system. The proposed algorithm is tested on a real time
ball beam system and the results are compared with the
simulated responses. By using this method best results are
obtained by using less number of fuzzy membership functions.

II.

KeywordsArduino; non-linear; ball and beam; simulated


annealing; fuzzy logic controller

I.

SYSTEM DESCRIPTION

The ball and beam system consist of a beam of length L


supported in the middle. One end of the beam is connected to a
servo through rotational joint between/by two links. The length
of the link connected to the servo is d. A metal ball of mass m
rolls along the beam restricted to a maximum range/span of
60cm. The balls position on the beam is controlled by
manipulating the servos angle . This angle theta is
proportional to beams angle .

INTRODUCTION

Ball and beam is a complex, non-linear control system. It


consists of a beam on which a ball moves freely. The objective
is to control the position of the ball on the beam by controlling
the angle of the beam. The angle of the beam is controlled
using a high torque servo motor. Fuzzy logic controller is
known for handling uncertainties and doesnt require complex
mathematical modeling. By knowing the correct range of
inputs and outputs, one can design a fuzzy logic controller
effectively.
In [1] a ball and beam system is mathematically modeled
and a fuzzy logic controller (FLC) is designed. A comparison
between the classic PID controller and the FLC is also
presented and it is proved that FLC is much better than PID.
Seven triangular membership functions for the input and output
variables have been used. Improving upon this, only 5
Gaussian membership functions were used, thus reducing the
computation time for the FLC. Adding to that, the fuzzy logic
controller is automatically tuned using the Simulated
Annealing (SA) algorithm. The center and the width
parameters of all the membership functions are tuned by SA.
We have implemented the ball and beam system with the tuned
and normal fuzzy logic controllers. The tuned FLC gave the
best results. A ball and beam system is constructed in real time
with the help of Arduino and MATLAB and tested with the
tuned and un-tuned fuzzy logic controllers. The results were
similar to the simulation results. In this paper we present the

978-1-4799-2395-3/14/$31.00 2014 IEEE

Fig. 1. Ball and beam system.

The dynamics of the system is given by the equation (4). In


order to implement the ideology in real-time, a ball and beam
system is fabricated according to the system dynamics derived.
Fig. 1. shows the model of the ball and beam system built to
validate the claim. The Real-time model has an analog IR
range sensor which gives the feedback to the system. This
system is controlled in real time and is achieved by connecting
Arduino Uno which incorporates the Atmega328 8 bit AVR
microcontroller to MATLAB through serial communication.
Thus the Arduino acts as a data acquisition device which

916

2014 International Conference on Circuit, Power and Computing Technologies [ICCPCT]

III.

continuously gets the position of the ball from the IR sensor


and provides the output of the controller to the servo motor.

A. Fuzzy Logic Controller


The Mamdani type fuzzy logic controller is designed with
two input variables and an output variable. The input variables
are the error and the change in error, whereas the output
variable is alpha (the angle of the beam). Five Gaussian
membership functions were used for each input and output
variables. Fig. 2. And Fig. 3. are the input variables and Fig. 4
is the output variable. This gives us a maximum of 25 rules as
shown in table 1. Thus a smooth surface plot is obtained as in
Fig. 5. The centroid method is used as the defuzzification
process.

Ordinary differential equation (ODE) is used to


mathematically model this non-linear ball and beam system so
that the proposed controllers can be implemented in software
simulations as well.
The Lagrangian equation of motion for the ball is given by
the following:

r + Mg sin Mr ( ) 2 = 0
2 + M 
R

(1.1)

NE
1
Degree of membership

This non-linear equation is linearized about the beam angle


alpha = 0,

2 + M r = Mg
R

(1.2)

The relation between the beam angle alpha and the gear
angle theta is approximately given by

d
=
L

PS

PE

-0.5

0
e

0.5

0.4
0.2

(1.3)

Fig. 2. Input variable e.

Degree of membership

NDE
1

(1.4)

NDS

ZDE

PDS

PDE

-0.5

0
de

0.5

0.8
0.6
0.4
0.2
0

(1.5)

-1

Fig. 3. Input variable de.

(1.6)
NDU
1
Degree of membership

d 2 x M * g *
=
J
dt
( 2 + M)
R

ZE

0.6

0
-1

The ODE equations are given by

dx d 2 r
=
dt
dt

NS

0.8

Thus the final equation is

d
J

r = Mg
2 + M 
L
R

METHODOLOGY

Where the variables are:


M Mass of the ball
R Radius of the ball
d Lever arm offset
g Gravitational acceleration
L Length of the beam
J Balls moment of inertia
r Balls position
Beam angle
Servo angle

NDSU

ZDU

PDSU

PDU

-0.5

0
alpha

0.5

0.8
0.6
0.4
0.2
0
-1

Fig. 4. Output variable alpha.

917

2014 International Conference on Circuit, Power and Computing Technologies [ICCPCT]

0.6
0.4

du

0.2
0
-0.2
-0.4
-0.6
1
0.5

1
0.5

-0.5
de

-0.5
-1

-1

TABLE II. Tuning Algorithm

Algorithm:
Initialize x randomly ( x is the solution)
Initialize the temperature T
For k iterations
Set xi = x + x ( x is the random change)

Fig. 5. Surface plot of un-tuned fuzzy.

TABLE I. Fuzzy rule base.

de

PE

PS

disturbance is given, it should counter act and go back to the


set point as quickly as possible with less overshoot. Hence we
choose the integral mean square error as our cost function. SA
is used to reduce this cost function by manipulating few fuzzy
parameters. The possible parameters that could be changed so
that there is change in the performance are the fuzzy rules, the
number of membership functions and the position of the
membership functions in the input and output variables. Here
we choose the latter option. Each Gaussian membership
function has two variables one being the width and the second
being the center of the function. Since there are 15 Gaussian
membership functions, the total number of variables is 30.
Thus SA is used to optimize the problem by manipulating
these 30 variables so the cost function is less. The following
outputs were achieved using SA.

ZE

NS

NE

Evaluate f ( x) and f (xi )

NDE

ZDU

NDSU

NDU

NDU

NDU

NDS

PDSU

ZDU

NDSU

NDU

NDU

ZDE

PDU

PDSU

ZDU

NDSU

NDU

PDS

PDU

PDU

PDSU

ZDU

NDSU

PDE

PDU

PDU

PDU

PDSU

ZDU

Where f ( x) is:
( v is the parameters width and centers of all 15 gaussian
membership functions)
Generate fuzzy structure A with x
Evaluate the ball and beam sytem with the
fuzzy logic controller A
For p iterations

E = s. p. p.v.
f ( x) =

B. Tuning of FLC using SA


Simulated Annealing is an optimization algorithm used to
solve highly non-linear problems. The algorithm is based on
the process of heating a system at high temperature and then
slowly decreasing the temperature [2]. The algorithm
generates initial random solution and then for every iteration a
small change in the random value is given to get the new
solution. The cost function is calculated and all the solutions
are accepted if the new solution is better than the old solution.
Even if the new solution is worse than the old solution, it is
accepted with the probability proportional to the temperature.
As even the bad solution is accepted with a probability, the
chances of the algorithm getting stuck in a local minimum are
reduced. Since temperature is decreased for every iteration,
the probability of accepting the bad solution becomes zero. It
shows that as the iterations increases the solution space
converges to smaller and smaller space.

( E) 2
p

If f (xi ) < f (x)


Set x = xi
Else if f (xi ) f (x)

Accept x = xi * e T ( f is the change in


cost function)
Set T (k ) = * T (k 1) ( is the cooling rate)
Final x is the solution.

IV.

RESULTS

The membership function parameters of the FLC were


tuned using the simulated ball and beam model as in (1.5) and
(1.6). The goal of tuning was to minimize the cost function
using simulated annealing as described in table 2. The
simulated annealing algorithm is run for a maximum iteration
of 300. The convergence graph shown in figure 6 shows that

The objective of this ball and beam system is for the ball to
correctly settle in the given position in the beam. If

918

2014 International Conference on Circuit, Power and Computing Technologies [ICCPCT]

the best value is attained at around 100th iteration. Fig. 7, Fig. 8


and Fig. 9 are the tuned input and output variables of the fuzzy
logic controller.

Degree of membership

45
40
35
Best Function Value

PDSU

30

NDUZDU
NDSU PDU

0.8
0.6
0.4
0.2
0

25

-1

20

-0.5

15

0
alpha

0.5

Fig. 9. Output variable alpha.

10
5
0

50

100

150

Iteration

Fig. 6. SA convergence response.


0.4

NS

Degree of membership

du

0.2

PSZEPENE

0.8

-0.2

0.6

-0.4
1
0.5

0.4

1
0.5

-0.5

0.2

de

-0.5
-1

-1

0
-1

-0.5

0
e

0.5

Fig. 10. Surface plot of tuned fuzzy.

Fig. 7. Input variable e.

Degree of membership

ZDE

The tuned fuzzy logic controller obtained is tested on both


the simulation modal and the real-time ball and beam system.

NDEPDS

A. Simulation
The ball position was kept at a distance 35cm from the
reference point in the simulation and the desired position was
set as 20cm from the reference point. The system response
under un-tuned FLC is given in Fig.11. Fig.12 shows the
system response under tuned FLC.

NDSPDE

0.8
0.6
0.4
0.2
0
-1

-0.5

0
de

0.5

Fig. 8. Input variable de.

919

2014 International Conference on Circuit, Power and Computing Technologies [ICCPCT]

35

40
35

25
Ball's position (cm)

Ball's Position (cm)

30

20
15
10
5

200

400
600
No. of samples
Fig. 11. Output response of un-tuned fuzzy.

30
25
20

800
15

Ball's position (cm)

10

4
6
Time (sec)
Fig. 14. Output response of tuned fuzzy.

30

25

Tuned
2.9308
3.3348

Un-tuned
44.7616
10.2139

Once the ball settled a random disturbance was given to the


system to observe the regulatory response of tuned and untuned fuzzy logic controllers in real-time system.

20

50

100
150
No. of samples
Fig. 12. Output response of tuned fuzzy.

200

20.5
20
19.5
Ball's position (cm)

B. Real-time implementation
The ball position was kept at a distance 35cm from the
sensor in the beam and the desired position was set as 20cm
from the sensor. The response is observed and logged using
the Arduino and MATLAB setup. Fig.13 and Fig.14 are the
corresponding output responses.

19
18.5
18
17.5
17

36

16.5

34

16

32

30
28

21

26

20
Ball's position (cm)

24
22
20
18
16

TABLE III. Cost Function

MSE
Simulation
Real-time

Ball's position (cm)

4
6
Time (sec)
Fig. 13. Output response of un-tuned fuzzy.

4
6
8
Time (sec)
Fig. 15. Regulatory response of un-tuned fuzzy.

19
18
17
16
15
14
13

920

6
8
10
Time (sec)
Fig. 16. Regulatory response of tuned fuzzy.

10

2014 International Conference on Circuit, Power and Computing Technologies [ICCPCT]

V.

CONCLUSION

From the results it is evident that the tuned fuzzy logic


controller has performed well when compared with the untuned fuzzy. From table 3 it is understood that the mean
squared error is reduced to a large extend by the SA tuned
fuzzy logic controller. In the regulatory response the time taken
by the ball to go back to the set point is smaller in tuned fuzzy
than the un-tuned fuzzy. Also it can be noted that the
magnitude of the random disturbance given is higher in case of
tuned fuzzy when compared to that of the un-tuned fuzzy. This
proves that the tuned fuzzy performs better than un-tuned. The
future work could be including the tuning of the rules and the
number of membership functions with the parameters of the
membership functions. This way a better FLC can be obtained
with less time. Simulated annealing is a slow process when
compared to other algorithms like genetic algorithm, particle
swarm optimization, etc however the probability of getting
stuck in a local minima is less in case of SA. The tuning of
FLC can also be experimented with these other algorithms.
APPENDIX
System details:

[8]

T. L. Seng, M. B. Khalid and R. Yusof, Tuning of a neuro-fuzzy


controller by genetic algorithm, IEEE Transitions on Systems and
Cybernetics, vo1.29, no.2, pp. 226-236, 1999.

[9]

Y. H. Shi, R. Eberhart, and Y. B. Chen, Implementation of evolutionary


fuzzy systems, IEEE Transactions on Fuzzy Systems, vol. 7, no. 2, pp.
109-119, 1999.

[10]

Cihan Karakuzu, Sitki ztrk, A Comparison of Fuzzy, Neuro and


Classical Control Techniques Based on an Experimental Application,
University of Quafaquaz, No. 6, pp 189-198,July 2000.

[11]

Von Altrock, "Fuzzy Logic and NeuroFuzzy Applications Explained",


Prentice Hall pp 82, 1995.

[12]

Evencio A. Rosales, A Ball-on-Beam Project Kit, Department Of


Mechanical Engineering, Massachusetts Institute of Technology, June
2004.

[13]

R.-E Precup , R.-C David , E. M. Petriu , S. Preitl and A. S. Paul A.


Gaspar-Cunha , R. Takahashi , G. Schaefer and L. Costa, Advances in
Intelligent and Soft Computing, vol. 96, pp. 141-50, 2011, SpringerVerlag.

[14]

Z.C. Johanyk, Student evaluation based on fuzzy rule interpolation,


International Journal of Artificial Intelligence, 5 (A10) (2010), pp. 37
55.

[15]

F. Nagi, L. Perumal, Optimization of fuzzy controller for minimum


time response, Mechatronics, 19 (3) (2009), pp. 325333.

Servo torque - 17kg/cm at 6V


Tharun Kumar S is a final year
undergraduate student of B.Tech in
Electronics & Instrumentation Engineering,
VIT University, Vellore. He is expected to
graduate in May 2014. His research interests
include measurements and instrumentation,
nonlinear control, neural networks and
embedded system.

Arduino Atmega328
Mass of the ball, M 300g
Radius of the ball, R 2cm
Lever offset,

d 7cm

Gravitational acceleration, g 9.8m2/s


Length of the beam, L 60cm

B. Jaganatha Pandian Assistant Professor


Sr., School of Electrical Engineering, VIT
University, Vellore. His Research areas of
interest are Machine learning, Nonlinear
Control,
System
Identification
and
Optimization.

REFERENCES
[1]

M. Amjad, KashifM.I., S.S Abdullah, Z.Shareef, Fuzzy Logic Control of


Ball and Beam System, 2nd International Conference on Education
Technology and Computer (ICETC), 2010.

[2]

Simulated Annealing.

[3]

Radu-Emil Precupa, Radu-Codrut David, Emil M. Petriu, Mircea-Bogdan


Radac, Stefan Preitl, Jnos Fodor, Evolutionary optimization-based
tuning of low-cost fuzzy controllers for servo systems, KnowledgeBased Systems 38 (2013) 7484.

[4]

Tahsin Alp Yanar, Zuhal Akyrek, Fuzzy model tuning using simulated
annealing, Expert Systems with Applications 38 (2011) 81598169.

[5]

Guixi Liu and Wanhai Yang, Learning and Tuning of Fuzzy


Membership Functions by Simulated Annealing Algorithm, IEEE AsiaPacific Conference on Circuits and Systems, 2000.

[6]

Claudio Moraga, Michio Sugeno, Enric Trillas, Optimization of fuzzy ifthen rule bases by evolutionary tuning of the operations, 39th
International Symposium on Multiple-Valued Logic, 2009.

[7]

Yeong-Hwa Chang, Wei-Shou Chan, and Chia-Wen Chang, T-S Fuzzy


Model-Based Adaptive Dynamic Surface Control for Ball and Beam
System, IEEE Transactions on Industrial Electronics, vol. 60, no. 6,
June 2013.

Available: http://www.mathworks.in/discovery/simulated-annealing.html

921

You might also like