Chapter 5 Two-Tank Liquid Level Control using a BASIC Stamp

Chapter 5
Two-Tank Liquid Level Control using a BASIC
Stamp Microcontroller and a MATLAB-based Data
Acquisition and Control Toolbox
5.1.
Introduction
A variety of PC-based data acquisition and control (DAC) boards are currently available
in the market. These DAC boards can be broadly classified in two categories: i) high-end
DAC boards, which provide a wide range of advanced hardware capabilities along with a
sophisticated software environment; and ii) low-end DAC boards, which are primarily used for
data acquisition of a few selective signals while using proprietary software.
With the emergence of MATLAB [6] as a widely used scientific computing tool in industry
and academia, many users seek a DAC platform that can interface with and exploit advanced
computing capabilities of MATLAB to perform hardware-in-the-loop experiments. Moreover,
within the last decade, new developments in automated code generation programs have allowed
users to utilize interactive icon-based control system simulation tools such as Simulink [44] for
real-time control. In particular, using the Simulink block library and Real-Time Workshop
(RTW) along with Simulink block libraries for vendor-specific DAC boards, one can generate
C code from Simulink-based feedback control diagrams for real-time controller implementation
on PC-based DAC boards. The ability to rapidly and efficiently design and implement complex
control algorithms using an icon-based programming environment enables control designers to
enhance productivity.
In Chapter 4, we developed a low-cost DAC platform which allows Parallax Inc.’s BASIC
Stamp 2 (BS2) microcontroller [55] to be programmed by MATLAB and Simulink. In this
Chapter, we illustrate several important features of the DAC platform developed in Chapter
4 by performing liquid level control of a coupled, two-tank system. Liquid level control is
ubiquitous in industrial applications, e.g., food processing, effluent treatment, power gener-
56
57
ation plants, pharmaceutical industries, water purification systems, and industrial chemical
processing. Thus, the study of liquid level control encompasses many engineering disciplines,
e.g., electrical, chemical, civil, and mechanical.
In this Chapter, we employ the classical proportional-plus-integral (PI) controller for liquid
level control of a coupled, two-tank system [63]. To effectively utilize this control methodology,
the system parameters, e.g., tank dimensions and pump characteristics, must be known exactly.
However, this may not be feasible since system parameters may change due to the effects
of scaling in tanks and orifices, aging of pump, and wear. Thus, to determine the system
parameters, we conduct an experimental system identification study which uses the inherent
nonlinear dynamics of the two-tank system.
The rest of the Chapter is organized as follows. In Section 5.2, we describe the coupled,
two-tank system model and formulate system identification and control design objectives. In
Section 5.3, we outline a method to perform system identification. In Section 5.4, we design
a PI controller. In Section 5.5, we perform experimental validation of the results of earlier
sections. In Section 5.6, we draw some concluding remarks.
5.2.
Coupled Two-Tank System Model
Figure 5.1 shows a two degree-of-freedom, state-coupled, two-tank system. This system
consists of two tanks with orifices and liquid level sensors at the bottom of each tank, a pump,
and a liquid basin. The two tanks have the same diameters and can be fitted with differing
diameter outflow orifices. In this experimental setup, the pump provides the infeed to Tank 1
and the outflow of Tank 1 becomes the infeed to Tank 2. The outflow of Tank 2 is emptied
into the liquid basin. The following conditions, with regard to the system dynamic model, are
used to describe the levels of liquid in Tanks 1 and 2:
i) the liquid levels in Tanks 1 and 2, denoted as L1(t) and L2(t), respectively, are measured
using two pressure sensors;
ii) L1(t) is always greater than 0cm and less than 30cm;
iii) L2(t) is always greater than 0cm;
iv) the desired liquid level in Tank 2 is greater than 0cm and less than 20cm for t > 0 ; and
58
v) the voltage applied at the input terminals of the pump, denoted by Vp(t), is between 0 and
22 volt direct current (VDC).
The nonlinear mathematical model describing the liquid levels of Tanks 1 and 2 is given
by [63]
q
L˙ 1 (t) = −A L1 (t) + BVp (t),
q
q
L˙ 2 (t) = C L1 (t) − D L2(t),
a1
where A 4
= A1
√
(5.1)
(5.2)
√
√
Kp
4 a1
4 a2
2g, B 4
= A1 , C = A2 2g, and D = A2 2g, ai is the cross-sectional area of the
outflow orifice at the bottom of the Tank i, Ai is the cross-sectional area of the Tank i, Kp is
the pump constant, g is the gravitational acceleration, and i =1, 2.
Figure 5.1: Two degree-of-freedom, state-coupled, two-tank system
59
5.2.1.
System Identification Objectives
In this Chapter, we assume that the system parameters A, B, C, and D or equivalently
ai , Ai , Kp , and g, for i =1, 2, are not known exactly. As previously discussed, the uncertainty
about system parameters may arise due to corrosive buildup in the liquid level system or the
deterioration of the pump motor. Thus, a control design based on the idealized values of the
system parameters may lead to performance deterioration for the closed-loop system. In a
subsequent section, we outline a series of experiments, which exploit the nonlinear dynamics
of (5.1) and (5.2), to numerically estimate the system parameters A, B, C, and D.
5.2.2.
Control Objectives
Given a desired, constant, liquid level for Tank 2, denoted as L2d, design a control input
Vp(t) such that lim L2 (t) = L2d . This objective is to be achieved with the assumption that
t→∞
L1 (t) and L2 (t) can be measured. Furthermore, the control design is to utilize estimates of the
system parameters.
To quantify this control objective, we define the liquid level tracking error for Tanks 1 and
2, i.e., l1 (t) and l2(t), as follows:
l1(t) = L1 (t) − L1d ,
(5.3)
l2(t) = L2 (t) − L2d ,
(5.4)
where L1d is some desired, constant liquid level for Tank 1, which using (5.2) is characterized
a2 2
as L1d 4
= ( a1 ) L2d .
5.2.3.
Linearized Error System Model
To facilitate the design of a controller to achieve the aforementioned control objectives, we
begin by describing the linearized error system model (see reference [63] for details)
l˙1(t) = α1 l1(t) + β1u(t),
(5.5)
l˙2(t) = α2l2 (t) + β2l1 (t),
(5.6)
4
where u(t) =
Vp(t) − Vpd and Vpd is the desired pump voltage, which using (5.1) is characterized
√
as Vpd 4
= a1
2gL1d
Kp .
Furthermore, the parameters α1 , β1 , α2 , and β2 in (5.5) and (5.6) are defined
60
as, respectively,
α1 4
= − √
C
A
D
4
, β1 4
, and β2 4
.
= B, α2 = − √
=√
4L1d
4L2d
4L1d
(5.7)
Next, we develop the transfer function models for the linearized error system of (5.5) and (5.6)
by taking the Laplace transform of (5.5) and (5.6) and rearranging terms to yield
β1
l1(s)
,
=
u(s)
s − α1
(5.8)
l2(s)
β2
,
=
l1(s)
s − α2
(5.9)
4 L[l (t)], l (s) 4 L[l (t)], and u(s) 4 L[u(t)] with L denoting the Laplace operator
where l1(s) =
1
2
2
=
=
[64].
5.3.
System Identification
In this section, we outline an experimental method to determine the parameters of the
coupled two-tank system given in (5.1) and (5.2). Specifically, motivated by the nonlinear
dynamics of (5.1) and (5.2), we outline a set of experiments that yield the system parameters
A, B, C, and D. In experiment 1, we first obtain numerical values for the ratios
A
B
and
C
D.
In
experiment 2, we obtain the numerical value for the parameter A, which using the numerical
value of
A
B
obtained in experiment 1 yields B. In experiment 3, we obtain the numerical value
for the parameter D using the same procedure as in experiment 2, which using the numerical
value of
C
D
5.3.1.
Experiment 1
obtained in experiment 1 yields C.
In this experiment, we obtain expressions that relate the ratios
A
B
and
C
D
to steady state
conditions of the pump and the liquid levels of Tanks 1 and 2. Specifically, we begin by noting
that if a fixed voltage is applied to the pump, then the liquid levels of Tanks 1 and 2 will reach
steady state after a sufficient amount of time. This characteristic can be proven by directly
solving the differential equations (5.1) and (5.2) given that Vp(t) is constant. Next, the solution
of (5.1) and (5.2) under steady state conditions, i.e., with L˙ 1 (t) = 0 and L˙ 2 (t) = 0 yields
A
Vpss
,
=√
B
L1ss
(5.10)
61
C
=
D
s
L2ss
,
L1ss
(5.11)
respectively, where L1ss, L2ss, Vpss are the steady state liquid levels of Tanks 1 and 2, and the
steady state pump voltage, respectively. From (5.10) and (5.11), by applying a fixed voltage
Vpss to the pump and directly measuring the liquid levels of Tanks 1 and 2 after a sufficient
amount of time, i.e., L1ss and L2ss , we can determine numerical values of
5.3.2.
A
B
and
C
D.
Experiment 2
In this experiment, we fill Tank 1 with a fixed amount of liquid and record the time history
of the liquid level in Tank 1 as it is discharged. Using this time history, we can determine
a relationship between the system parameter and the liquid level in Tank 1 at a given time
instant. To do so, we solve the differential equation (5.1) with Vp(t) = 0 and obtain
q
L1 (t) =
q
1
L1(t0 ) − A(t − t0 ),
2
(5.12)
where t0 is the initial time and L1 (t0) is the initial liquid level in Tank 1. Note that equation
(5.12) is only valid when the right hand side of (5.12) is nonnegative, i.e., prior to full discharge
of Tank 1 since once Tank 1 is fully discharged the right hand side of (5.12) becomes negative.
To determine when the liquid in Tank 1 is fully discharged, we set L1(t) = 0 in (5.12) and
solve for the corresponding time, resulting in
p
2 L1 (t0 )
t =
+ t0 ,
A
∗
(5.13)
where t∗ is the time of full discharge of Tank 1. Using (5.13), the analytic expression for the
liquid level in Tank 1 is given by
L1 (t) =

p


 ( L1 (t0 ) − 12 A(t − t0 ))2



0
√
t<
2
L1 (t0 )
A
+ t0
(5.14)
√
t≥
2
L1 (t0 )
A
+ t0
√
Thus, if we choose a time instant t¯ with t¯ <
2
L1 (t0 )
A
+ t0 , or equivalently when the liquid level
in Tank 1 is still discharging, then (5.12) can be rewritten to yield the parameter A as follows
A=2
p
p
L1 (t0 ) − L1(t¯)
.
(t¯ − t0 )
(5.15)
62
Next, substituting (5.15) into (5.10), we can determine the parameter B as follows
p
p
L1(t0 ) − L1(t¯)
(t¯ − t0 )
B= 2
√
L1ss
.
Vpss
(5.16)
Note that the determination of the numerical value for B in (5.16) requires the use of the
experimental data obtained from experiments 1 and 2, i.e., the steady state values L1ss, Vpss
from experiment 1 and t¯, t0 , L1 (t¯), L1 (t0 ) from experiment 2.
5.3.3.
Experiment 3
In this experiment, we fill Tank 2 with a fixed amount of liquid and then obtain the time
history of the liquid level in Tank 2 as it is discharging. Using this time history, we can obtain
a relationship between the system parameter D and the liquid level in Tank 2 at a given time
instant. Similar to experiment 2, using the solution of (5.2), we obtain a relationship between
the system parameter D and the liquid level in Tank 2 as follows
D=2
q
p
L2(t0 ) − L2 (tˆ)
,
(tˆ − t0 )
(5.17)
where tˆ is a time instant before Tank 2 is fully discharged. Now, substituting (5.17) into (5.11),
we can determine the parameter as follows
p
C= 2
q
s
L2 (t0 ) − L2 (tˆ) (tˆ − t0 )
L2ss
.
L1ss
(5.18)
Note that the determination of the numerical value for C in (5.18) requires the use of the
experimental data obtained from experiments 1 and 3, i.e., the steady state values L1ss , L2ss
from experiment 1 and tˆ, t0 , L2 (tˆ), L2 (t0 ) from experiment 3.
5.4.
Proportional-Plus-Integral (PI) Liquid Level Control
In this section, we outline a PI liquid level control design that is based on the linearized
model of (5.8) and (5.9). As described previously, the liquid level control problem consists
of controlling the liquid level of Tank 2 to a desired, constant liquid level L2d . From (5.9),
to control the liquid level in Tank 2, we must use the liquid level of Tank 1, i.e., l1 (t) as a
pseudo control input. This necessitates control of liquid level of Tank 1 to a desired liquid level
63
L1d, which serves as a command signal for the Tank 1 controller u(t), or equivalently Vp (t).
Referring to Figures 5.2 and 5.3, we design PI controllers for Tank i, i =1, 2, as follows
Ci (s) = KPi +
KIi
,
s
(5.19)
where KPi is the proportional gain and KIi is the integral gain. To aid in determining the
controller gains KPi and KIi, the desired closed-loop responses for Tank i are specified in
terms of a settling time Tsi and percent overshoot oi performance criterion. It then follows
from reference [64] that the settling time and percent overshoot criterion can be related with
the closed loop damping ratio ξi and natural frequency ωni for Tank i, as follows
bi
ξi = q
,
2
bi + π 2
ωni =
4
,
Tsiξi
(5.20)
(5.21)
oi
where bi = log( 100
). Thus, using (5.20) and (5.21), the controller gains KPi and KIi that
achieve the desired closed-loop responses for Tank i are obtained as follows [63]
KPi =
1
(2ξiωni + αi ),
βi
(5.22)
2
ωni
,
βi
(5.23)
KIi =
where αi and βi given in (5.7) depend on the parameters A, B, C, and D, which are obtained
via system identification.
5.5.
Experimental Validation
In this section, we explore the experimental system identification and liquid level control
of a two-tank system using the BS2 microcontroller and the BS2 DAC toolbox developed in
Chapter 4. The two-tank, liquid level system is a commercial laboratory equipment developed
and marketed by Quanser Consulting Inc. [65]. The PC-based BS2 DAC platform developed in
Chapter 4 allows MATLAB and Simulink to seamlessly interact with the BS2 microcontroller.
In particular, this DAC platform provides a library of Simulink functions, which allows for direct interaction between user-defined Simulink block diagrams and sensors/actuators connected
to the BS2 microcontroller.
64
The PC-based BS2 DAC platform is composed of two main components, hardware and
software. The hardware required for this platform is the BS2 microcontroller, and user selectable sensors and actuators. The software required for this platform is the MATLAB-based
DAC toolbox.
The BS2 DAC toolbox supports several different types of input and output signals. However, in this Chapter, only analog input and output signals between ±5VDC are considered.
To convert an analog input signal to a digital format for use on a PC, we utilize the 12-bit
LTC1296 A2D IC. Analogously, to convert an actuation signal, whose representation is in a
digital format, to an analog output signal, we utilize the 12-bit MAX537 D2A IC. Both ICs
are natively supported in the BS2 DAC toolbox. See Chapter 4 for more details of the BS2
DAC toolbox features.
The BS2 DAC toolbox allows users to implement control designs and to develop DAC
panels within Simulink block diagrams. This toolbox provides a Simulink custom library
(BS2Library), which contains blocks that interface with sensors and actuators connected to
the BS2. In this Chapter, we use only the IOBlock, AtoD LTC1296, and DtoA MAX537. The
descriptions of these blocks are provided in Chapter 4.
As described earlier, the liquid levels of Tanks 1 and 2 are measured using pressure sensors,
where the output signal of the sensor is a voltage in the range of 0 to 5VDC corresponding
to the liquid levels in Tanks 1 and 2. A calibration gain for the pressure sensors is then
determined, i.e., the gain that converts the sensor output voltage to centimeters of liquid is
computed as
20
4.2
( Vcm
olt ) . The pressure sensor analog signals are supplied to the LTC1296 A2D
and are utilized in the Simulink block diagram, as shown in Figures 5.2 and 5.4. Using the
MAX537 D2A, the BS2 supplies a controlled voltage signal to the pump, which controls the
liquid levels of Tanks 1 and 2.
5.5.1.
System Identification
In performing experiment 1, as outlined earlier, we applied a constant 7VDC signal to
the pump Vpss , which produced a steady state liquid level in Tanks 1 of L1ss = 10.75cm and
a steady state liquid level in Tank 2 of L2ss = 11.40cm. Next, we performed experiment 2
65
Figure 5.2: Simulink block diagram of the PI controller for Tanks 1 and 2
Figure 5.3: PI controller for Tanks 1 and 2
66
Figure 5.4: Calibration and system identification Simulink block diagram
outlined earlier by filling Tank 1 with 16.46cm of water, i.e., L1(t0 ) = 16.46cm, and obtained
the liquid level of Tank 1 as it was discharged. Figure 5.5(a) shows the liquid level time
history of Tank 1. From Figure 5.5(a), the initial time of discharge t0 is 11.5sec and the time
of full discharge t∗ is 26sec. To compute the system parameter A, we chose ¯
t = 16sec, which
corresponds to a liquid level in Tank 1 of L1 (t¯) = 10cm. Using (5.15) and (5.16), A and B are
computed numerically to be 0.3978 and 0.1863, respectively.
Next, we performed experiment 3 outlined earlier, by filling Tank 2 with 15.80cm of water,
i.e., L2 (t0 ) = 15.80cm, and obtained the liquid level of Tank 2 as it was discharged. Figure
5.5(b) shows the liquid level time history of Tank 2. From Figure 5.5(b), the initial time
67
of discharge t0 is 59.5sec and the time of full discharge t∗ is 76sec. To compute the system
parameter D, we chose tˆ = 66sec, which corresponds to a liquid level in Tank 2 of L2 (t¯) =
7.8cm. Using (5.17) and (5.18), C and D are computed numerically to be 0.4056 and 0.3938,
respectively.
Next, we used the liquid level time histories given in Figure 5.5 to obtain numerous time
instances ¯
t and ˆ
t, corresponding to many estimates of the system parameters A, B, C, and D.
We then averaged, individually, the estimates of A, B, C, and D and obtained the following:
A = 0.4382, B = 0.2052, C = 0.4486, D = 0.4356. For comparison, manufacturer specifications
of the Tanks 1 and 2 cross-sectional areas and orifices areas produce the nominal system
parameters A = 0.5128, B = 0.2991, C = 0.5128, and D = 0.5128.
(a)
(b)
Figure 5.5: (a) Experiment 2–L1(t) response and (b) Experiment 3–L2(t) response
5.5.2.
PI Liquid Level Control
Next, we implement the PI control architecture discussed earlier to control the liquid level
of Tank 2. Referring to Figure 5.2, two A2D blocks labeled Tank 1 Liquid Level and Tank 2
Liquid Level, are used to import the signals L1 (t) and L2 (t). These sensor signals are then
used for the PI controller of Tanks 1 and 2, wherein the control signal Vp(t) is sent to a D2A
block labeled Pump Voltage for output to the pump.
In this experiment, we specify the desired liquid level of Tank 2 to be L2d = 12cm. Next,
68
we design the control gains KPi, KIi, i = 1, 2 using (5.22) and (5.23) given a set of settling
time and overshoot performance criterion. The resulting control gains are shown in Table 5.1.
Table 5.1: Settling time and percent overshoot requirements and PI controller gains
Case 1
Case 2
Case 3
Ts1
20 sec
35 sec
60 sec
o1
1.5 %
1.5 %
1.5 %
Ts2
30 sec
50 sec
70 sec
o2
1.5 %
1.5 %
3.5 %
KP1
1.6315
0.7963
0.3322
KI1
0.3039
0.0785
0.0267
KP2
3.0559
1.4565
0.7710
KI2
0.3288
0.1184
0.0641
Figures 5.6–5.8 show the time history of L1 (t) and L2 (t) using the control gains given in
Cases 1–3 given in Table 5.1. Note that the controller design for the system is obtained by
linearizing the nonlinear model near the predetermined steady state level of Tank 2. Therefore,
the response is not guaranteed to satisfy the imposed constraints.
(a)
(b)
Figure 5.6: Response of (a) L1 (t) and (b) L2(t) using the PI controller gains of case 1
5.6.
Conclusion
In this Chapter, we utilized the MATLAB and Simulink-based DAC platform developed in
Chapter 4 to control a two degree-of-freedom, state-coupled, two-tank system. We outlined a
comprehensive method to perform system identification, and provided a design of a set-point
tracking controller to control the liquid level of the two-tank system. In addition, we experimentally validated the system identification method by using the BS2 DAC toolbox, which
69
(a)
(b)
Figure 5.7: Response of (a) L1 (t) and (b) L2(t) using the PI controller gains of case 2
(a)
(b)
Figure 5.8: Response of (a) L1 (t) and (b) L2(t) using the PI controller gains of case 3
produced estimates of the two-tank system parameters. Finally, we experimentally obtained
the response of the set-point tracking controller, which showed good tracking performance
using several sets of performance criterion. This Chapter illustrates that the integration of a
low-cost BS2 microcontroller and the MATLAB and Simulink based DAC toolbox can be used
for data acquisition, experimental system identification, and advanced feedback control.