Week 10 · Monday, November 9, 2026 · Room D-221
The loop closes.
Your bench can sense, decide and act, and since last week it can do so across a network. Today it learns to hold a goal: a controller that watches the light level and steers the LED until reality matches the setpoint, then keeps it there against every shadow and flashlight you throw at it. The algorithm is PID, the workhorse behind the overwhelming majority of industrial control loops, and this hub is its full lesson: theory, curves, code, tuning.
What happens today
Theory · first hour
Feedback, and the three terms
What a closed loop is and how to grade one; why on/off control oscillates forever; the P, I and D terms each derived, pictured with computed response curves, and priced (P leaves an offset you can calculate, I erases it but can wind up, D damps but amplifies noise).
Lab · two hours
Hold the setpoint
A PIDController class on the node, built P → PI → PID with a tuning log; a flashlight and a hand as disturbances; anti-windup and noise handling; then the loop moves onto the network, Pi as controller, and finishes as supervisory control.
In the course outline
This is Week 10 of 420-302-VA, the close of phase 3. Assignment 2 (PID light harvesting, 15 %) is due at the start of class, submitted per the brief on Omnivox; today's lesson is the full theory behind what you built, so expect several "so that's why" moments. Next Monday, November 16, Week 11 opens the LIA project phase (40 %): the project brief lands and deliverable D1 is due that same week. Arriving there with a tuned, networked bench is this fortnight's whole purpose.
The week the system acts
Week 9's moment was a number crossing the air. This week's is better: set a target of 50 %, shine a flashlight at the sensor, and watch the LED dim itself, exactly enough, within a second, to cancel you out. Pull the light away and it recovers alone. Nothing in your code mentions flashlights. That is the deep trick of feedback: a controller that measures results does not need to predict causes, and the dumbest loop that watches reality beats the cleverest script that assumes it.
Why control theory, and why here
Control is the discipline your diploma is named for. The 243.D0 program exists because industry runs on loops: temperature, pressure, flow, level, speed, position, every one of them held at a setpoint by a controller, and the overwhelming majority of those controllers computing the same three-term law you implement today. Everything in the course so far was infrastructure for this week: Week 8 gave the loop its senses (ADC) and hands (PWM), Week 9 gave it a nervous system (MQTT), Weeks 5 and 6 gave the discipline (fixed-period timing, state in a class) that a controller's code demands. Today the stack does the thing stacks are for.
Three ideas you will reuse for the rest of your career
Feedback forgives ignorance
You will never have a perfect model of the room, the LDR or the LED. A closed loop does not need one: it measures the error and leans against it, so unmodelled disturbances are handled by construction, not by foresight.
Three terms, three tenses
P reacts to the error now, I to the error's accumulated past, D to its predicted future. Every behaviour of the loop, offset, recovery, overshoot, jitter, traces back to one tense doing too much or too little.
Tuning is empirical engineering
Gains are not derived at a desk; they are found at the bench, by ordered experiments, read off response curves, and logged. The method, not the final numbers, is the professional skill.
What you will be able to do by the end of the week
- Draw and label the closed-loop block diagram (SP, PV, e, u, plant, sensor, disturbance) and map each box to bench hardware.
- Grade a step response: rise time, overshoot, settling time, steady-state error, and disturbance recovery.
- Explain each PID term's job with its equation, including why P alone leaves a computable offset and why I removes it.
- Implement a
PIDControllerclass with measureddt, output clamping, anti-windup and derivative-on-measurement. - Tune a loop by the manual recipe, keep a tuning log, and diagnose a bad response curve by sight.
- Run the same loop locally on the node and distributed over MQTT, and argue when each architecture is right.
Words you will hear all day
| Term | Plain meaning | Common mix-up to avoid |
|---|---|---|
| Setpoint (SP) | The target value: "hold 50 % light". | A goal, not a measurement; the loop's job is making PV meet it. |
| Process variable (PV) | The measured reality: this instant's calibrated light percentage. | Always the sensor's word, never the code's assumption. |
| Error (e) | e = SP − PV, the gap the controller works to close. | Signed: too dark is positive, too bright negative; the sign steers. |
| Control output (u) | What the controller commands: LED duty, 0–100 %. | Clamped by the real actuator; the math does not know about limits until you teach it. |
| Plant | The thing being controlled: LED, air gap, room light, LDR together. | Includes the room; the plant is physics, not a component. |
| Disturbance | Any outside push on PV: a shadow, a flashlight, a cloud. | Not noise; a disturbance is real and the loop should cancel it. |
| Open / closed loop | Act without checking vs measure, compare, correct, repeat. | The difference is the feedback path, not the quality of the plan. |
| Gain | How hard a term pushes per unit of error: Kp, Ki, Kd. | Higher is not better; every gain buys speed with stability. |
| Steady-state error | The gap that remains once everything settles. | P-only control has one by design; the integral term exists to erase it. |
| Overshoot / settling time | How far PV blows past SP, and how long until it stays within a band. | Judged on the curve, within a stated band (we use ±5 %), not by eye alone. |
| Windup | The integral ballooning while the actuator is maxed out, then overshooting badly. | A saturation disease: the cure is to stop integrating, not to remove I. |
| Sample period (Δt) | The loop's heartbeat; ours is a fixed period with measured Δt. | Assumed Δt lies; Week 5's monotonic rule returns with a MicroPython twin. |
Where this fits in the course
Week 9 · Nov 2
MQTT and Wi-Fi
The nervous system: broker, topics, telemetry up and commands down. Today's distributed loop runs on exactly those channels.
Week 10 · Nov 9 · this hub
Control: closing the loop
Feedback theory, the three-term law with computed curves, a controller class, tuning, and the loop over the network. A2 due.
Week 11 · Nov 16
Flask & the project: the system gets a face
The Pi grows a web dashboard, and the LIA project phase opens with deliverable D1: your system gets a face and a mission.
Working at home
The whole week reproduces at home on the Week 9 setup: 2.4 GHz network, the Pi's address in config.py, both boards. The control lab itself needs no network at all until the distributed half, the local loop is one board, one LDR, one LED, so a bench-less evening can still tune gains with the node alone. Dim, steady room light makes the plant calmer than a bright window; tuning near a flickering lamp teaches you about noise sooner than planned.