What you learn today
- Hold a room with a PI controller
- Anti-windup
- Show the trend
This week showed P, PI, D, tuning and cascades in small pieces. Now you build a controller that really holds a room: the lab with a wall heater, a dial for the setpoint and two displays for the trend.
The plant
| Device | Prefab | Name |
|---|---|---|
| gas sensor in the room | StructureGasSensor | “Raum” |
| wall heater | StructureWallHeater | “Heizung” |
| dial | StructureLogicDial | “Soll” (setpoint in °C) |
| LED display | StructureConsoleLED5 | “Leistung” (output in %) |
| LED display | StructureConsoleLED5 | “Abweichung” (in K) |
The wall heater gives off 1000 J per tick and only runs above 6.3 kPa. It knows only On – no Setting, no half power.
PI controller with pulse width
The PI controller computes an output u between 0 and 1. Because the heater can only be on or off, you turn that into pulse width modulation (PWM): in a window of 10 ticks the heater is on for as many ticks as u says. u = 0.3 means 3 ticks on, 7 off.
add tick tick 1
mod tick tick WINDOW # 0 to 9, then start over
mul tmp u WINDOW
slt on tick tmp # on while tick < u * 10
A room is sluggish enough not to notice switching on and off within a 5-second window. It only feels the average power.
The controller itself is the one from day 156, only in kelvin and with u from 0 to 1:
sub e target t
mul tmp e KI
add i i tmp
clamp i i 0 1 # anti-windup: never more than full power
mul u e KP
add u u i
clamp u u 0 1
Setpoint and failures
- The dial delivers °C.
add target target CELSIUSOFFSETturns it into kelvin. If the dial is missing,targetis NaN – then TARGET_STD (20 °C) applies. - If the sensor is missing,
tis NaN. Then: heater off, “Leistung” shows −1, “Abweichung” 0, andiis not touched. Otherwise the controller is poisoned after the repair.
Milestones
- Cold room: heater on, “Leistung” 100, “Abweichung” in K
- Close to the setpoint the I term pushes on and holds the output once the setpoint is reached
- PWM: at u = 0.5 the heater is on in the first half of the window and off in the second
- Anti-windup: after a long cold spell the heater switches off as soon as the room is above the setpoint
- Setpoint from the dial, 20 °C without the dial
- Sensor gone: heater off, “Leistung” −1,
istays put
The registers i (r3) and tick (r5) are fixed in the starter code. The tests set them directly for the PWM check – keep that assignment.
Without clamp i i 0 1 the I term collects values far above 1 during a cold night. In the morning the heater then keeps heating at full power for a long time even though the room is long warm.
Project task
Task
Build the PI heater controller following the sections above. The defines, aliases and reading the sensor are already there. Missing are the setpoint, the NaN check, the controller with anti-windup, PWM, both displays and the fault branch.
Milestones
- Milestone 1: cold room, full output
- Milestone 2: I term pushes on and holds
- Milestone 3: PWM in a window of 10 ticks
- Milestone 4: anti-windup after a long cold spell
- Milestone 5: setpoint from the dial
- Milestone 6: sensor gone, safe state
Hints
Hint 1
Setpoint: lbn target DIAL HASH("Soll") Setting Average, add target target CELSIUSOFFSET, then snan tmp target and select target tmp TARGET_STD target.
Hint 2
Right after reading the sensor bnan t fault. In the fault: branch switch the heater off and set the displays – do not touch i.
Hint 3
Controller: first accumulate i and limit it with clamp i i 0 1, then u = KP · e + i, also limited to 0 to 1.
Hint 4
PWM: add tick tick 1, mod tick tick WINDOW, mul tmp u WINDOW, slt on tick tmp.
Quiz
2 questions. You pass from 60 % – the server does the grading.
Complete the day
- Passed all milestones of the project
- Passed the quiz with at least 60 %
Without an account progress is saved in this browser only.
Report a mistake in this lesson
Please sign in to report. Sign in