Level Tank MPC
Level Tank MPC
Faculty of Technology
TABLE OF CONTENTS
TABLE OF CONTENTS .................................................................................................... 3
1 Introduction ..................................................................................................................... 4
2 Creating the program ..................................................................................................... 5
2.1 Step 1: Creating a new database .......................................................................................................... 5
2.2 Step 2: Creating a MPC control module in an area ........................................................................... 5
2.3 Step 3: Connecting I/O to the MPC_LOOP ........................................................................................ 6
2.4 Step 4: Creating a Kalman filter ........................................................................................................ 11
2.5 Step 5: Activate I/O configuration ..................................................................................................... 16
2.6 Step 6: Assigning area to alarm and events and continuous historian ........................................... 17
2.7 Step 7: Downloading the program ..................................................................................................... 18
3 Modelling and validation .............................................................................................. 19
3.1 Step 1: Connecting the Level Tank process ...................................................................................... 19
3.2 Step 2: Creating the MPC model ....................................................................................................... 20
3.3 Step 3: Verification of the MPC model ............................................................................................. 23
3.4 Step 4: Validation of the MPC controller ......................................................................................... 26
4 Creating the HMI .......................................................................................................... 28
4.1 Step 1: Creating a new picture ........................................................................................................... 28
4.2 Step 2: Creating picture interface using dynamos ........................................................................... 29
4.3 Step 3: Creating names and datalinks ............................................................................................... 31
4.4 Step 4: Creating faceplate- and MPC operator interface buttons .................................................. 32
5 Operating the Level Tank system ................................................................................ 34
3
Telemark University College
1 INTRODUCTION
In this tutorial you will learn how to:
Create a program to control level in a Level Tank with MPC and Kalman filter using
DeltaV Database Administration, -Explorer, -Control Studio and –I/O Configuration.
Create a MPC model for a Level Tank and do validation using DeltaV Predict, -MPC
Operate and –MPC Simulate.
Create a HMI for a Level Tank using DeltaV Operate Configure.
Control and tune the level performance of a Level Tank system using the MPC controller
in DeltaV Operate Run.
4
Telemark University College
Now set the database you just made active with the Set Active Database button. This button is
found in the Database Administration window. Select the database you just made and press ok.
Your database is now created and active.
5
Telemark University College
You will find the MPC loop you just added in your LEVELTANK area.
6
Telemark University College
From Control Studio we see that we have a MPC block. In addition we have one analog in block
and one analog out block, for our case being the controlled variable (CV) for the level and
manipulated variable (MV) to the pump respectively. These IO needs to be assigned to the
hardware controller and IO modules. Since the level is measured in percent, then we also need to
scale this value into cm.
Drag and drop a Scaler block found under the Analog Control tab, see Figure 2.4. Wire a
connection from the AI block to the Scaler block and from the Scaler block to the CNTRL1 on
the MPC block. Mark the Scaler block and double click OUT_SCALE in the property section to
the left, and write 20 under 100% scale. Then, press OK.
Right click the AI block and choose Assign I/O To Signal Tag. An IO_IN Properties window
will then appear, see Figure 2.5.
7
Telemark University College
Browse Device Tag, double click on CTLR and choose TLR-1-HITC01CH02. This is the second
IN on the analog input module (CH02). Press ok until you are back to the MPC loop.
Now, right click the AO block and choose Assign I/O To Signal Tag, and double click
IO_OUT. Browse Device Tag, double click on CTLR and choose TLR-1-HITC02CH01. This is
the first OUT on the analog out module (CH01). Press OK and then close. We have now
connected the I/O to the MPC controller.
In addition, for MPC training purposes we will also include constraints (AV) on the level, and
disturbance (DV) being the outflow. These are typical variables in a process and often affect the
performance. To include them we need to add these parameters to the MPC block. Right click
the MPC block and choose Extensible Parameters. Then double click on NOF_DSTRB and add
1 to the Modify Extensible Parameter - NOF_DSTRB, see Figure 2.6. Click OK and add 1 to the
NOF_CONSTR. Again click OK and Yes until you are back to the MPC loop.
8
Telemark University College
Do the same with the other parameters. For the Constraint parameter, also include CNTRL1
under Related CV, and add a Low limit and High Limit being 5 and 15 cm respectively. When
finished close the property window.
The level is the constrained parameter and then we need to connect the Scaler block OUT to the
CNSTR1 input on the MPC block, see Figure 2.9.
Since we don’t have any hard-sensor measured disturbance we will in section 2.4 create a
Kalman filter in a different control module to estimate the disturbance outflow. However, before
we do that we will finish up the blocks needed in MPC_LOOP_1.
Add an Input Parameter from the Special Items tab, see Figure 2.8. A New Parameter Properties
window will appear. Write a Parameter name, and choose External Reference under Parameter
type since we want to get this value from a different module.
9
Telemark University College
Figure 2.8 Adding an Input Parameter from the Special Items tab.
Since the MPC block requires an OUT_SCALE as an input then we also need to add a Scaler
block found under the Analog Control tab. Connect the Input Parameter and Scaler block to the
MPC block as seen in Figure 2.9.
Figure 2.9 Constraint and disturbance parameters connected to the MPC block.
For the Kalman filter we will use scaled values and therefore we also need to scale the control
signal into volt output.
Add an Output Parameter from the Special Items tab. Give the Output Parameter a name when
the New Parameter Properties window appears.
Add a new Scaler block from the Analog Control tab. Mark the Scaler block and double click
OUT_SCALE in the property section to the left. Write 5 under 100% scale and 1 under the 0%
of scale, see Figure 2.10. Then, press OK.
Finally, connect the MPC block to Scaler block, and the Scaler block to Output Parameter, see
Figure 2.10.
10
Telemark University College
A discrete state space model must be developed to implement the Kalman filter. With x1=x and
x2=Fout, then the state space model is as follows:
1 𝑥 𝐾𝑝
𝑥1̇ 0 − 1
[ ]=[ 𝐴 ] [𝑥2 ] + [ 𝐴 ] 𝑢
𝑥2̇
0 0 0
𝑥1
𝑦 = [1 0] [𝑥 ]
2
11
Telemark University College
𝑥1,𝑘+1 𝑇𝑠 𝑥
𝐾 𝑇
] = [1 − 𝐴 ] [𝑥 ] + [ 𝑝 𝑠 ] 𝑢𝑘
1,𝑘
[𝑥
2,𝑘+1 2,𝑘 0
0 1
𝑥1,𝑘
𝑦𝑘 = [1 0] [𝑥 ]
2,𝑘
To get a more structured program we want to separate the Kalman filter into its own control
module and later use an external reference for the estimated outflow in the MPC_LOOP_1
module.
Go to DeltaV Explorer and right click on your area LEVELTANK. Then choose New Control
Module, see Figure 2.11.
12
Telemark University College
Name the Object name KALMAN_FILTER, see Figure 2.12, then press OK.
Right click your new control module KALMAN_FILTER, and then choose Open Open with
Control Studio.
Drag and drop a Calc/Logic block from Analog Control tab. W.r.t. the derived Kalman filter
algorithm we now need 9 inputs and 6 outputs on the Calc block. Right click the block and
choose Extensible Parameters. Double click IN and OUT, and write 6 and 9 inputs and outputs
respectively, see Figure 2.13.
13
Telemark University College
Figure 2.13 Adding inputs and outputs to the Kalman filter Calc block.
Now, drag and drop 9 Input Parameters and 6 Output Parameters from the Special Items tab and
connect them to the Calc block, see Figure 2.14.
Figure 2.14 Connecting Input and Output Parameters to the Calc block.
For each and one of the parameters a New Parameter Properties window will appear, e.g. similar
as in Figure 2.8. For all the output parameters enter only Parameter name, e.g. as shown on the
parameters in Figure 2.14. Table 2.1 explains necessary settings you should enter for the input
parameters.
14
Telemark University College
Note! Values given in Table 2.1, e.g. for K1, K2 and KP, are found using LabVIEW doing
different experiments with trial and error. They have proved to be acceptable. However, you may
want to adjust these values yourself if the estimation performance is not satisfactory.
From the Kalman filter algorithm we now need to enter the expressions into the CALC block.
Right click the CALC block and choose Expression. Then write the expression as shown in
Figure 2.15, either by typing it directly or using the toolbar above the expression area.
The last thing we need to do now is to insert a reference to the estimated outflow parameter in
the MPC_LOOP_1.
15
Telemark University College
Open the MPC_LOOP_1 control module in Control Studio. Double click the EST_OF_DV
parameter and Browse under External parameter path: KALMAN_FILTER CALC1 OUT4,
see Figure 2.16.
Figure 2.16 Inserting a reference to the estimated outflow parameter in the MPC_LOOP_1.
The Kalman filter is now finished and connected as an estimator for the disturbance to the MPC
controller.
Here we can see all the modules that are connected to the station. See Figure 2.18.
Choose C01 and right click the CH02 and enable it. Do the same with C02CH01.
CH02 under C01 and CH01 under C02 should now be activated.
16
Telemark University College
2.6 Step 6: Assigning area to alarm and events and continuous historian
Now we need to return to Control Studio and download our program for both the MPC_LOOP_1
and KALMAN_FILER modules. This is done by pressing the arrow called Download, see Figure
2.19. You will then get a question box that asks if you want to assign the module. Press yes,
choose CTLR-1-HIT, press Ok, and yes on the Control Studio box. After that, press ok and yes
on everything until you have downloaded. If you get any error messages just press Ok and
proceed.
The control modules and I/O is now connected to the hardware module. For alarms and events
and data collecting to work we need to connect this to the history module that’s premade in
DeltaV.
Go to Exploring DeltaV, choose your area LEVELTANK under Control Strategies and drag and
drop it down to Alarms And Events, see Figure 2.20. Also, since we need to collect input/output
17
Telemark University College
data to create a model as in section 3, then drag and drop the area to Continuous Historian as
well.
Figure 2.20 Assigning LEVELTANK area to Alarms and Events and Continuous Historian.
Also, every time you make a change in a program in Control Studio this need to be saved and
downloaded again as well, see Figure 2.19.
18
Telemark University College
Outl
et
Outlet
Figure 3.1 Connecting the Level Tank model to the DeltaV system.
19
Telemark University College
20
Telemark University College
Start by going to Options in the application menu and chose Expert. This gives additional
features which we want to use.
From the Figure 3.3, the upper left part is where the model hierarchy is found. On the upper right
is a trending picture which shows the MPC parameters configured, and chosen by double-
clicking the respective parameter under Operation and Trend. The lower left part is for modelling
configuration and the lower middle is for model generation.
Before we start modelling we want to find a preferred operational point, e.g. around 10 cm.
Click Application in the application menu and choose MPC Operate.
A new application appears, and with the physical process connected we have the choice to run
the MPC control either in manual or in auto mode. Since we do not have a model yet only the
manual mode will work.
On the bottom in the MPC Operate application all the MPC parameters are shown.
Start by marking all the parameter check boxes in the bottom of the figure. Click on the
manipulated variable (MV). At the left side a slide-bar for the parameter is then shown. Adjust
the slide-bar so that the level gets steady and about 10 cm, see Figure 3.4.
When you have the operational point steady around 10 cm, go back to the DeltaV Predict
application and set the Test Process parameters Step Size to 5 %, Time to Steady-State to 180 s
and Cycles to 2, as seen in Figure 3.5. Also, set the flow handle on the physical Level Tank to
45°. Then press the Test button.
21
Telemark University College
The application is now starting to collect input/output data to create the model. For the above
Test Process settings it will take some time to finish this test process. This will be indicated by a
blue progression bar under Test Process.
When the test process is finished this is indicated by the green area layered on the period of data
collection seen on the trend picture and as in Figure 3.6.
22
Telemark University College
23
Telemark University College
To possible improve the model, e.g. remove uncertain data, we may adjust the period of data
collection as seen in Figure 3.6. However, note that doing this may also worsen your model, and
should be done with cautiousness.
If you want to adjust the period of data collection, then click on and adjust the edges of the green
layered area, see Figure 3.9. From the figure the data seems to correlate (negative) better within
the new green area.
Figure 3.10 New model verification of the actual measurement vs the predicted.
24
Telemark University College
Once you are satisfied that the model fairly reflects the process dynamics, select Generate Ctlr to
update the MPC configuration for the new model.
When the control is generated from a selected model, control parameters used to generate the
control are displayed and shown in Figure 3.11. Here we can somewhat tune the controller.
Normally only the Penalty On Move (PM) and Penalty On Error (PE) should be adjusted. In
short:
Increase the PM value (in fifty percent increments) for any manipulated variables that are
moving more than the acceptable limits.
Decrease the PM for manipulated variables that are not responsive. It is recommended
that they do not go below the default minimum PM values (the PM min = 3).
Increase or decrease the PE, depending on process control requirements.
We might want to wait to do this kind of tuning since we have not tested the controller yet.
However, normally the default values give a good performance.
Now, press Start to continue, and then Close after the progression bar has finished.
To download the MPC controller click the blue arrow in the DeltaV Predict application as seen
in Figure 3.12.
25
Telemark University College
Start by marking all the parameter check boxes in the bottom of the figure.
Then select AUTO under Mode, and start the simulation by clicking the play button.
Now you can adjust the controlled variable using the slide-bar to the left and see the simulation
performance of the MPC controller. If you want the simulation to go faster you can do so by
adjusting the horizontal slide-bar above the play button. The yellow area in the trend is the
predicted future measurement.
If the performance is satisfactory then you can test it on the Level Tank, e.g. using the MPC
Operate application in the same manner as in the simulation environment, and see if the response
is similar. The green area in the trend is the predicted future measurement. Figure 3.13 vs Figure
3.14 shows that the response is fairly similar. Note that in the simulations the disturbance is
constant. The constant value is set w.r.t. the average value of the earlier collected disturbance
data.
26
Telemark University College
Note! If your model or simulations doesn’t look to good it could be a good idea doing the test
process again and possible change the test process parameters, e.g. try to vary the period of
testing w.r.t. number of samples.
27
Telemark University College
Press the +sign on the folder Pictures Templates and double click on main. You will then get a
standard template picture, see Figure 4.2.
28
Telemark University College
Mark and delete all the text on the picture so you get a blank picture like the one below, see
Figure 4.3.
Next, go to File in the menu and choose Save As. Save the picture with yourname.grf.
29
Telemark University College
A Dynamo box will appear after you have placed your tank, as shown in Figure 4.5. Start by
entering 20 (cm) in Highest Input Value under Input Ranges. Press the button, then press
Browse DeltaV Control Parameters LEVELTANK MPC_LOOP_1 MPC1 CNTRL1
CV.
This can be connected to the I/O. Check the box for Animate Pump Color. Press the button
and do exactly the same as you did when connecting the tank, except that you will choose
MNPLT1 instead of CNTRL1.
We can also choose what kind of color the pump will have at different values. Choose green
color when the pump is running, see Figure 4.6.
30
Telemark University College
Figure 4.6 Linking control signal data to the pump and adding animation color.
Now we need to add a reservoir tank and some pipes. Drag and drop a tank and some pipes into
the drawing board and adjust them similar to as seen in see Figure 4.7. The tank is found in
Tanks2 and pipes are found in Pipes_DF, under Dynamo Sets.
31
Telemark University College
Let’s start with the CV. Press “ABC100” that you can find in the toolbar. Then press the
button. Browse DeltaV Control Parameters LEVELTANK MPC_LOOP_1 MPC1
CNTRL1 CV. Then press ok until you get back the Datalink box. Here, change Type to
Numeric and press ok. Place the variable next to CV, see Figure 4.8.
Do exactly the same for SP, but choose SP1 instead of CNTRL1, and in Datalink box we need to
choose in-place on the data entry to be allowed to change the variable. Place it next to SP.
For the MV, do exactly the same procedure as we did with SP, except that we choose MNPLT1.
Place the variable next to MV.
The only datalink left is the DV. Do exactly the same procedure as when we did with CV, except
that we choose DSTRB. Place the variable next to DV.
32
Telemark University College
We have now made it possible to open a faceplate to our controller. Also, we want to create a
button that opens the MPC Operate interface. Choose Dynamo Sets and double click
frsAdvCFncblk. Then drag and drop MPCOperMode into the picture, see Figure 4.10.
A Dynamo Properties window appears. As for the faceplate press the button and choose
Browse DeltaV Control Parameters. Then choose LEVELTANK MPC_LOOP_1 MPC1
CNTRL1 CV and press OK until you are back to your picture.
You have now made the interface that can be used to control the temperature for the Level Tank.
If you haven’t already saved your picture then do this now by choosing Save As under File. Save
the picture with yourname.grf.
33
Telemark University College
To open the MPC Operate application just press the Open MPC Operate button you created. You
can then control the Level Tank as explained in section 3.
Press the Open Faceplate button to open the faceplate. Alternatively you can mark either SP or
MV and then press the faceplate button in upper left corner. Here you have the options to control
the process manually or set it to auto.
You can see the trend of the variables by pressing the button that looks like a graph in the
faceplate. You will then see the CV, SP, MV and DV.
If you press the button with the magnifying glass in the faceplate, a detail window will appear.
Here you can e.g. try to do further tuning changing the SP Filter Time. If your controller f.ex. has
to fast control response, then by increasing the setpoint filter time the response will be relaxed.
Figure 5.2 shows the running model with its associated faceplate and detail window.
34
Telemark University College
Figure 5.2 Running the Level Tank system in DeltaV Operate Run with associated faceplate and
detail window.
Further tuning can be done changing the PM and PE by pressing the Generate Ctlr button in the
DeltaV Predict application, and explained in section 3.3. Feel free to experiment and try to find
values that might improve the performance.
In Auto mode, try to set the setpoint to 20- or 0 cm, starting from e.g. an operational area around
10 cm, and see what happens. Hint: The controller should respect the constraints set 5- and 15
cm respectively.
Try also to adjust the handle on the physical Level Tank, and see both the performance of change
in the estimated disturbance and controller.
35