You are on page 1of 8

This regular paper was presented as part of the main technical program at IEEE ETFA'2011

Implementation of Fuzzy Logic Control Based on PLC

Jiri Kocian, Jiri Koziorek, Miroslav Pokorny


VSB - Technical University of Ostrava
Department of Measurement and Control
17. listopadu 15/2172
708 33 Ostrava, CZ
jiri.kocian1@vsb.cz, jiri.koziorek@vsb.cz, miroslav.pokorny@vsb.cz

Abstract The goal of this work is to design own universal


fuzzy control function block and own universal fuzzy
A substantial portion of the literature on fuzzy control expert system function block which cover all necessary
deals with the usage of fuzzy rules to implement PID type industrial functions and possibilities mentioned above.
control and also fuzzy supervisory control. Chapter 2 contains a description of the designed
Fuzzy models have received significant attention from control system with fuzzy PS/PD regulator and with the
various fields of interest. Especially so called the visualization made in Intouch.
Takagi-Sugeno-type fuzzy model which superbly Chapter 3 contains a description of the designed
describes a nonlinear system. control system with fuzzy expert system in PID control
In this paper we present implementation of universal and with the visualization made in Intouch.
fuzzy PS/PD function block implemented to the PLC Description of implementation details of with fuzzy
Simatic S7 300/400. We also present implementation of expert system function block and PID regulazor function
universal function block of fuzzy expert system and PID block is in chapter 3.3.
regulator for PLC Simatic S7 300/400.
Control system with implemented fuzzy expert system 2. Control system with fuzzy regulator
and PID regulator and control system with implemented
PS/PD regulator with visualizations are designed. Control system with fuzzy PS/PD/PSD regulator is
designed.
1. Introduction Block diagram of the control system is shown on
Fig. 1. The control system consists of programmable
The aim of this work is design and implementation of controller CPU 315-2 DP which is connected to the
universal function block of fuzzy regulator PS/PD and communication processor CP 343-1 Advanced.
design of own universal fuzzy expert system function Communication processor communicates with the
block for PLC Simatic S7 300/400. visualization created in InTouch through an Ethernet
Many papers deal with fuzzy expert systems or fuzzy communication interface.
supervisors that provide adaptation of PID regulator.
Fuzzy supervisors generally monitor step responses of
closed loop and according measured variables PID
regulator constants are recalculated. This approach is
discussed in [2], [3]. [4], [6], [7]. Practical case studies
of fuzzy gain scheduling as a supervisory control
function implementation are in [5], [8], [9]. Online
stochastic analysis approach of closed loop and case
study of adaptive bioreactor control is given in [1]. Figure 1. The block scheme of the control
Generally, there are also a lot of implementations of system with fuzzy regulator.
fuzzy control to the PLC. [11]
Nearly all PLC producers offer fuzzy control 2.1 Implementation of fuzzy regulator PS/PD/PSD
functions in their portfolio. But a lot of these solutions Function block for Siemens Simatic S7 300/400 has
do not cover all possibilities that may occur when using, been implemented to be used in described control
e.g. dead band for regulation error, manipulated value system.
limitation, manual control mode etc. Therefore, if you Fuzzy controller function block uses auxiliary
need to apply these functions you have to program it function Fuzzification. This function was implemented
yourself. for degrees of membership evaluation of the error or

978-1-4577-0018-7/11/$26.00 2011 IEEE


the first difference of the error in order to known sets procedure also checks the coordinates of fuzzy sets so
coordinates. that any bad assignment of fuzzy sets and no fatal impact
Function Fuzzification is called by internal code of to the regulation function should be applied. If errors are
function block. When using fuzzy controller function detected in the coordinates of fuzzy sets during
block, function Fuzzification has to be copied to the initialization procedure, the control is stopped and
project. indication of wrong is appeared in function block output
Fuzzy controller can be PS or PD according to a (can be displayed on the visualization).
logical value of function block input Sel_PS_PD
(Sel_PS_PD in log. 0: PS regulator, Sel_PS_PD in log. Regulation error
1: PD regulator). NB NM NS Z PS PM PB
For regulation error the first difference of regulation NB 1 2 3 4 5 6 7
error and for and manipulated value (in the case of NB NB NB NB NM NS AZ
fuzzy PS regulator the first difference of manipulated

First difference of regulation error


NM 8 9 10 11 12N 13 14P
value ) are implemented weighting factors ( , , NB NB NB NM S AZ S
, ). When selecting the type of fuzzy PD regulator NS 15 16 17 18 19 20 21
the error is multiplied by factor and the first NB NB NM NS AZ PS PM
difference of the error by factor. On the other Z 22 23 24 25 26 27 28
hand when selecting a fuzzy PS regulator the error is NB NM NS AZ PS PM PB
multiplied by factor and the first difference of the PS 29 30 31 32 33 34 35
error by factor. NM NS AZ PS PM PB PB
Structure (1) is generally applied for fuzzy PD PM 36 37 38 39 40 41 42
regulator and structure (2) is generally applied for fuzzy NS AZ PS PM PB PB PB
PS regulator.
PB 43 44 45 46 47 48 49
(1) AZ PS PM PB PB PB PB

(2) Table 1. Fuzzy rules.


Manipulated value calculation for the fuzzy PD
regulator is in (3) and for the fuzzy PS regulator in (4). To suppress a small constant oscillation due to the
manipulated value quantization (for example due to a
(3) limited resolution of the manipulated value by the
(4) actuator valve) a dead band is applied to the error signal
The range of control error and the first difference of of the controller.
the error is divided to seven fuzzy sets (NB - Regulation error and the first difference of
Negative Big, NM - Negative Medium, NS - Negative regulation error are then fuzzified by function
Small, AZ - Approximately Zero, PS - Positive Small, Fuzzification.
PM - Positive Medium, PB - Positive Big). After fuzzy inference defuzzification procedure starts.
Manipulated value is expressed by crisp numbers Manipulated value is calculated according (5) and then
and also takes seven values (NB, NM, NS, AZ, PS, PM, limited to the Hi_Lim and Lo_Lim limits and the
PB). resulting control value is then sent to the output. The last
Fuzzy rules used for fuzzy PS/PD regulator are shown step is to determine the dominant rule and the value of
in Tab. 1. Takagi-Sugeno method was used for inferring dominant rule (degree of membership of dominant
the manipulated values (5). value). Dominant rule number and value of dominant
rule is copied to the output (and displayed on the


, where (5) visualization).
Crisp valu in accordance with the rule at the table It is possible to switch over two modes: an automatic
rules. and a manual mode. The set point is taken from block
- Degree of membership. It is given as a minimum input to fuzzy calculation procedure in automatic mode.
degree of membership of members of the antecedent The manipulated value is in manual mode directly
(corresponding to the logical AND in the antecedent). copied from the block input through manipulated value
- Calculated manipulated variable. limitation to manipulated value output.
Fuzzy regulator is inserted into the program and The block scheme of implemented function block is
instance data block is generated. on Fig. 2. The scheme of fuzzy PS/PD regulator in
Fuzzy regulator contains an initialization procedure control system is on Fig. 3. Fuzzy PS/PD regulators can
that will get the coordinates of fuzzy sets , and crisp be also connected as shown on Fig. 4 to make complete
numbers of manipulated value from input structures into fuzzy PSD regulator.
static structures of the fuzzy controller. Initialization
2.2 Visualization
Visualization system was created in InTouch.
The visualization application consists of several
windows, which are logically arranged. The main
window of visualization (Fig. 7) is a central window that
displays key information.
Setpoint switch switches automatically generated and
manual setpoint. There is also a fuzzy controller switch
between manual and automatic mode of fuzzy regulator.
In the middle part of the window are switches for
initialization procedure and fuzzy regulator type: PS or
PD type. Number of dominant rule and its value are
Figure 2. The block scheme of fuzzy PS/PD displayed in the right panel. From the main window, you
regulator. can get to the window with real time trend or to the
window with historical trend. In addition there are also
other windows: window for users access, window for
fuzzy regulator settings, window for simulated control
system setting and window with information about the
application.
Many controlled systems were tried to control.
Figure 3. The scheme of fuzzy PS/PD regulator.
Simple example is shown on Fig. 6. This controlled
system has transfer function (6). All tried controlled
systems are simulated in PLC by mathematical functions
and function blocks.
(6)

Figure 4. The scheme of fuzzy PSD


regulator.
The interface of the implemented function block is
shown on Fig. 5.

Figure 6. Real time trend.

3. Control system with PID control and


fuzzy expert system

Many controlled systems are nonlinear systems.


Successful control of system with nonlinear
characteristic is very difficult. Linearization around
working point has to be made. If the nonlinear system
has to be operated in several different operating points or
regulated system has significantly nonlinear behaviour
then constant values of PID regulator parameters cannot
lead to good control quality in required operating range.

Figure 5. Fuzzy PS/PD regulator.


Figure 7. The main visualization window of fuzzy control system.

A method of switching sets of parameter values is one


of possible solutions which can be used in these
situations. Several approaches can be used to switch
values sets of the PID regulator depending on the
operating point.
The contribution shows an example of a fuzzy expert
system for the adaptation of PID regulator based on the
selected operating point. The suggested sets of PID
regulator parameters are placed into a function block of
Figure 8. The block scheme of the control
an expert system. Sets of PID regulator parameters are
system with fuzzy expert system.
then send to PID regulator depending on current working
point of the controlled system. This allows a constant
adjustment of PID regulator constants when process
value is moving between operating points.
Block diagram of the control system is shown on
Fig. 8. The control system consists of programmable
controller CPU 315-2 DP which is connected to the
communication processor CP 343-1 Advanced.
Communication processor communicates with the Figure 9. The principal scheme of fuzzy
visualization created in InTouch through an Ethernet expert system with PID regulator.
communication interface.
The control loop scheme of fuzzy expert system with 3.1 Configuration of fuzzy expert system and
PID regulator is shown on Fig 9. Controlled system PID regulator
transfer function is simulated by mathematical blocks of Stable static system with a transfer function (7) is
standard library in Step 7 software. Process value is chosen as a controlled system.
except PID regulator also input to the fuzzy expert
system function block.
(7) 3.2 Visualization

Visualization system is created in InTouch. The
Transfer function with changing static gain is selected
visualization application consists of several windows,
to achieve the desired characteristics of the controlled
which are logically arranged. The main window of
system suitable for testing the fuzzy expert system. The
visualization (Fig. 13) is a central window that displays
static gain depends on the process variable as is shown in
key information. The main part of the window is control
Tab. 2.
loop with control loop value: Set Point, Manipulated
Value, Manipulated Value in Test/Direct Mode, Process
Process Value Controlled system parameters Value and PID regulator constants set by fuzzy expert
KS T1 T2 system to PID regulator: K P , TI and TD .
<0; 30> 2,0 16,0 2,0 Set Point switch switches automatically generated and
<30; 50> 1,0 16,0 2,0 manual Set Point. There is also a fuzzy expert system
<50; 70> 0,75 16,0 2,0 switch between manual and automatic mode.
<70; 100> 0,5 16,0 2,0 In the middle part of the window there is a switch for
initialization procedure of fuzzy expert system. Number
Table 2. Controlled system parameters.
of dominant operation point and its value (degree of
Operation points of regulation are set according membership) are displayed in the right panel. From the
Tab. 2: 20.0, 40.0, 60.0 and 80.0. main window, you can get to the window with real time
Coordinates of fuzzy sets and corresponding PID trend or to the window with historical trend.
regulator constants dedicated from Tab. 2 are shown in In addition there are also other windows: window for
Tab. 3 and Tab. 4. Coordinates of fuzzy sets are also on users access, window for fuzzy expert system settings,
Fig. 10. PID regulator constants are calculated according window for simulated control system setting and
Ziegler-Nichols tuning rules from step response for window with information about the application. Fig. 11
every value of K S in transfer function (7). (real time trend window) shows sample regulation over
Implemented PID regulators have purely parallel different operation points in regulation range.
form with filtration of derivation part (8). Detailed
information of implemented PID regulator function
block are in Chapter 3.4.

(8)

Fuzzy sets
1. 2. 3. 4.
WP 1 0,0 0,0 20,0 40,0
WP 2 20,0 40,0 40,0 60,0
WP 3 40,0 60,0 60,0 80,0
WP 4 60,0 80,0 100,0 100,0
Figure 11. Real time trend.
Table 3. Working points with fuzzy sets.
3.3 Implementation details of fuzzy expert system
PID regulator constants The interface of the implemented fuzzy expert system
KP TI TD function block is shown on Fig. 12.
WP 1 8,9274 0,2730 5,2219
WP 2 17,2548 0,1412 10,0929
WP 3 22,8065 0,1069 13,3402
WP 4 33,9097 0,0719 19,8348

Table 4. Working points and PID constants.

Figure 10. Working points and fuzzy sets. Figure 12. Implemented function block of
fuzzy expert system.
Figure 13. The main visualization window of fuzzy expert system.
The implemented fuzzy expert system processes , - Value of the PID derivative part of i-th
Process Value in its fuzzy algorithm. Process Value fuzzy set (working point).
can cover the operating range of up to eight fuzzy sets , - The calculated derivative part of the
representing up to eight working points. Two fuzzy PID controller
sets representing two working points are minimum - Number of fuzzy sets (number of working
number of fuzzy sets. Fuzzy sets names have general points).
meaning: from Working point 1 to Working point 8. - The degree of membership of the
Each fuzzy set is determined by four coordinates and controlled variable of i-th fuzzy set.
can be form as trapezoid fuzzy set or triangular fuzzy
set. Coordinates of the fuzzy sets and sets of PID
PID constants are calculated (8) - (10) by Takagi- regulator parameters are inputs of fuzzy expert system.
Sugeno defuzzification method. Fuzzy expert system includes an initialization

procedure (input InitFuzzy) that will get the
,
,
(8) coordinates of fuzzy sets and sets of PID regulator
parameters from input structures into static structures
of the function block of fuzzy expert system.
,
, (9) Coordinates of fuzzy sets and sets of PID regulator

parameters are also checked during the initialization
procedure because wrong coordinates (wrong order of
, fuzzy sets coordinates etc.) of fuzzy sets can have a
, (10)
fatal impact to manipulated value calculation. If any
, - Value of the PID proportional part of i- errors are detected during initialization procedure these
th fuzzy set (working point). errors are then indicated at the output of function block
, - The calculated proportional part of PID outputs InSetsOK, PIDConOK, NmbrOfPntsOK (and
controller. shown on visualization).
, - Value of the PID integral part of i-th The input value is fuzzificated by the function
fuzzy set (working point). Fuzzification degrees of membership of Process
, - The calculated integral part of PID Value are calculated depending on coordinates of fuzzy
controller sets.
Furthermore, on the basis of (8) - (10) PID constant
calculated and transmitted to the PID regulator
function block.
So-called manual control mode is also implemented
to expert fuzzy (input Man). Fuzzy expert system can
be switched to manual control mode and PID regulator
parameters from function block input are directly
copied to the output (to the PID regulator).

3.4 Implementation details of PID regulator

PID algorithm of designed PID regulator operates as


a position algorithm. Proportional, integral and
derivative actions are connected in parallel form and
can be activated or deactivated individually by setting
zero to K P and/or TI and/or TD constants. This
allows P, PI, PD, and PID regulator to be configured.
Pure I and D regulators are also possible but not
recommended.
Implemented PID regulators have purely parallel
form with filtration of derivation part (8). Although
transfer function (8) is not so often implemented in
commercial PLC it brings some advantages. Figure 15. The simplified function block
To suppress a small constant oscillation due to the scheme of the implemented PID
regulator.
manipulated value quantization (for example due to a
limited resolution of the manipulated value by the
actuator valve) a dead band is applied to the error 4. Conclusion
signal of the controller. Transfer function of PID
regulator is in a component recursion form with With the development of PLC, improving the
filtration of derivate action value by a discrete analogy operation speed and function unceasing enhancement,
of continuous low pass filter. The PID regulator PLC has been applied in many fields, and achieved
implements the control law with two degrees of many functions modular.
freedom and anti-wind up. The main goal of this work is design and
The simplified function block scheme of the implementation of universal function block of fuzzy
implemented PID regulator is on Fig. 8. The interface regulator PS/PD and design and implementation of
of the implemented function block of PID regulator is universal function block of fuzzy expert system for
shown on Fig. 9. PLC Simatic S7 300/400.
Implementation details of fuzzy regulator PS/PD
function block and description of the designed control
system with fuzzy PS/PD regulator and with the
visualization made in Intouch is introduced.
The contribution shows an example of a fuzzy
expert system for the adaptation of the PID regulator
parameters based on the selected working point. This
approach can be appropriate for systems with nonlinear
characteristic which have to be controlled in several
operating points. The suggested sets of PID regulator
parameters are placed into the function block of the
expert system. Sets of the PID regulator parameters are
then send to the PID regulator depending on current
working point of the controlled system and according
degree of membership of process value to coordinates
of fuzzy sets. This allows a constant adjustment of PID
Figure 14. The simplified function block
regulator constants when process value is moving
scheme of the implemented PID
regulator. between operating points.
Acknowledgements [11] Aydogmus, Z.: Implementation of a fuzzy-based level
control using SCADA. In Expert Systems with
This work is supported by project SP2011/45, Data Applications. Volume 36, Issue 3 Part 2, April 2009,
acquisition and processing from large distributed Pages 6593-6597. ISSN: 09574174.
systems of Student Grant System, VSB-TU Ostrava [12] Tutsch, M., Machacek, Z., Krejcar, O., Konarik, P.:
and also by the company of Ingeteam a.s. Ostrava. Development Methods for Low Cost Industrial Control
by WinPAC Controller and Measurement Cards in
References Matlab Simulink, In Proceedings of Second
International Conference on Computer Engineering and
[1] Babuska, R., Damen, M., R., Hellinga, C., Maarleveld, Applications, ICCEA 2010, 19. - 21. March 2010, Bali
H.: Intelligent adaptive control of bioreactors. In Island, Indonesia, Volume 2, NJ. IEEE Conference
Journal of Intelligent Manufacturing. Vol. 14, Num. 2, Publishing Services, 2010 pp. 444-448, ISBN 978-0-
p. 255-265, DOI> 10.1023/A:10229637/16905. 7695-3982-9, DOI 10.1109/ICCEA.2010.235.
[2] Chand, S.: On-line, self-monitoring tuner for [13] Kocian, J., Koziorek, J.: An Outline of Advanced
proportional integral derivative controllers. In Decision Regulation Techniques on PLC Background and
and Control, 1991. Proceedings of the 30th IEEE Control Systems with Self Tuning Methods Design. In
Conference. Brighton, UK. DOI: PDES 2010: Proceedings of 10th IFAC International
10.1109/CDC.1991.261746. ISBN: 0-7803-0450-0. Workshop on Programmable Devices and Embedded
[3] Van Nauta Lemke, H., R., Wang de-Zhao: Fuzzy PID Systems, Pszczyna, Poland, October 06 08, 2010, p.
Supervisor. In Decision and Control, 1985. 143-148. Pszczyna, Poland.
Proceedings of the 24th IEEE Conference. DOI: [14] ODwyer, A., 2003. Handbook of PI and PID
10.1109/CDC.1985.268559. Controller Tuning Rules. Imperial College Press.
[4] Kanagaraj, N., Sivashanmugam, S., Paramasivam, S.: London, 375 pages. ISBN: 1-86094-350-0.
A Fuzzy Logic Based Supervisory Hierarchical Control
Scheme for Real Time Pressure Control. In Internation
Journal of Automation and computing. Vol.6, 2009,
ISSN: 1751-8520.
[5] Zhen-Yu Zhao, Tomizuka, M., Isaka, S.: Fuzzy Gain
Scheduling of PID Controllers. In IEEE Transactions
on Systems and Cybernetics. Vol. 23, Issue 5, p. 1392-
1398. ISSN: 0018-9472.
[6] Sanjuan, M., Candel, A., Smith, C., A.: Design and
implementation of a fuzzy supervisor for on-line
compensation of nonlinearities: An instability
avoidance module. Published in Journal Engineering
Applications of Artifical Inteligence. Vol. 19, Issue 3,
April, 2006. Pergamon Press, Inc. Tarrytown, NY,
USA. DOI: 10.1016/j.engappai.2005.09.003.
[7] Kazemian, H., B.: The SOF-PID Controller for the
Control. IEEE Transaction on Fuzzy Systems, Vol. 10,
No. 4, August 2002.
[8] Wang, W., Han-Xiong Li, Zhang, J.: Intelligence-
Based Hybrid Control for Power Plant Boiler of a
MIMO Robot Arm. IEEE Transaction on Fuzzy
Systems, Vol. 10, No. 2, March 2002.
[9] Kanagaraj. N., Sivashanmugam. P.: Intelligent Fuzzy
Coordinated Control Scheme for Pressure Control
Process. In International Conference on Computational
Intelligence and Multimedia Applications, 2007. ISBN:
0-7695-3050-8.
[10] Kocian, J., Koziorek, J.: An Outline of Advanced
Process Control and Self Tuning Techniques on PLC
Background. In ETFA 2010: Proceedings of IEEE
International Conference on Emerging Technologies
and Factory Automation, Bilbao, Spain, September 13
- 16, 2010. ISBN 978-1-4244-6849-2.

You might also like