What you learn today
- Check assumptions
- Secure limits
- Defined states
A script that only works in the normal case has an expiry date. Sooner or later someone turns the room temperature dial to 90, moves the sensor to the workshop or renames a light. Robust means: the chip expects such days and still behaves sensibly.
Write down your assumptions and check them
Every lbn line is full of assumptions. Write them down once:
| Assumption | Check |
|---|---|
| The device exists and has this name | catch NaN: snan, snanz or a comparison like sgt ok t 0 |
| The value lies in a sensible range | plausibility: Ratio between 0 and 1, pressure not negative |
| The value is an integer | trunc or round before it becomes a stage or a mode |
| The player sets something sensible | limits with clamp |
Securing limits
Everything that comes from outside – a dial, a Logic Memory, another chip – is limited before the chip calculates with it:
lbn soll KNOPF HASH("Soll") Setting Average
snan tmp soll
select soll tmp SOLL_STD soll # no dial: default value
clamp soll soll SOLL_MIN SOLL_MAX # 16 to 28 C, whatever is set
The same goes for outputs. If you compute a pump power, clamp it to the allowed range instead of hoping the calculation never overshoots.
Defined states
Every output gets a value in every pass. There is no path through the code on which a heater “somehow stays on” because a jump skipped the line. And for the fault case there is exactly one safe state, which you decide in advance:
| Device | safe state |
|---|---|
| heater | off |
| cooling of a pantry | on |
| airlock door | closed and locked |
| fill pump | off |
| warning light | on |
clamp does not protect against NaN. If r1 holds NaN, clamp r0 r1 16 28 gives NaN again. Replace NaN first, then limit – the order in the example above is no accident.
Exercise
Task
The dial “Soll” gives the desired temperature in °C. Secure it: if it is missing, 21 °C applies, otherwise it is limited to 16 to 28 °C. The display “SollAnzeige” shows the effective setpoint. The heater “Wohnraum” switches on 1 K below the setpoint and off 1 K above it. If the sensor “Wohnraum” is missing: heater off, light “Stoerung” on.
Hints
Hint 1
First snan, then select with SOLL_STD, then clamp – in this order.
Hint 2
For the hysteresis convert the setpoint to Kelvin and build both limits with add/sub.
Hint 3
At the end and on on ok, so the heater is off on NaN.
Quiz
4 questions. You pass from 60 % – the server does the grading.
Complete the day
- Passed the simulator exercise
- 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