Interactive closed-loop level control with a control valve on the inlet and a load-dependent outlet. Tune the PID controller, change the downstream demand, and watch the level track the setpoint.
Level L
—
m
Inlet Qin
—
m³/s
Outlet Qout
—
m³/s
Valve u
—
% open
Error
—
m
Sim time
—
s
Simulates pump / supply issues. 1.0 = nominal, 0.5 = degraded, 0 = pump dead.
Mass balance on the tank:
A = cross-section, L = level, Qin = inlet flow, Qout = outlet flow.
Torricelli's law (outlet):
Outflow depends on level only — as L rises the discharge rate increases.
Valve dynamics (1st-order lag):
u = PID output (0..1, valve fraction open). ΔP is assumed constant.
Control law (parallel form):
Derivative-on-measurement (avoids derivative kick on setpoint changes). Anti-windup via output clamping and integrator freezing.
Open-loop dynamics:
Linearised about operating point L0 — first-order, non-integrating. Tuning rule of thumb: Kp ≈ A·τ / (L·τ_v) for 1st-order-plus-dead-time.