Problem 127920 · medium · Level 01 Prerequisites & Setup

A Heater That Pushes Harder When It Is Colder

closed loop · proportional control · saturation · steady-state error

An electric radiator in a workshop is controlled by a proportional controller: every minute it measures the temperature, computes the error (how far below the setpoint the room is) and delivers a power proportional to it. A big error gives a big push; as the room approaches the setpoint the push fades away. The radiator can deliver between 0 and 4 kW, so the command is saturated (limited) to that range.

The workshop has tau = 100 minutes and gain = 0.05 °C per minute per kW, and the time step is dt = 1 minute. Starting from temperature T0, each minute does exactly this, in this order:

error = setpoint - T
p     = Kp * error, then limited to the range 0..4
T     = T + 1 * ((T_out - T) / 100 + 0.05 * p)

Write p_heater(setpoint, T0, T_out, Kp, minutes) that runs minutes steps and returns a tuple (T, full): the temperature at the end, and the number of minutes in which the radiator ran at full power (the command Kp * error was at least 4 kW, so it was limited to 4).

Plot the temperature over a few hundred minutes (collect it in a list and press Run with plot(temps)): the room never quite reaches the setpoint. That gap is the steady-state error of proportional control: the radiator only delivers power while there is an error, so some error must remain to hold the room above the outside temperature.

Examples

Input:  setpoint = 20, T0 = 10, T_out = 5, Kp = 2, minutes = 3
Output: (10.445515, 3)
Explanation: minute 1: error 10, command 20 kW, limited to 4 (full power);
T = 10 + (5 - 10) / 100 + 0.05 * 4 = 10.15. Minutes 2 and 3 are also at full power.

Input:  setpoint = 20, T0 = 10, T_out = 5, Kp = 2, minutes = 600
Output: (18.6363636, 76)
Explanation: after 76 minutes at full power the command falls below 4 kW;
the room then settles about 1.36 °C short of the setpoint.

Constraints

  • answers are compared with a tolerance of 1e-6; do not round

Goals

  • Simulate a closed loop: measure, compute the error, act, update
  • Limit a controller's command to what the actuator can deliver
  • See that a proportional controller settles short of its setpoint
Starting Python…