You are on page 1of 6

Water Level Control by Fuzzy Logic and Neural

Networks
Daniel Wu Fakhreddine Karray Insop Song
Dept. of Systems Design Eng. Dept. of Electrical & Computer Eng. Dept. of Systems Design Eng.
University of Waterloo University of Waterloo University of Waterloo
Waterloo, ON N2L 3G1 Waterloo, ON N2L 3G1 Waterloo, ON N2L 3G1

Abstract— The objective of this paper is to investigate and find


a solution by designing the intelligent controllers for controlling
water level system, such as fuzzy logic and neural network. The Sensor
controllers also can be specifically run under the circumstance
of system disturbances. To achieve these objectives, a prototype Water Level
of water level control system has been built and implementations
of both fuzzy logic and neural network control algorithms are Valve2
performed. In fuzzy logic control, Sugeno model is used to Water Tank
3

control the system. In neural network control, the approach of 2 3

Model Reference Adaptive Neural Network Control based on the Pump Servor
Motor
backpropagation algorithm is applied on training the system. Valve3 Valve1
Both control algorithms are developed to embed into a stand-
alone DSP-based micro-controller and their performances are
compared.
DSP Controller
I. I NTRODUCTION
Traditionally, accurate mathematical model-based strategies Fig. 1. Configuration of the Water Level Control System. The system consists
of the servo motor, valves, a pump, a infra-red sensor and a DSP controller.
have been applied to deal with control problems. However,
water level control system, for example, is very complex
system, because of the nonlinearities and uncertainties of a non-crystalloid [5].
system. Conventional control approaches are not convenient In this paper, we first elaborate the configuration of the
to solve the complexities. Fuzzy logic and neural networks water level control system. Then, we introduce Sugeno fuzzy
control have emerged over the years and become one of the control [7], [8] and model reference adaptive neural network
most active and fruitful areas of the research in the intelligent control (MRANNC) [6], [9], [10] strategies based on back-
control applications. There are two major different types of propagation algorithm. Finally, some experimental and real-
the control rules in fuzzy control: the Mamdani type and the time results using DSP controller are presented.
Sugeno type. The Mamdani control rules are significantly more
linguistically intuitive while Sugeno rules appear to have more II. S YSTEM C ONFIGURATION
interpolation power even for a relative small number of control Figure 1 shows the system configuration. The system con-
rules. In neural network control, the most commonly used sists of the servo motor, valves, a pump, a infra-red sensor and
ones are supervised control, direct inverse control and neural a DSP controller. Water is constantly pumped into a vertical
adaptive control. tube by a pump. Water can outflow from the horizontal tube.
There are many papers addressed the fuzzy or neural The general control objective is to reach and stabilize a certain
networks control in the water or liquid level control system. water level in the vertical tube. As shown in the figure, a
Niimura et al. utilized the fuzzy logic for water level control in sensor measures the water level and sends height signal to
small hydro-generating units[1]. Roubos et al. chose Sugeno the DSP micro-controller. The controller controls the servo
fuzzy model as the model structure for a linear model based motor, which adjusts the valve 1 to maintain a desired water
predictive control of the liquid level [2]. Ghwanmeh et al. level in the vertical tube. Valve 2 constantly opens and valve 3
showed a self-learning fuzzy logic control applied to a non- randomly opens to provide disturbances to the control system.
linear process and demonstrated the robust and repeatable
performance [3]. Naman et al. presented an adaptive model-
reference fuzzy controller for controlling the water level in a III. F UZZY L OGIC C ONTROL
water tank [4]. Xiao et al. provided a backpropagation neural In Fuzzy control, two inputs for the system are chosen.
network algorithm used to adjust the parameters of the PID They are an error (e) and an error derivative (ė). The error
controller and control the liquid level of molten steel smelling is calculated by taking the difference between the reference
1 If e is HN OPEN valve WIDE
2 If e is N and ė is NOT P OPEN valve A BIT HN N S P HP
3 If e is N and ė is P LEAVE valve ALONE
4 If e is S and ė is N OPEN valve A BIT
5 If e is S and ė is S LEAVE valve ALONE
6 If e is S and ė is P CLOSE valve A BIT
7 If e is P and ė is N LEAVE valve ALONE -15 -5 -2 0 2 5 15
8 If e is P and ė is NOT N CLOSE valve A BIT
9 If e is HP CLOSE valve A LOT (a) Error Membership Functions
TABLE I
RULE BASE N S P

Output Functions
1 OPEN valve WIDE 900 · e + 0 · ė − 20 -4 -0.5 0 0.5 4
2 OPEN valve A BIT −50 · e − 200 · ė − 20
3 LEAVE valve ALONE −5 · e + 0 · ė + 0 (b) Error-Dot Membership Functions
4 CLOSE valve A BIT −50 · e − 2000 · ė + 20
5 CLOSE valve A LOT −100 · e + 0 · ė + 20
error
TABLE II
O UTPUT F UNCTIONS . HN N S P HP
N 1 2 2 3 5
error_dot
S 1 2 3 4 5
P 1 3 4 4 5
signal and the current water height. The error derivative is
calculated by subtracting a previous error from the current (c) Mapping
error. The output of the system is a voltage that is sent to a
servo motor to control the valve 1.
Fig. 2. Membership Functions and Mapping
The Sugeno model is used in the system. The Sugeno model
is computationally efficient, and works well with optimization
and adaptive techniques, so it is popular for control problems, ei -
in particular for dynamic nonlinear systems. The Sugeno fuzzy NN yi ec
identifier
model takes the form: - +
ec TDL TDL ei
IF e is A AND ė is B, THEN SERVO is f (e, ė) +
r (t ) TDL yp
NN u Nonlinear
controller
The output function f (e, ė) takes the form: Plant

TDL TDL
A2 e + A1 ė + A0

The parameters of the output function A2 , A1 , and A0 can


be modified through the micro-controller interface.
Fig. 3. Neural Network Control in Water Level Control Systems, TDL
The rule base used here is shown in Table I. Five mem- denotes time delays of the input or output signals.
bership functions for the error are shown in Figure 2(a),
and three for the error derivative are shown in Figure
2(b). The rules mapping is shown in Figure 2(c). Labels 3 shows the control structure. TDL in Figure 3 denotes time
in Table I and Figure 2 are as follows: HN=High Nega- delays of the input or output signals.
tive;N=Negative;S=Small;P=Positive; HP=High Positive;
For the Sugeno model, output functions must be defined. A. Neural Network for Identifier
This will decide how the system provides the proper control The neural network for identifier is designed as a three-
through the manipulation of the valve 1. Table II shows the layer neural network. It has a input layer, a hidden layer,
output functions and nominal tuning values that the controller and an output layer. Nii ,Nji and Nki are their output values
uses on start up. Each of these parameters can be modified respectively. The neuron numbers in the hidden layers can be
using the user interface of the micro-controller. chosen depending on the practical training result.
The neural network identifier models are trained to learn the
IV. N EURAL N ETWORK C ONTROL
forward dynamics of the plant. Six inputs and one output are
In this paper, the Model Reference Adaptive Neural Net- selected as the identifer model for the system. These six inputs
work Control approach based on backpropagation algorithm are the control signals: u(t − i), i = 0...2, and the previous
is applied to implement the water level control system. Figure output signals: y(t − j), j = 1...3. These signals provide the
current and previous two control signals, and also incorporate N ic N cj
N kc N ij
in the historical trend from the last three time steps of the N ii
N ki
output of the system. A set of corresponding input-output
training patterns is selected from the open-loop continuous wcji wkjc
wiji wkji
signal response of the system. The control input signal is
directly added to servo motor of the system and system output
NN Contorller NN identifier
signal is reflected with the sensor, which is actual water level.
In training a neural network to learn a forward dynamic
model of a plant, the backpropagation error signal between Fig. 4. The Connection Between the Controller and the Identifier
the output and the hidden layer is expressed as

δk = Tk − Nki (1) To illustrate the derivation of the error signals for the neural
network controller, Figure 4 provides the connections between
where Tk is the target pattern and Nki is the actual output of the controller and identifier networks.
the identifier, and between the hidden and input layers, it is The adaptation of the weights of the neural network con-
expressed as X troller between the hidden and output layers can be derived as

δj = f (netj ) δk · wkj (2) follows:
k c ∂E i
∆wkj =η· c (6)

Here, f (netj ) is the derivative of the activation function ∂wkj
f (netj ) where where
1
f (netj ) = (3) 1
1 + exp(−netj ) Ei =
· (yp − r)2 (7)
2
The weights between the input and hidden layers are updated where yp and r are the actual and desired plant output. The
as superscript c denotes the variables belonging to the neural
∆wji (t + 1) = η · δj · Nii + α · ∆wji (t) (4) network controller and superscript i denotes the variables
and the weights between the hidden and output layer are belonging to the neural network identifier.
updated as Using chain rule, equation (6) can be expanded as follows:

∆wkj (t + 1) = η · δk · Nji + α · ∆wkj (t) (5) c ∂E i ∂netck


∆wkj =η· ·
∂netck ∂wkj
c
where Nii and Nji are the outputs of the input and hidden
so
layers, respectively, η is the learning rate, and α is the c
∆wkj = η · δkc · Njc (8)
momentum coefficients. The constants η, α are all chosen
empirically. where
∂E i
B. Neural Network for Controller δkc =
∂netck
The neural network controller is created directly based on
and
the neural network identifier. Its design is fully incorporated ∂netck
the learning strategy into the trained identifier. The weights Njc = c
∂wkj
of the neural network identifier are constantly verified against
the actual plant output. This ensures that the weights allow δkc is the error signal between the hidden and output layers
the neural network identifier to properly predict actual plant of the neural network controller. Linear functions are used at
output. The neural network identifer is used as means to the input and output neurons of the neural networks between
backpropagate the performance error to get the equivalent error the controller and identifier. Therefore, δkc can be represented
at the output of the neural network controller. as follows:
The accuracy of the plant model is critical in ensuring that ∂E i ∂E i ∂E i
the controller is accurate as well. The error between the plant δkc = = = (9)
∂Nkc ∂netii ∂Nii
output and the identifier output is also checked for the accuracy
level of the identifier. This error is used to backpropagate and where netii and Nii are the input and output of the identifier
adjust the weights of the identifier to provide the most accurate input layer neurons. Further using chain rule
representation of the plant. The neural network for controller
∂E i ∂netij
is also designed as a three-layer neural network. It has a input δkc = · (10)
layer, a hidden layer, and an output layer. Nic , Njc and Nkc are ∂netij ∂Nii
their output values respectively. The neuron numbers in the Hence,
hidden layers can be chosen also depending on the practical ∂E i
= δji
training result. ∂netij
NN In ni nj nk η α Plant Disturbance Training Data Y
Identifier 6 10 1 0.00001 0.8
4.5 U
Controller 10 20 1 0.00005 0.65
4

3.5
TABLE III
3
PARAMETERS S ETUP

Voltage (V)
2.5

1.5

and 0.5

∂netij i
0

= wji 1 201 401 601 801 1001 1201 1401


Sample
1601 1801 2001 2201 2401 2601

∂Nii
so,
Fig. 5. Plant Disturbance Training Data, U is an input signal and Y is a
δkc = δji · wji
i
(11) output of the sensor

The error signal between the input and hidden layer of the Plant Test Data Y

neural network controller can be derived as follows: 4.5


U

∂E i
∂E i ∂Njc 4

δjc = c = · (12) 3.5

∂netj ∂Njc ∂netcj 3

2.5

Voltage (V)
By using chain rule 2

1.5

∂E i X ∂E i ∂netc 1
k
c = ·
∂Nj ∂netck ∂Njc 0.5

0
1 401 801 1201 1601 2001 2401 2801 3201 3601 4001 4401 4801 5201 5601
-0.5
and Sample

∂Njc ′
= f (netcj )
∂netcj Fig. 6. Plant Test Data

where

f (netcj ) = Njc · (1 − Njc ) 2) Identifier Training and Testing: The trained identifier
will be used as a representation of the system plant to
so, effectively create a controller for the system. Then, the off-
X line training of the controller will be feasible to reach.
δjc = Njc · (1 − Njc ) · ( δkc · wkj
c
) (13) 1. Training Data
An open loop system was used to obtain a system response
The weights of the neural network identifier can be further curve for the plant response to a random input signal. Figure
improved online if necessary. This can be reached by back- 5 shows the input signal used for training of the NN iden-
propagation of the following error equation through the neural tifier. This was done by sending a voltage signal through a
network identifier at every sample. yp and yi are the outputs potentiometer into the servo motor, and it controls the valve
of the actual plant and neural network identifier, respectively. 1. By creating a random input control signal and measuring
the sensor output while a random and a constant disturbance
1
e= · (yp − yi )2 (14) exists. A set of data was created and indicated the behavior
2 of the plant response to a characteristic input signal. It was
V. E XPERIMENTAL R ESULTS designed to fall within the operating range of the sensor. As
shown in the figure, the input signal u varies between values
The neural network control algorithm were first trained and
of 2V and 4V .
tested with C language with a normal PC. Then, the algorithm
2. Testing Data
were ported to DSP-based controller and tested. Once the training portion of the Identifier is completed, it
needs to be verified with the training results. A selection of
A. Training and Testing for Neural Network Control
similar data was created for testing the trained network. Figure
1) Parameters Setup: In order to have quicker calculation 6 shows a set of testing data used for the Identifier.
without sacrificing performance, some parameters were setup 3. Identifier Training
as shown in Table III. In Table III, ni ,nj and nk denote Identifier training resulted to a level of error of 7.9842
the number of nodes in the input layer, hidden layer and after 150,000 epochs. At the cut-off of 150,000 epochs, the
output layer, respectively, η and α denote learning rate and identifier was still converging on an error, but extremely
momentum term, respectively. slowly. Then, this level of an error was used to move onto
Identifier Training Error Controller Training Data
Error Desired
1000 35

30

25
100

Water Level (cm)


Error (V)
20

15

10
10

1 0
100 1000 10000 100000 1000000 1 101 201 301 401 501 601 701 801 901 1001 1101 1201 1301
Epoch Test Sample

Fig. 7. Identifier Training Error Fig. 9. Controller Training Data

Identifier Test Data U Controller Test Data


Y Test Data
4.5
Y-PRED 40

35
4

30
3.5

Water Level (cm)


3 25

2.5 20
Voltage (V)

2 15

1.5 10

1 5

0.5 0
1 26 51 76 101 126 151 176 201 226 251 276 301 326 351 376
0 Sample
1 501 1001 1501 2001 2501 3001 3501 4001 4501 5001 5501
-0.5
Epoch

Fig. 10. Controller Testing Data

Fig. 8. Identifier Testing Results

completed, it needs to verify that training. A set of data


controller training. Figure 7 shows the trend of decreasing was selected for testing the controller training. Since the
error in the identifier training. training data used was designed to be a component of typical
4. Identifier Testing operational values, a similar set of data was created for testing
The error seen as a result of testing is shown in Figure 8. the trained network.
Since the level of error seen is on the same scale of that for the 3. Controller Training
training, then moving to controller training became the next In Figure 11, convergence towards the goal of small error
step. It is believed that a more rigorous training could result is clearly seen in the controller training algorithm. However,
in better error and better performance for controller training the error does not reach the desired cut-off. Despite this, the
and final implementation. weights trained as a result of this training provide a very good
3) Controller Training and Testing: In order to effectively response when the testing data is used to evaluate the controller
create a controller for the system, the existing system was weights.
analyzed in an off-line setup. The goal in the project is 4. Controller Testing
to develop a controller through simulation and use more As shown in Figure 12, the weights for both the identifier
computer resources in a highly effective manner. It proved far and controller had been trained to a level that provided an
more effective to design the training and testing in an off-line acceptable level of prediction, and showed that the controller
format. was working as expected.
1. Training Data
Figure 9 shows the reference signal used for training of the Controller Training Error
neural network controller. It was designed to maintain a level 1000
Error

within the operating range of the sensors. A random signal


was created that would provide the controller with typical 100

values that a user could choose during normal operation. These


Error (V)

values were held within the ideal operating range for which
10

the identifier was trained.


2. Testing Data
1

Figure 10 shows a set of testing data used for the neural 0 1000 2000 3000 4000 5000 6000 7000 8000

Epoch
network controller. As can be seen, this pattern is somewhat
similar to that seen in the training. As was the case in
the identifier, once the training portion of the controller is Fig. 11. Controller Training Error
Neural Network Control Results
Controller Test Data Setpoint
R Sensor1
30
Y
1.4

25
1.2

1 20

Water Level (cm)


Voltage (V)
0.8
15

0.6
10

0.4

5
0.2

0
0

17

25

33

41

49

57

65

73

81

89

97

105

113

121

129

137

145

153

161

169

177

185

193

201

209

217
1 26 51 76 101 126 151 176 201 226 251 276 301 326 351 376
Time (s)
Sample

Fig. 12. Controller Testing Fig. 14. Online Neural Network Control Result

Fuzzy Control Result Sensor


Setpoint comparisons between the two control schemes based on the
30
experimental results.
25

FLC NNC
20
Plant Math Model Unnecessary Unnecessary
Water Level

15
Computation Light Heavy
Tracking Performance Good Better
10 Disturbance Rejection Good Better

5
TABLE IV
C OMPARISON BETWEEN THE FUZZY CONTROL AND NEURAL NETWORK
0
CONTROL BASED ON THE EXPERIMENTAL RESULTS
1

11

21

31

41

51

61

71

81

91

101

111

121

131

141

151

161

171

181

191

201

211

221

231

Time (s)

Fig. 13. Online Fuzzy Control Result


R EFERENCES
[1] Niimura, T. and Yokoyama, R., “Water level control of small-scale hydro-
generating units by fuzzy logic”, Proceedings of IEEE Int’l Conference
B. Experiments on micro-controller on Systems, Man and Cybernetics, pp. 2483, 1995.
The fuzzy and neural network control algorithms were [2] Roubos,J.A., Babuska,R., Bruijn,R.M. and Verbruggen,H.B., “Predictive
Control by Local Linearizatin of a Takagi-Sugeno Fuzzy Model”, IEEE
ported to a stand-alone VRP MTSC32 micro-controller. The Transactions, 1998.
main board of micro-controller is based on Texas Instruments’ [3] Ghwanmeh,S.H., Jones,K.O. and Williams,D., “On-line Performance
TMS320C32 DSP with a CAN bus communication port that Evaluation of a Self-Learning Fuzzy Logic Controller Applied to Non-
Linear Processes”, IEEE Transactions, 1996.
facilitates the communication with a PC for monitoring online [4] Naman,A.T., Abdulmuin,M.Z. and Arof,H., “Development and Appli-
parameters. The control algorithms were developed with C cation of a Gradient Descent Method in Adaptive Model Reference
language, complied with TI Compiler and run from the micro- Fuzzy Control”, 2000 TENCON Proceedings. Intelligent Systems and
Technologies for the New Millennium, pp. 358, 2000.
controller. [5] Xiao,Y., Hu,H., Jiang,H., Zhou,J.and Yang,Q., “A Adaptive Control Based
To provide an objective comparison between the fuzzy and Neural Network for Liquid Level of Molten Steel Smelting Noncrystlloid
neural network control algorithms, two tests were carried out Flimsy Alloy Line”, Proc. of 4t h World Congress on Intelligent Control
and Automation, China, 2002.
in the VRP MTSC32 DSP micro-controller. Figure 13 shows [6] Narendra, K.S. and Parthasarathy, K., “Identification and Control of
fuzzy control result and Figure 14 shows the neural control Dynamical Systems Using Neural Networks”, Neural Networks, IEEE
result. Transactions on,Vol.1, No.1,Mar,1990.
[7] Takagi,T. and Sugeno,M., “Fuzzy Identification of System and its Appli-
VI. C ONCLUSION caiton to Modeling and Control”, IEEE Transactions on Systems, Man
and Cybernetics, Vol.15, No.1, 1985.
This paper proposed two control schemes for the water level [8] Murakami,K. and Sugeno,M., “An Experimental Study on Fuzzy Parking
control system. From the results of the experimental studies, Control Using a Model Car”, Industrial Application of Fuzzy Control,
North Holland, 1985.
the following summary can be obtained. [9] Yamada, T.and Yabuta, T., “Dynamic system identification using neural
For the fuzzy control, in order to ensure the best perfor- networks”, Systems, Man and Cybernetics, IEEE Transactions on, Vol.23,
mance, a number of factors and values need to be online Issue 1,Jan/Feb, 1993
[10] Mistry, S.I.and Nair, S.S., “Identification and Control Experiments Using
determined heuristically or by trial and error, for example, Neural Designs”, IEEE Control Systems Magazine, Vol.14, Issue 3, Jun,
the membership functions. For neural network control, the 1994.
learning parameters and prior well-training is essential for
the success of the control. Once trained, the neural network
does not require for tuning. Table IV shows a summary of

You might also like