A village hall is heated by a big hot-water system controlled by a proportional controller. The water takes a while to warm up, so the heat reaching the hall lags behind the controller's command: there are two slow things in the loop, the radiators and the hall. The caretaker wants a table that shows, for several candidate gains Kp, how the hall responds when the heating is switched on.
The hall starts at the outside temperature, T = T_out, and the radiators start cold, Q = 0 (kW of heat delivered). Each minute, in this order:
p = Kp * (setpoint - T), then limited to the range 0..20 (the command, kW)
Q = Q + (p - Q) / 20 (the radiators catch up slowly)
T = T + (T_out - T) / 100 + 0.05 * Q (the hall, using the new Q)
With a proportional controller the hall does not settle at the setpoint but at the final value
final = (T_out + 5 * Kp * setpoint) / (1 + 5 * Kp)
(where the leak (T - T_out) / 100 equals the heating 0.05 * Kp * (setpoint - T)).
For every gain, simulate minutes minutes and record T[0] = T_out, T[1], ..., T[minutes]. Then measure, against final:
- the percent overshoot:
100 * (peak - final) / (final - T_out)wherepeakis the highest temperature, or0.0if the peak is not abovefinal; - the settling time in minutes: the smallest index
isuch thatT[i]and every later temperature satisfyabs(T[j] - final) <= 0.02 * (final - T_out);NoneifT[minutes]is outside that band.
Write tuning_table(setpoint, T_out, gains, minutes) that returns a list with one tuple (overshoot, settling) per gain, in the order of gains. Plotting the four responses of the first example on one chart is the best way to see what the table says.
Examples
Input: setpoint = 20, T_out = 5, gains = [0.5, 1, 2, 10], minutes = 600
Output: [(3.76811841, 139), (12.53870234, 105), (25.63328505, 132), (40.44315617, 143)]
Explanation: the final values are 15.71, 17.5, 18.64 and 19.71 °C: a bigger gain gets
closer to the setpoint, but the lagging radiators make it overshoot more and more.
Kp = 1 settles fastest.
Input: setpoint = 20, T_out = 5, gains = [1], minutes = 3
Output: [(0.0, None)]
Explanation: the hall goes 5, 5.0375, 5.11015625, 5.215658984 and is far from 17.5.
Constraints
- answers are compared with a tolerance of
1e-6; do not round - every call must finish quickly: at most about 10**5 simulated minutes in total
Goals
- Simulate a loop with two states: a slow heater and a slow room
- Measure overshoot and settling time against a computed final value
- See the trade-off a controller gain controls: speed and accuracy against overshoot