Week 5 · Lesson 2 · 55 minutes

Program a simple controller

I can test a threshold rule at its boundary.

Planned lesson. Follow your teacher’s teaching order.

Source workbook pages: 31.

Resources

Vocabulary

Vocabulary
threshold: a value where the decision changes; boundary test: a test at or next to a decision limit
55-minute lesson sequence
  1. 0–5 · Retrieve actuator role.
  2. 5–15 · Predict and run the threshold model.
  3. 15–25 · Guide one normal test and draw the decision diamond.
  4. 25–45 · Students implement the validation rule and run all six boundary/fault tests.
  5. 45–50 · Inspect the None test before any comparison and discuss context-dependent safety.
  6. 50–55 · Collect the equality-test explanation.

Try before notes

Which component actually changes the room temperature?

Build the idea

A threshold rule changes its decision at a boundary. Read the comparison symbol carefully: less than excludes equality, while less than or equal includes it. Choose tests immediately below, at and above the boundary.

Predict the Boolean result before running code. Then record actual output. A successful run only shows the program ran; comparison with the expected result shows whether it met the rule.

Invalid input needs a specified response. Check for a missing value before numeric comparisons so the program does not compare None with a number. This is a simulation; real physical safety needs a separate engineered design.

input → valid? ─no→ fault response
             yes
              ↓
          threshold? → action

See the method

In this simplified model the heater is on below 20 degrees and off otherwise. Predict before running. This is a simulation, not instructions for wiring a real heater.

def heater_on(temp):
    return temp < 20

print(heater_on(19))
print(heater_on(20))

Predict then reveal

A simulated cooling fan runs when temp>28. Predict results for 27,28,29.

Reveal reasoning

27>28 is False; 28>28 is False; 29>28 is True. The boundary value 28 distinguishes this rule from temp>=28.

A reading may be None. Why check temp is None before evaluating temp>28?

Reveal reasoning

None represents missing data, not a numeric temperature. Python cannot order None and 28, so the comparison raises a TypeError. Handle the missing case first, then compare valid numbers.

Work one step together

Read the first task. Each learner predicts the first step privately. Compare the method, then complete one intermediate row or one code iteration together. Do not display a finished workbook answer.

Practice

  1. Predict and test temperatures 18,19,20,21. Record the Boolean outputs. Write an equivalent flowchart with a decision diamond and both branches.

Your turn

Complete the remaining steps of task 1 alone, then the next tasks. Predict before running code. Save your own evidence before comparing.

Practice

  1. Predict and test temperatures 18,19,20,21. Record the Boolean outputs. Write an equivalent flowchart with a decision diamond and both branches.
  2. Add a rule: a missing reading represented by None, or a reading outside 0–50, returns False and reports a fault. Assume every other input is numeric. Test None,-1,0,20,50,51. Explain one limit of using “heater off” as a fault response.

Check and explain

Testing only far from the threshold can miss an equality error.

Point to the first step, row, condition or requirement that supports your answer. If results differ, find the first different state and repair one cause.

Show what you know

Why test exactly 20, not only 10 and 30?

HL challenge when ready

Readings jump 19.9,20.1,19.9,20.1. What may the simple controller do?

Week 5 homework

Show working. Keep code and output. Stop at 25 minutes and mark where you reached.

  1. Draw a closed-loop automatic door system. Label sensor, controller, actuator, controlled process and feedback. Explain one possible fault.
  2. Trace the hysteresis rule from off for 20,18,21,22,19. Explain both exact-boundary cases.
  3. Choose a cloud model for a team that must configure its own OS. Explain what extra work this choice brings.
  4. Retrieve memory: why must a log be written to persistent storage if it should survive power loss?

Source workbook pages: 35.

Weekly homework (Word)

Python practice · two short prompts

Spend about 3 minutes on each during practice time. Predict, run, change one thing, then explain. These prompts do not add homework.

A starter is runnable code to explore or complete. If the playground restores your saved code, the linked starter is selected in Example: use Load example when ready. Download your work before confirming replacement.

Prompt 1

Complete a function that turns a fan on above a threshold. Test below, equal and above.

No imports needed.

Hint and starter code

A threshold is the boundary where a decision changes; > excludes equality.

# A threshold is the boundary where a decision changes; > excludes equality.
def fan_on(temperature):
    return False  # Your turn: compare with 28

for temperature in [27, 28, 29]:
    print(temperature, fan_on(temperature))
Open this starter in Python playground →
Prompt 2

Reject a missing reading before doing a comparison.

No imports needed.

Hint and starter code

None means no reading in this model. Do not silently treat it as zero.

# None means no reading in this model.
reading = None
if reading is None:
    print("sensor unavailable")
else:
    print(reading > 28)
Open this starter in Python playground →