Tank Level Control Studio
Gravity-drained tank · manual and PID level control
A gravity-drained tank with an inlet valve you can drive by hand or hand
to a PID controller. With the outlet closed it is a pure integrator with a fill-only
actuator. Open the outlet and Bernoulli's square-root law makes it self-regulating. The
app ships as the assignment asks (proportional only, Ki
and Kd at zero) so the first thing you meet is offset.
1. Overview
This guide covers the Tank Level Control Studio: the mass balance and its two operating regimes, the velocity-form PID every app in the collection shares, why a P-only loop parks the level away from setpoint and exactly where, what the outlet valve does as a disturbance, and the two behaviors (a small noise-driven offset, and honest negative readings on an empty tank) that look like bugs and are deliberate.
For faculty
Section 2 is lecture background, section 3 is what to demonstrate live, and the scenario table in section 3 is assignable as-is. Section 5 says what not to claim.
For students
Start at section 3, run the app while you read, then come back to section 4 to connect what you saw to the equations. Nothing here is graded. The app is.
For practitioners
Section 2 places Tank Level Control Studio against the real unit operation, section 4 gives the model you would have to replace, and section 5 is the honest gap list.
The one-paragraph version
The tank obeys
ρA·dh/dt = c·uin − ρcout(uout/100)√h with
ρ = 1000 kg/m³, A = 1 m² and c =
50 kg/s per %, so dh/dt = 0.05uin with the outlet shut. The
controller is the velocity form: its proportional term acts on changes of the
error, and the operating point is carried by the running output. Every case starts settled at
its setpoint, so a P-only loop is on target until something moves the valve position the tank
needs, uss. Then it parks Δuss/Kp
off setpoint: with the outlet shut uss is zero at every level and
P-only is offset free. With the outlet open a load leaves an offset (0.84 m when the
outlet steps from 10 to 50%), and Ki is what removes it.
2. Background
The engineering problem
A cylindrical tank is filled through an inlet valve and drained through an outlet valve. The controlled variable is the liquid level. The manipulated variable is the inlet valve position, 0–100%. The outlet valve is adjustable in both modes, so it doubles as a drain disturbance.
The tank has two quite different characters depending on that outlet valve, and noticing which one you are in explains most of what the app does:
- Outlet closed. Inflow is constant for a given valve position and nothing drains, so the level is a pure integral of the inlet valve. Worse, the actuator can only add water: there is no way at all to lower the level. A step in valve position gives a ramp in level, and the ramp only stops at the tank height.
- Outlet open. Outflow follows Bernoulli's principle,
∝ √h, so a rising level drains faster. That negative feedback is internal to the process: the tank now finds its own equilibrium at√h = c·uin/(ρcout(uout/100)), and it is a self-regulating plant.
The engineering problem is to hold a commanded level, 10 m in the assignment, against changes in the outlet valve, with a measurement that carries noise, and with an actuator that saturates at 0% and 100%.
Where it sits in control theory
This app is the collection's introduction to the two most basic ideas in feedback control, and it is deliberately arranged so that both are met as results rather than as claims:
- Whether proportional-only control leaves offset depends on the plant. The app
ships with
Ki = Kd = 0because that is what the assignment asks for. With the outlet shut the tank is an integrator, the valve it needs to hold still is zero at every level, and a P-only loop moves to a new setpoint with no offset. With the outlet open the needed valve depends on the level and on the outlet: case 4 opens the outlet from 10 to 50%, the tank then needs 11.07% instead of 2.21%, and the P-only loop parks 0.84 m low, aboutΔuss/Kp. AddingKiremoves it. Being able to predict the offset before running is the exercise. - Integrating against self-regulating plants. The outlet valve switches the tank between the two, and everything about the loop changes with it: whether a constant valve position has an equilibrium at all, whether the level can be lowered, whether proportional action alone can hold a setpoint. Learning to ask "does this plant self-regulate?" first is worth more than any tuning rule.
- A nonlinear process gain. Because outflow goes as
√h, the incremental gaindh/dudepends on the operating level. A tuning that suits a nearly empty tank is different from one that suits a nearly full one. The same operating-point dependence that the speed, reactor and distillation apps show in other units. - A velocity form that keeps the error it is handed. The proportional term acts on changes of the error, so a P-only loop switched to Auto with a standing error keeps that error: handed control 1 m below an 11 m setpoint, it holds 10 m, and a later setpoint move to 12 m raises the level by 0.99 m and leaves it 1 m short. Integral action is what closes a standing error. The derivative term acts on the measurement, so a setpoint step gives no derivative kick.
- Anti-windup by back-calculation. The output is clipped to 0–100%. With integral action on, the integral is driven back toward what the valve actually delivers while it sits on a limit. With integral action off there is nothing to wind up, and the clip alone acts on the emitted output.
- Measurement noise acting on an actuator that cannot undo. With the outlet shut, the valve cracks open whenever the reading falls below the first one the loop saw, and the water that admits cannot drain, so the level rests a few standard deviations above where the noise-free calculation puts it. It is bounded and it settles, because a reading that low stops occurring once the level has risen. This is what a one-way actuator does with a symmetric measurement, not a bug, and opening the outlet even slightly shrinks it. It is the clearest small example in the collection of noise plus a rectifying nonlinearity producing a systematic offset.
- An instrument model that is honest about signs. The reported level is
not clipped at zero. Half-rectifying the noise would bias an empty tank's
reading by
σ/√(2π)= 0.399σ, an error introduced by the instrument model rather than by the instrument. A real transmitter reads below zero on an empty tank, and the app shows that.
What this app teaches
- Why proportional-only control leaves a steady-state offset, and how to compute exactly where a velocity-form P-only loop will park.
- How to tell an integrating plant from a self-regulating one, and why that distinction comes before any tuning decision.
- That a square-root outflow law makes the process gain depend on the operating level, so one tuning is not right everywhere.
- How the velocity form's proportional term acts on changes of the error, so a P-only loop keeps a standing error it is handed.
- How back-calculation keeps the integral from winding up while the valve sits on a limit.
- How measurement noise plus a one-directional actuator produces a bounded systematic offset that neither term is at fault for.
- Why an instrument model should not clip its own noise, and how much bias clipping would introduce.
- How to use a disturbance (the outlet valve) deliberately, and why the same valve is both a process parameter and an upset.
The application in practice
Level control is the most common loop in the process industries:
- Surge drums and buffer tanks throughout refining and chemicals, where the level's job is to absorb variation rather than to be held tightly, which is why averaging level control exists and why the cooling-tower app in this collection argues for a deliberately loose tuning.
- Boiler drum level, the classic hard case: an integrating plant with inverse response (shrink and swell) and a three-element cascade to handle it.
- Storage tanks, sumps, distillation column bases and reflux drums, all of which are the same mass balance with different fluids.
- Any inventory: a hopper of solids, a battery's state of charge, a warehouse stock level, a queue. The mathematics is identical and so is the tuning argument.
- Gravity-drained vessels specifically are worth knowing because the square-root law appears wherever flow is driven by head (a drain, an overflow weir, an orifice) and it is the reason such vessels are self-regulating at all.
This app is built for the APMonitor Tank
Level exercise, and its defaults are the assignment's:
ρ = 1000 kg/m³, A = 1 m², c =
50 kg/s per percent, and a P-only controller with
Kp = 10.
Automation and its broader implications
A level loop is the least glamorous automation in a plant and a good place to see what automation is actually doing.
- It removes a task humans do badly for boring reasons. Holding a level by hand is not difficult. It is relentless. Try it in MANUAL with the outlet valve moving and the tedium is the point. Almost all industrial automation started here, with tasks that are easy and endless, and the value is attention freed rather than performance gained.
- The default tuning encodes a decision nobody restated. The app ships P-only because the assignment asks for it, and a P-only level loop will sit off setpoint. On a real plant that is sometimes exactly right (a surge drum should drift, so that flow variation is absorbed rather than passed on) and sometimes a fault. The distinction is a plant decision, and it lives in a number in a configuration file where nobody will look at it again. A great deal of industrial control performance is decided by defaults of this kind.
- Automation changes what a failure looks like. The noise-driven offset with the outlet shut is small, slow and entirely explicable, and no alarm would catch it and no operator watching a fast trend would notice it. Automated loops fail like this far more often than they fail dramatically: a slow bias, a gradual drift, a small persistent error that nobody owns. Building the habit of asking "what would a slow failure of this loop look like, and who would see it?" is worth more than another tuning rule.
- Instrumentation honesty is an engineering obligation. The choice not to clip the level reading at zero costs nothing and prevents a 0.4σ bias. Small decisions in a measurement chain create errors that look like process behavior, and once they are in the historian nobody can separate them again. The app exports both the transmitter reading and the true state so an offline identification can tell them apart, which is a courtesy a real plant does not extend, and a reason to think carefully about what gets recorded.
- Overflow is the automation's real failure mode. A tank that spills sends product, and in a real plant chemistry or hydrocarbon, to a drain or a bund. The consequence of a level loop failing is environmental and financial rather than a control statistic, which is why level loops carry independent high-level alarms and trips, and why "the controller was in auto" is never a sufficient answer.
3. Operating the app
The app runs entirely in your browser. It opens on case 1, the reference operating point: Manual, the level steady at its 10 m setpoint with the inlet valve at 2.2% against the manual outlet valve at 10%. Every case starts at steady operation in the same way, and its scripted event (a valve step, a setpoint step, an outlet step) arrives at 5 s. Speeds run 0.5× to 10×, and a run gives the same trajectory at every speed, including the noise, because the physics and the controller run on the simulated clock rather than on browser timers. The Learn panel carries the scorecard and the Predict, Try It, Hint and Explain card for the loaded case.
Interface anatomy
The layout is the one shared by every app in this collection:
- Header: the simulated clock, ▶ Run, ↺ Reset (restart the run and keep your settings, including the noise realization, so the same experiment really is the same experiment), the speed, Manual / Auto, Instructions (this page), Show Model and Export CSV.
- Tank visualization (upper left): the liquid level drawn to the tank height, a dashed setpoint line, LT and LC connected to the inlet valve, the manual outlet valve, and flow streams that scale with the inlet and outlet flows. An OVERFLOW badge shows while the tank spills. The readings give the outlet position and the outflow.
- Control panel (right): the scenario list with its ⓘ briefing and ↻ reload, the
🎯 Challenge button, the level setpoint (up to the tank height), the manual inlet valve, the
PID gains (
Kp,Ki,Kd) and the manual outlet valve. The tank area, the valve coefficients, the tank height and the level noise are under Show Model. - Trends (lower): the measured level with its setpoint, and the inlet valve.
Diagram of the layout rather than a screen capture, so that it follows this page's light or dark theme. The regions and the button names are the ones the app actually shows.
First run, step by step
Read the steady state. Case 1 holds 10 m with the inlet at 2.2% and the outlet 10% open. Check the balance
c·uin/ρ = cout(uout/100)√h: 0.05 × 2.21 = 0.035 × √10.Make it an integrator. In case 1, press Run, then shut the outlet valve and the inlet. The level stays wherever it is: every level is an equilibrium. Open the inlet to 1% and the level ramps at
dh/dt = 0.05 × 1= 0.05 m/s, 0.5 m in 10 s. Nothing you do to the inlet valve can bring it back down.Make it self-regulating. Open the outlet to 50% and watch the level settle where the flows balance. Compute the equilibrium yourself. Now the plant has an equilibrium for every valve position.
Meet the offset. Case 4 opens the outlet from 10 to 50% at 5 s under the shipped P-only tuning (
Kp= 10). The tank now needs 11.07% of inlet instead of 2.21%, and the loop parks about 0.84 m low with the valve at 10.6%: roughlyΔuss/Kp. Predict that number before you look.Shrink it, then remove it. Run case 4 again with
Kp= 20 and 40: the level settles 0.43 and 0.22 m low. Then setKi= 1: the level dips to 9.34 m and is back within ±0.05 m by about 33 s. That is what integral action is: an automatic search for the valve position the tank needs.See what the velocity form does with a standing error. In case 1, set the setpoint to 11 m before Run, press Run and switch to Auto. With P only, the level stays at 10 m: the proportional term acts on changes of the error. Step the setpoint to 12 m and the level rises 0.99 m and stays 1 m short. With
Ki= 1 it goes to 11 m.Check the derivative term. Set
Kd= 5 and run case 3. At the 10 → 11.2 m setpoint step the valve jumps by the proportional term only: the derivative acts on the measurement, so a setpoint step gives no derivative kick.Find the actuator limit. Case 8 opens the outlet fully and weakens the inlet valve (10 kg/s per %), so 6 m needs 85.7% of inlet. At 5 s the setpoint steps to 10 m: the inlet pins at 100% and the level climbs toward 8.16 m, the most the valve can hold.
Watch the noise offset. In case 1, before Run, shut the outlet and switch to Auto. With P only and the default 0.05 m noise, the level creeps up: 10.12 m after five minutes and 10.16 m after fifty. Then open the outlet 5% and watch the offset shrink. The section on two behaviors that look like bugs explains why.
Keep the data. Export CSV downloads every logged sample with both the transmitter reading and the true level, so an offline identification can separate signal from noise without turning the noise off.
The velocity-form PID, and where its operating point lives
The controller is the velocity (incremental) form every app in the collection shares. Each cycle adds one increment to the previous output:
Δu = Kp(ek − ek−1) + KiekΔt − Kd(PVk − 2PVk−1 + PVk−2)/Δt
with e = SP − PV, PV the noisy measured level, and
u clamped to 0–100%. The derivative acts on the measurement, so a setpoint step
gives no derivative kick. The proportional term still steps with the setpoint.
There is no bias setting. The running output carries the operating point. Three consequences worth stating:
- Transfer is bumpless. In Manual the controller tracks the inlet valve, so switching to Auto changes nothing at that instant. Every case in Auto starts settled at its setpoint with the valve where the tank needs it.
- P-only keeps a standing error. The proportional term responds to changes of the error, not to the error itself. Handed control with the level 1 m below setpoint, a P-only loop stays there and follows later setpoint moves one for one, never reaching them. Integral action is what closes a standing error.
- Anti-windup is back-calculation. The output is clipped to 0–100%, and with
Kion, the integral is driven back toward what the valve actually delivers while it sits on a limit, with a tracking timeKp/Ki.
The controller runs at a fixed 0.1 s sample time on the simulated clock, the same time base as the assignment's ODEINT interval, and the tank is integrated in 0.05 s steps. Browser timer jitter cannot change the closed-loop response.
Predicting the P-only offset, and when there is none
This is the app's central quantitative result and it is worth deriving rather than observing.
Start a P-only loop settled at setpoint with the valve at u0. From
then on u = u0 + Kpe. At a new steady state the valve must
equal whatever uss the plant needs to hold still, so
e∞ = (uss − u0)/Kp
Outlet shut, the integrating case. A tank with no discharge only holds still with
the inlet closed, so uss = 0 at every level and
e∞ = 0: proportional control alone lands on a new setpoint, exactly.
This is the property that makes P-only respectable for level control, and it is why
averaging level control on a surge drum is usually P-only with a deliberately low gain.
Outlet open, the self-regulating case. Case 4 opens the outlet from 10 to 50%:
uss at 10 m goes from 2.21% to 11.07%, so the formula predicts
8.86/10 = 0.89 m of offset, and the app settles 0.84 m low. The difference is the
square-root outflow law: at the lower level the tank needs a little less valve. Now no single
starting valve is right after every load, which is precisely the gap integral action
fills.
Two experiments follow. Raise Kp and watch the offset shrink as
1/Kp (0.43 m at 20, 0.22 m at 40) and never reach zero. Then
add Ki and watch it go.
Two behaviors that look like bugs and are not
Both are documented deliberately, and both teach something.
1 · The small upward offset with the outlet closed. The plant is a pure
integrator driven by a fill-only actuator, so nothing can lower the level. With the
outlet shut a settled P-only loop holds the valve at
Kp(e − e0), clipped at zero, so it cracks open on any
sample that reads below the first one the loop saw, and the water that admits cannot drain.
The level rises until a reading that low has become rare, which happens about 3.2σ
above setpoint. The
approach is asymptotic rather than a plateau, because a strictly positive mean inflow
never stops: 10.12 m after five minutes and 10.16 m after fifty at the default
σ = 0.05 m, and 10.24 m then 10.32 m at σ = 0.1 m, the fifty-minute
value repeating to within a centimetre across noise seeds. This is what a one-way
actuator does with a symmetric measurement, not an algorithm defect, and it is the one
place where the offset-free integrating result above is spoiled, by the instrument
rather than by the controller. Opening the outlet removes it, because the tank can give
the water back.
2 · Negative level readings on an empty tank. The reported level is
true level + noise and is not clipped at zero. Clipping it would
half-rectify the noise and bias an empty tank's reading by
E[max(0, X)] = σ/√(2π) = 0.399σ, which is +0.12 m at the maximum noise
setting, a systematic error introduced by the instrument model rather than by
the instrument. A real transmitter reads below zero on an empty tank, and the app shows
that.
Both are worth pointing out to students explicitly, because the instinct in each case is to assume the simulation is wrong, and the more valuable habit is to ask what mechanism would produce the observation.
The predictive controller (MPC) beside the PID
The Controller switch, PID or MPC, adds a model predictive controller beside the PID. The PID stays the default of every case. The MPC acts in Auto, and case 9 runs it.
Its model is a first-order lag fitted by a step test on this simulator at the design
point (10 m with the outlet 10% open and the inlet at 2.21%, the inlet stepped by
±0.2%): Δh = 9.03·(Δu + d)/(180.7s + 1), in m per % of inlet, with an RMS residual
of 0.0004 m. It is the tangent of the square-root drain at that point (the balance gives
9.04 m/% and 180.7 s by hand), so it is wrong away from it: with the outlet at 50% the
tank's gain at 10 m is 1.8 m/% and its lag 36 s.
What it decides. Every 0.5 s, five controller periods, it plans the inlet valve over a 360 s horizon (720 prediction steps in twelve move blocks, one step each near now and longer far out), applies the first move and holds it until the next plan. The plan weighs the predicted error, scaled by 0.5 m, against the valve's moves, scaled by its 100% span. The Move suppression λ (Advanced, 0.03) is their ratio. The valve's 0–100% range is a hard constraint of every plan.
Its estimator. A steady-state Kalman filter on the model, with an input disturbance
d added as a random walk, runs at every 0.1 s execution whichever controller is
in charge, so the MPC takes over warm. It reads only the measured level and the valve position
the controller applied. A load the model lacks shows up as d: with the outlet at 50%
it settles near −8.8% of inlet, and planning with it is what removes the offset, integral
action by another route.
When a plan fails. A plan the solver rejects hands the valve to the PID, which has
been tracking it, without a bump. The historian is marked MPC FALLBACK, a note is
posted, and the next good plan takes the valve back. A plan takes about 0.7 ms in Chrome,
0.14% of one core at 1× and 1.4% at 10×.
While the MPC is in charge the scene adds an MPC plan reading on wider screens and an MPC badge: the level the plan predicts at the end of its horizon. The trends do not change.
The MPC’s estimator (Kalman or MHE) and the relay autotune
Estimator: Kalman or MHE. While the Controller is MPC, Advanced → Predictive controller shows an Estimator switch: what the MPC starts each plan from. Kalman, the default, is the steady-state Kalman filter above. MHE (moving-horizon estimation) fits the same model, with the filter’s own noise variances, to the measurements of the last 30 controller periods (3 s) at every execution, weighting the window’s first state by the filter’s steady covariance, and keeps the level between the floor and the declared 12 m rim, from the declared values, never the run’s. With no bound active the two estimates agree to within a millionth of the measurement noise: what the MHE adds is the bounds, and only where the Kalman filter’s estimate would leave them.
On this studio no bound is ever active: the level stays well inside the tank, so on every case the MPC’s run with the MHE is its run with the Kalman filter, the valve differing by at most 5×10⁻⁹ %.
The Kalman filter keeps running whichever is chosen: est_pv and est_d stay its estimates, and the MHE’s are logged in mhe_pv and mhe_d. Choosing MHE mid-run starts its window from the filter’s own prediction, so nothing moves unless a bound is active at that instant. A window the solver does not solve is replaced by the Kalman update of the MHE’s own prediction, kept inside the bounds, marked MHE FALLBACK and noted, none occurred on any case. In Chrome, on the app’s own frame loop, the estimates and plans of case 9 take about 0.95% of one core at 1× and 8.0% at 10× (measured with other work on the computer).
Relay autotune. The Relay autotune (PID) button (Advanced. The PID in Auto) replaces the PID by a relay about the valve’s mean over the last 6 s (a tenth of a trend window, so one noisy reading does not move the cycle’s center): 5% of its span above or below it (less near a limit), switching each time the measurement crosses the setpoint by more than a band ε of three times the declared noise. When two cycles agree within 5% it takes Ku = 4d·sin(πD)/(π√(a² − ε²)) from the swing ±a and the fraction D of each cycle spent on the high side (½ for a symmetric cycle, which a relay centered on the output that holds the setpoint gives. The note reports D), and Pu from the period, writes the Tyreus–Luyben PI gains (Kc = Ku/3.2, τI = 2.2Pu) into the tuning, and hands the valve back to the PID without a bump. Pressed again it cancels. A switch to Manual or to the MPC cancels it too. The RELAY badge counts the cycles and the note says what happened, including, from ψ = asin(ε/a) ≥ 10°, that the band rather than the loop set the cycle. Reset keeps the written gains, as it keeps any you set.
On this studio, from case 3’s start (steady at 10 m in Auto, the setpoint step removed), the relay swings the inlet valve by ±2.03% (90% of the way to its nearer limit) and its band is ±0.15 m. It converges in 20 cycles, 48 s: Ku = 20.9 % per m, Pu = 4.40 s, so Kp = 6.53 and Ki = 0.675 (shipped: 10 and 0, proportional only). Over ten noise seeds Ku runs from 15 to 51. The model, sampled every 0.1 s, reaches −180° only at the sampling’s Nyquist frequency, with an ultimate gain of 400 at 0.2 s. The same relay on the noise-free model gives 107 at 6.0 s. A lag with no dead time has no phase crossover of its own: the swing is only 1.3 times the band, so the band set the cycle 51° short of −180°, and the noise lowers Ku further. The result note says so. The autotune adds the integral action the shipped loop lacks, which is what wins case 4: its outlet-valve upset scores an IAE of 18.9 against 145 m·s (true 13.9 against 145). Case 3’s setpoint step loses, 11.3 against 9.49 (true 5.79 against 4.53), with less valve travel (339 against 528%).
The gains are a starting point, not a design: try them on a setpoint step and a load step, and edit them.
Controls reference
Everything below is live in both modes except the mode's own primary control. The outlet valve in particular stays adjustable in auto, which is what makes it usable as a disturbance.
| Control | Symbol | Units | Range | Default | What it does |
|---|---|---|---|---|---|
| Setpoint | |||||
| Tank level setpoint | sp | m | 0.00 – 20.00 | 10.00 | The assignment value is 10 m. The range follows the tank height. |
| Manual actuator | |||||
| Inlet valve | u_manual | % | 0.0 – 100.0 | 0.0 | The manipulated variable. Live in Manual. In Auto it follows the controller output. |
| Controller tuning | |||||
| Proportional gain | Kp | %/m | 0.00 – 100.00 | 10.00 | The assignment default. With the outlet open it divides the P-only offset Δuss/Kp. |
| Integral gain | Ki | %/(m·s) | 0.00 – 20.00 | 0.00 | Zero by default for the P-only assignment. Adding it removes the offset. |
| Derivative gain | Kd | %·s/m | 0.0 – 50.0 | 0.0 | Zero by default. Acts on the measured level, so on a noisy level it needs care. |
| Prediction horizon | Tp | s | 20 – 720 | 360 | How far ahead the MPC plans. 360 s is two of the model’s 180.7 s time constants. On case 9 any horizon from 20 to 720 s gives the same scorecard IAE. (Advanced mode only) |
| Move suppression | λ | — | 0.00 – 1.00 | 0.03 | The price of moving the valve against the price of error, dimensionless. 0.03 was chosen by one stated rule for all seven studio MPCs: among the settings that move the actuator no more than the PID on the setpoint-step and disturbance cases, the largest move suppression within 10% of the best error. At 1, the slider’s top, case 9’s IAE rises from 6.32 to 8.64 m·s. (Advanced mode only) |
| Structure option | |||||
| Controller | ctrl | — | PID · MPC | PID | PID (the default) or MPC. The MPC acts in Auto. The PID tracks its output all along, takes the actuator without a bump if a plan is rejected, and is in charge again the moment you switch back. While MPC is chosen, the tuning of the loops it replaces leaves the control panel. The loops that still act keep theirs. |
| Estimator | mpcEstimator | — | Kalman · MHE | Kalman | Kalman (the default) or MHE, under Advanced while the Controller is MPC. The MHE keeps the level inside the tank over its last 30 controller periods. No case brings a bound into play, so both give the same run. (Advanced mode only) |
Disturbances
Disturbances are what the controller has to reject. Sliders are persistent conditions and buttons are one-off events. Every change is stamped on the trends so cause and effect stay visible.
| Disturbance | Kind | Units | Range | Default | Effect |
|---|---|---|---|---|---|
| Manual outlet valve | Slider | % | 0 – 100 | 10 | The app's principal disturbance, and also the switch between an integrating and a self-regulating plant. Cases 4, 5 and the challenge step it from 10 to 50%. Case 8 holds it at 100%. |
| Relay autotune (PID) | Button | — | — | — | An action, not a setting: under the PID in Auto a relay experiment from the present state writes Tyreus–Luyben PI gains into the tuning. From case 3’s start: Ku 20.9, Pu 4.40 s, Kp 6.53, Ki 0.675. Press again to cancel. (Advanced mode only) |
Scenarios
Each scenario is a complete set-up: mode, setpoint, tuning, disturbances and timed events. Selecting one from the list resets the run, so a scenario is reproducible and can be assigned as-is.
| # | Scenario | What it sets up and what to look for |
|---|---|---|
| 1 | Reference operating point | Sets: MANUAL · Inlet valve = 2.2 % Look for: The level steady at 10 m with the inlet at 2.2% against the outlet at 10%: the flows balance and nothing moves. |
| 2 | Open-loop actuator step | Sets: MANUAL · Inlet valve = 2.2 % · at t = 5 s: Inlet valve step Look for: Manual at 10 m. At 5 s the inlet steps from 2.2% to 1.2%. The level falls, to 7.6 m by 60 s, toward the 3.0 m the smaller inflow can hold: a slow, self-regulating response. |
| 3 | Closed-loop setpoint step | Sets: AUTO · Inlet valve = 2.2 % · at t = 5 s: setpoint step Look for: At 5 s the setpoint steps from 10 to 11.2 m. The shipped P-only loop ( Kp 10) rises in 4.6 s (10 to 90%) and settles about 0.01 m short. Without transmitter noise the level does not overshoot. With it the true level crosses 11.2 m by up to 9 mm, and the overshoot tile, which reads the noisy measurement, shows about 9%. |
| 4 | Disturbance rejection | Sets: AUTO · Inlet valve = 2.2 % · at t = 5 s: Manual outlet valve step Look for: At 5 s the outlet steps from 10 to 50%. The level falls and the P-only loop parks about 0.84 m low with the inlet at 10.6%, short of the 11.07% that would hold 10 m: proportional offset. |
| 5 | Recover by hand | Sets: MANUAL · Inlet valve = 2.2 % · at t = 5 s: Manual outlet valve step Look for: The same outlet step in Manual. Left alone, the tank drains to 0.5 m by 60 s. Setting the inlet to 11.1% holds 10.06 m. |
| 6 | Conservative tuning | Sets: AUTO · Inlet valve = 2.2 % · Proportional gain = 4.00 %/m · at t = 5 s: setpoint step Look for: Kp 4 on a 10 to 10.96 m step: a 12.2 s rise against 4.6 s for the reference gain on the same step, with about 40% of its valve travel. |
| 7 | Aggressive tuning | Sets: AUTO · Inlet valve = 2.2 % · Proportional gain = 20.00 %/m · at t = 5 s: setpoint step Look for: Kp 20: a 2.0 s rise and about twice the reference valve travel, mostly on transmitter noise, which also drives the valve to 0% at times. |
| 8 | Actuator limit | Sets: AUTO · Tank level setpoint = 6.00 m · Inlet valve = 85.7 % · Inlet valve coefficient = 10 kg/s/% · Manual outlet valve = 100 % · at t = 5 s: setpoint step Look for: The outlet wide open and a weaker inlet valve (10 kg/s per %): 6 m needs 85.7% of inlet. At 5 s the setpoint steps to 10 m. The inlet pins at 100% and the level climbs toward 8.16 m, the most the valve can hold. No tuning closes the gap. |
| 9 | MPC on a tank it was not fitted to | Sets: AUTO · Inlet valve = 2.2 % · Controller = MPC · at t = 5 s: Outlet valve to 50 % · at t = 30 s: setpoint step Look for: The outlet opens from 10 to 50% at 5 s, taking the tank away from the point the MPC’s model was fitted at, and the setpoint steps to 11.2 m at 30 s. The MPC is within 0.1 m of the new setpoint 1.0 s after the step and ends 0.003 m from it, with a scorecard IAE of 6.32 m·s and 92% of inlet travel over the 60 s run. The same case under the proportional PID ends 0.91 m short (IAE 48.4 m·s, 191% of travel). The Kalman filter carries the opened drain as an input disturbance of −8.8% of inlet. |
| 10 | 🎯 Challenge · return to target | Sets: AUTO · Inlet valve = 2.2 % · Proportional gain = 2.00 %/m · at t = 5 s: Manual outlet valve step Look for: One-fifth of the reference gain ( Kp 2) and the outlet step to 50% at 5 s. The judged worst error over 13.2 to 20 s is 2.97 m with the shipped tuning and 0.95 m with the suggested one (Kp 10, P only), against ±1.5 m. |
Reading the charts and the scorecard
The trends share one time axis, with a 15 s, 1, 3 or 5 min window (1 min by default).
- Tank level: the measured level with the setpoint and a ±0.5 m band.
- Inlet valve: 0–100%, the controller's output in Auto and your hand in Manual, shaded where it sits on a limit. Scripted events and your own changes (an outlet move, a setpoint step) are marked on the time axis.
The readings beside the tank give the outlet position and the outflow. The quickest hand
check of the mass balance is that at steady state the inflow c·uin/ρ
equals that outflow.
The MPC faceplate (Advanced → Predictive controller, with the Controller on MPC). The group already holds the MPC’s tuning, so the faceplate declares its Prediction horizon (20 to 720 s, shipped 360 s) and its Move suppression λ (0 to 1, shipped 0.03) and adds no slider. There is no band price: the plan’s only limits are the inlet valve’s hard range. Changes take effect at the next plan. Reset keeps them and reloading the case restores them. While the MPC is in charge every strip keeps the right-hand part of the window for the future, the shipped horizon’s share of it and never more than a third or less than a tenth (a third of every window, sized by the shipped 360 s whatever horizon is set): the plan whose first move was applied is drawn dashed after a “now” line, labeled MPC plan: the level the MPC’s model predicts from its estimate, one point per 0.5 s decision, and the inlet valve it plans, held over each decision. It is the controller’s prediction on its own model, identified at the design point, not the plant’s future. It disappears in Manual, under the PID and on a rejected plan. The Constraint prices lines (in the same group, while the MPC is selected) give, for each limit the accepted plan presses on (the inlet valve’s 0 and 100 %), how much of the MPC’s objective would be saved per unit that limit were relaxed (the QP’s own multipliers, summed over the plan): per unit of the controller’s objective as solved, which includes the solver’s small ridge (here under 0.01 % of every price), not money. They say so when no limit binds. On this studio a line appears in case 8 under the MPC, where the plan wants the valve past 100 % (up to 229 J per %). On the other cases no limit binds. Each slider was run at both ends of its range, all at their bottoms and all at their tops, and in two mixed extremes, on every scenario for its full length under the MPC with the Kalman filter and the MHE: no plan was rejected, every logged number stayed finite and the inlet valve inside its limits. Nothing run limited a range, so the sliders keep their shipped ranges.
Logged data and CSV export
Export CSV downloads every logged sample, five per second: the setpoint, the measured and the true level, the inlet valve, the saturation flag and the outlet valve. The logged measurement is the reading the controller acts on at that instant. Eight more columns follow them, the MPC’s: whether it is in charge, the Kalman filter’s estimates (logged under the PID too) and its latest plan. Twelve more follow those, added for the estimator choice and the relay autotune: the estimator chosen, the MHE’s estimate and its solver’s record, the relay’s state and its latest Ku and Pu.
| Column | Meaning | Units |
|---|---|---|
time | Simulated time since the run started, in seconds. | — |
mode | MANUAL or AUTO at that sample. | text |
scenario | Which scenario was loaded. | text |
sp | Level setpoint. | — |
pv | Measured level, including noise: the reading the controller acts on at that instant. Not clipped at zero. | — |
true_pv | The actual level, noise-free. Having both is what lets an offline identification separate them. | — |
mv | Inlet valve position: the value held over the 0.1 s control period just ended. | — |
saturated | 1 while the inlet valve sat at 0 or 100%. | — |
dist_outletValve | Outlet valve position. | — |
ctrl_mpc | 1 while the MPC is in charge (Auto with the Controller at MPC), otherwise 0. | — |
est_pv | The Kalman filter’s estimate of the level (m), updated at every 0.1 s execution whichever controller is in charge. | — |
est_d | The estimated unmeasured disturbance, in % of inlet: the load the MPC’s model does not have. | — |
mpc_pv_end | The level (m) the latest plan predicts at the end of its horizon. While the PID is in charge, the estimate est_pv. | — |
mpc_iters | Active-set iterations of the latest plan, 0 while the PID is in charge. | — |
mpc_slack | The largest soft-band slack of the latest plan. This MPC has no soft band, so it is always 0. | — |
mpc_fallback | 1 while a rejected plan has left the actuator with the PID. | — |
mpc_cost_us | Wall-clock time of the latest plan on the computer running the app, in µs, so it differs from run to run, 0 while the PID is in charge. | — |
mpc_estimator | 1 while the MHE is the estimator the MPC plans from (Estimator: MHE), 0 for the Kalman filter. | — |
mhe_pv | The MHE’s estimate of the level (m). The Kalman filter’s (est_pv) while Kalman is chosen. | — |
mhe_d | The MHE’s estimate of the unmeasured disturbance d, in % of valve. The Kalman filter’s (est_d) while Kalman is chosen. | — |
mhe_fallback | 1 at an execution whose MHE window was rejected, so the Kalman update of its prediction, inside the bounds, was used. | — |
mhe_iters | Active-set iterations of the latest MHE window, 0 while Kalman is chosen. | — |
mhe_active | Bound rows active in the latest MHE window: 0 when no bound binds (or Kalman is chosen). | — |
mhe_cost_us | Wall-clock time of the latest MHE window on the computer running the app, in µs, so it differs from run to run, 0 while Kalman is chosen. | — |
relay_on | 1 while a relay autotune drives the valve. | — |
relay_u | The valve applied (%): the relay’s output during an autotune, the controller’s otherwise. | — |
relay_cycles | Relay cycles closed in the running experiment, or in the last one, 0 before any. | — |
relay_ku | The relay’s latest ultimate gain Ku (% per m): updated at each counted cycle and kept after the experiment ends, converged or not, 0 before any. | — |
relay_period | The relay’s latest ultimate period Pu (s), as relay_ku. | — |
Keyboard shortcuts
| Key | Action |
|---|---|
Space | Run / pause the simulation |
R | Reset the run (keeps the scenario, tuning and parameters) |
M | Toggle MANUAL / AUTO |
E | Export the logged samples as CSV |
1 – 5 | Simulation speed (0.5×, 1×, 2×, 5×, 10×) |
? | Show the shortcut list inside the app |
If something looks wrong
| Symptom | Most likely cause | What to do |
|---|---|---|
| The level settles below setpoint and stays there | Proportional-only control after a load moved the valve position the tank needs | The offset is about Δuss/Kp. Predict it, then remove it by adding Ki. With the outlet shut there is no offset to remove. |
| Switched to Auto and the level did not move to setpoint | The velocity form's proportional term acts on changes of the error, so P-only keeps the error it was handed | Add Ki, or make the setpoint change after the switch. |
| The level will not come down | Outlet valve closed: the actuator can only add water | Open the outlet valve. With it shut the tank is an integrator with a fill-only actuator and no controller can lower the level. |
| The level rests a few centimeters above setpoint, with the outlet shut | Measurement noise cracking the valve open on a plant that cannot drain | Expected, and bounded: about 3.2σ above setpoint, 0.16 m at the default noise. Open the outlet and it goes. See the section on two behaviors that look like bugs. |
| The level reading goes negative on an empty tank | The instrument model does not clip its noise, deliberately | Correct behavior. Clipping would bias an empty tank by 0.399σ. Compare pv with true_pv in the CSV. |
| The tank overflows | The level saturates at the tank height and spills | Reduce the setpoint, open the outlet, or lower Kp. On a real plant this is the loop's consequential failure mode. |
| A setting changed before Run shows no response | A change before Run is a starting condition: the case starts settled with it | Press Run first, then make the change, to see a step response. |
| Two runs of the same experiment give different numbers | They should not | The noise is seeded and Reset restarts the realization, and the physics runs on the simulated clock, so every speed gives the same run. Reset keeps your settings. ↻ beside the scenario restores the case's own. |
4. Model
One state, the liquid level, and one algebraic instrument model. Integration is explicit Euler with 0.05 s substeps. The controller samples every 0.1 s. Both run on the simulated clock, so a run replays exactly.
Modeling assumptions
Every one of these is a deliberate simplification. Knowing which one you are standing on is the difference between a model you can teach with and a model you can design with.
- Tank cross section and water density are constant.
- Valve flow responds instantly to the command.
- Overflow is clamped at the tank height.
- The MPC plans on a first-order model fitted by a step test at 10 m with the outlet valve 10 % open (gain 9.03 m per % of inlet, lag 180.7 s). It does not know the square-root drain, so its gain is wrong away from that point. Its Kalman filter estimates an input disturbance d, which removes the offset.
- With the MHE estimator the MPC starts each plan from a fit of its model to the level readings of the last 30 controller periods (3 s) in which the level stays between the floor and the declared 12 m rim. With no bound active it is the Kalman filter’s estimate to within a millionth of the measurement noise. The window uses the Kalman filter’s own noise variances and its steady covariance as the cost of the window’s first state. A window the solver does not solve is replaced by the Kalman update of the MHE’s prediction, kept inside the bounds.
- The Relay autotune button (Advanced. The PID in Auto) replaces the PID by a relay about the inlet valve’s mean over the last 6 s (a tenth of a trend window), of amplitude d = 5 % of its span (less near a limit), switching each time the measurement crosses the setpoint by more than three times the declared noise (ε). When two cycles agree within 5 % the describing function of the relay’s fundamental gives the ultimate gain Ku from the swing ±a and the fraction D of each cycle spent on the high side (D = ½ for a symmetric cycle, where sin(πD) = 1), and the period Pu, and the Tyreus–Luyben PI rule is written into the tuning. Where the loop’s phase never reaches −180° (a lag with no dead time) the cycle sits where the hysteresis puts it, so Ku describes the experiment as much as the plant: the result note says so when the band sets the cycle (ψ = asin(ε/a) ≥ 10°), and the gains are always a starting point to try and edit.
Equations
Mass balance on the gravity-drained tank
With the outlet closed the second term vanishes and the tank is a pure integrator: dh/dt = 0.05·uin at the default parameters. With the outlet open, the square-root term is negative feedback internal to the process, and the tank becomes self-regulating.
Equilibrium level with the outlet open
The level goes as the square of the inlet valve position, so the incremental process gain dh/du grows with the operating level. One tuning is not right at every level.
Draining time from full
At the defaults this is 2√12/0.35 ≈ 20 s for a full 12 m tank at 100% outlet, which is where the 0.35 coefficient comes from.
PID controller (velocity form, derivative on the measurement)
Each cycle adds an increment every 0.1 s. There is no bias setting: the running output carries the operating point, and in Manual it tracks the inlet valve, so the switch to Auto is bumpless. With Ki on, back-calculation drives the integral toward the clipped output while the valve sits on a limit.
Steady-state offset of a proportional loop
From a start settled at setpoint with the valve at u0. With the outlet shut the tank holds still only with the inlet closed, so uss = u0 = 0 and the offset is zero. With the outlet open a load moves uss, and the offset is what integral action exists to remove: 0.84 m for case 4's outlet step at Kp = 10.
Instrument model
Zero-mean Gaussian noise, not clipped at zero. Clipping would bias an empty tank by σ/√(2π) = 0.399σ. The generator is a seeded mulberry32, so a noisy run replays exactly.
MPC controller model (identified at the design point)
Fitted by a step test at 10 m with the outlet 10% open (±0.2% inlet, RMS residual 0.0004 m). d is the input disturbance the Kalman filter estimates. The model does not know the square-root drain.
MPC objective, every 0.5 s
Ts = 0.5 s, τn = 180.7 s, ys = 0.5 m, us = 100%, N = 720 steps (360 s) in twelve move blocks, λ = 0.03. Only the first move is applied.
Variables
These are the quantities that move while the simulation runs. The app shows all of them live under Show Model → Variables.
| Symbol | Meaning | Units | Where it appears |
|---|---|---|---|
| h | True liquid level | m | The single integrated state, and what the tank visualization draws. |
| PV | Measured level | m | True level plus noise. This is what the controller acts on, and it is the trace on the level chart. Logged as pv, beside the true level true_pv. |
| SP | Level setpoint | m | From the setpoint control. The assignment value is 10 m. |
| e | Error, SP − PV | m | Note it is computed on the noisy measurement. |
| uin | Inlet valve position | % | The manipulated variable: your hand in manual, the controller output in auto. Clamped 0–100%. |
| uout | Outlet valve position | % | A process parameter and a disturbance. Adjustable in both modes. |
| qin | Inlet volumetric flow | m³/s | c·uin/ρ. |
| qout | Outlet volumetric flow | m³/s | cout(uout/100)√h, shown beside the tank. At steady state it equals the inlet flow, the quickest hand check in the app. |
Parameters and default values
Parameters are held constant while the simulation runs but can be edited under Show Model → Parameters. The default column is what the app loads with, and what every scenario in the table above is quoted against.
| Symbol | Name | Default | Range | Units | Meaning |
|---|---|---|---|---|---|
| Plant | |||||
area | Tank area | 1.00 | 0.30 – 5.00 | m² | The assignment default. A larger tank fills and drains more slowly. It divides the whole mass balance, so it is a pure time-scaling parameter. |
inletCoeff | Inlet valve coefficient | 50 | 10 – 100 | kg/s/% | Mass flow per percent open, from the assignment. With A = 1 m² and ρ = 1000 kg/m³ this gives dh/dt = 0.05u. Case 8 lowers it to 10. |
outletCoeff | Outlet coefficient | 0.35 | 0.10 – 0.80 | m³/s/√m | The Bernoulli coefficient at 100% open. The default drains a full 12 m tank in about 20 s. |
tankHeight | Tank height | 12.00 | 5.00 – 20.00 | m | Overflow height, and the top of the setpoint range. The level saturates here and the tank spills. |
sensorNoiseStdDev | Level noise | 0.05 | 0.00 – 0.30 | m | Zero-mean Gaussian noise on the reported level, seeded so a run replays exactly. Set it to 0 to see the loop without it. |
Numerical method and timing
The tank is integrated with explicit Euler in 0.05 s substeps and the controller samples every 0.1 s, both on the simulated clock inside a single loop. Nothing is driven by wall-clock timers, which has three consequences worth relying on: a run gives the same trajectory at every speed, the CSV time column steps by exactly 0.2 s, and browser timer jitter cannot change the closed-loop response.
The sensor noise is deterministic too. A mulberry32 generator seeded from a fixed
constant rather than Math.random, so a noisy run replays exactly and two
students can compare numbers. Reset restarts the noise realization along with the
state.
Euler at 0.05 s is comfortable here: the fastest thing in the model is a full tank draining in about 20 s. It is worth knowing that the choice is Euler rather than a higher-order method because the assignment's reference solution uses a fixed-interval ODE solve, and matching it matters more than the extra accuracy would.
How the model is checked
npm run test runs this app through the shared framework checks for model behavior, controller limits, scenario stability, reproducible reset, and CSV consistency. npm run build creates the deployable app and instructions.
5. Limitations
A browser simulation is a teaching instrument, not a plant model. These are the places where this one stops describing the real thing. Read them before quoting a number from it in a design.
Process representation
- One well-mixed lump with a single level state. No inlet jet momentum, no sloshing, no stratification, and no dynamics in the piping, the inlet flow responds to the valve instantly.
- The valves are ideal. Inlet flow is exactly linear in position and outlet flow exactly follows
√h, with no valve characteristic, no stiction, no hysteresis, no actuator lag and no stroking-rate limit. A real control valve has all five, and stiction in particular is the commonest cause of a cycling level loop in service. - No upstream or downstream pressure. The inlet coefficient does not depend on supply pressure and the outlet does not depend on backpressure, so neither is a disturbance here.
- Constant density and temperature, and no composition. The tank holds one fluid at one condition.
- Overflow and empty are hard clamps. The level saturates at the tank height and at zero with no spill dynamics, no weir behavior and no pump-suction consequence.
Instrument and control scope
- The MHE bounds the model’s states, not the plant’s, and the relay measures one experiment. The MHE’s bounds are box bounds on the states of the MPC’s own linear model, from declared values: where that model is wrong the MHE is wrong in the same way, inside its bounds, and with no bound active it adds nothing to the Kalman filter. On a loop with no dead time the relay’s Ku measures its band and the noise more than the plant, and Tyreus–Luyben is one conservative rule among many.
- The level measurement has noise and nothing else. No transmitter lag, no calibration drift, no bias, no quantization and no failure mode. A real level transmitter (differential-pressure, radar or float) has its own dynamics and its own characteristic errors.
- A velocity-form PID and one MPC on a fixed model. There is no cascade to a flow loop (which is how a real drum level is controlled), no feedforward from the outlet flow, no gain scheduling for the nonlinear gain, and no averaging-level or error-squared controller, all of which are standard answers to problems this app poses. The MPC plans on a first-order model fitted at 10 m with the outlet 10% open and is never refitted: away from that point its gain is wrong (five times too high with the outlet at 50%), and its Kalman filter, not its model, is what removes the offset.
- No alarms, trips or interlocks. Overflow is shown as a badge and nothing happens. On a real tank the high-level trip is the protection that matters.
- Explicit Euler at 0.05 s. Comfortable for this plant, and not a general-purpose choice: it was picked to match the assignment's reference solution rather than for accuracy.
- Perfect reproducibility. A real plant does not replay, and a real DCS's sample time jitters. The determinism here is a teaching convenience.
What this app is, and is not, evidence for
It is a sound demonstration of proportional offset and its exact magnitude, of the difference between an integrating and a self-regulating plant, and of how a velocity-form controller carries its operating point. It is not a tank or valve sizing tool, and with ideal valves and an ideal transmitter it cannot show the mechanical and instrument faults that cause most real level-loop problems.
6. Classroom and practice
Each of these has a number you can mark, and most are answered from the exported CSV. A setting chosen before Run starts the case settled with it, so make the change you want to observe after Run.
E1 · Verify the mass balance
With the outlet closed, hold the inlet valve at 10%, 20% and 40% and
measure dh/dt from the chart in each case. Compare with
c·u/(ρA). Then open the outlet to 100%, fill the tank, close the inlet, and
time the drain from 12 m. Compare with 2A√h₀/cout.
E2 · Predict the offset, in both regimes
First with the outlet shut: in case 1, shut the outlet and switch to Auto before Run, then step the setpoint to three different levels after Run and predict where the P-only loop lands each time. The answer is the new setpoint every time.
Now, from a settled start at 10 m with the outlet at 10%, step the outlet to 30, 50
and 80% after Run. For each, compute the valve position uss that
balances the drain at setpoint, predict (uss − u0)/Kp,
and compare with what the app settles at. Your prediction will be slightly large every time.
Explain why using the square-root outflow law, and say which level
uss should have been evaluated at.
Then repeat one of the open-outlet cases at Kp = 5, 10, 20 and
40 and confirm the offset scales as 1/Kp. Finally hand the loop a
standing error (setpoint 1 m above the level before switching to Auto) and explain from
the increment expression why P-only does not close it.
E3 · Remove the offset, and pay for it
With the outlet at 40% and the loop holding 10 m, sweep
Ki over 0, 0.25, 0.5, 1, 2 and 4 and record, after a step in the
outlet valve to 60%: the peak deviation, the time to return within 0.1 m, and the
total inlet-valve travel. Plot deviation against travel and recommend a value.
E4 · Show the process gain moves
With the outlet at 50%, tune the loop so that a 1 m setpoint step
around 3 m gives a well-damped response. Freeze that tuning and repeat the same
1 m step around 9 m. Report both responses, explain the difference from
h ∝ uin², and propose a gain schedule in h that
would fix it.
E5 · Derivative action, on the measurement
With the outlet at 50%, run (a) a 2 m setpoint step and (b) a 20-point step
in the outlet valve at Kd = 0, 5 and 20. Tabulate peak valve movement
and peak level deviation for all six runs. Then explain, from the increment expression, why
the derivative term adds nothing at the instant of the setpoint step, and what it does add
in (b) on a noisy level.
E6 · Quantify the noise offset
With the outlet closed and P-only, starting settled in Auto, run for five simulated minutes at noise levels of 0, 0.02, 0.05, 0.1 and 0.2 m and record the level rise in each case. The rise depends on the first reading the loop saw, and the noise is seeded, so to see the scatter between realizations change the setpoint slightly between repeats. Plot mean rise against σ and confirm it is roughly proportional. Then check that the rise stops rather than continuing: run σ = 0.2 m for five minutes and again for thirty, and compare. Finally repeat at σ = 0.05 m with the outlet at 2%, 5% and 10%, and report the opening at which the resting level falls below the noise-free prediction rather than above it.
E7 · For practitioners: specify the loop
Write the design basis you would hand over for this loop: the control objective (tight or averaging, and why), the tuning with its justification, the valve characteristic you would specify and why, the level-transmitter requirements, the high-level and low-level alarm and trip settings, and the behavior required when the inlet valve saturates. Then, from section 5, list what this model cannot tell you, particularly about valve stiction, and how you would check it on the real tank.
E8 · The model the MPC plans with, and the one it needed
Run case 9 under the MPC and export the CSV. Read est_d just before the
setpoint step at 30 s and check it against the inlet the tank needs at 10 m with the
outlet at 50%, u = ρcout(uout/100)√h/c, minus the model's
2.21%. Then, in Manual with the outlet at 50% and the level settled at 10 m, step the inlet
by 1% and fit a first-order model to the response. Compare its gain and time constant with the
MPC's 9.03 m/% and 180.7 s and with what the balance predicts, and explain why the MPC
still ends the case offset free.
E10 · What does the relay measure?
Load case 3, press Run and let the level settle at its new setpoint, then press Relay autotune (Advanced) and copy Ku, Pu and the swing ±a from the note. Set the level noise to 0, press Reset, let it settle and repeat. For each run compute ψ = asin(ε/a) with ε = 0.15 m (three times the declared noise, so the band does not shrink with yours) and compare Ku with the sampled model’s ultimate gain, 400 % per m at 0.2 s, and with the 107 the same relay gives on the noise-free model. Then run case 4 with the written gains and with the shipped ones: how much of the improvement is the integral action alone? (Try the shipped Kp with the written Ki.)
7. References and further reading
- APMonitor Tank Level exercise: the assignment this app implements, including the parameter values it defaults to
- APMonitor PID equations: the PID equations, of which the app runs the velocity form with derivative on the measurement
- Process Dynamics and Control course: the course this collection was built for
- Clara, the APMonitor assistant: the chat bubble in the corner of this page. Ask it why a proportional controller can be offset free on an integrating process, or check your mass balance
