Replace Pid.scale()'s mutable gain factor with a stateless process() arg

Pid.scale(k) set self.k as persistent state, mutated from outside the
class and never reset in reset(), so a stale scale factor could survive
a state-transition reset. Replace it with a plain scale=1.0 argument on
Pid.process(), and have temp_controller.py/temp_controller_smith.py
compute the heat-rate-overshoot compensation factor themselves and pass
it through process_pid() each tick instead of mutating pid_hold's state.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-19 17:37:55 +02:00
co-authored by Claude Sonnet 4.6
parent 519bbd485f
commit 1e89a58370
5 changed files with 20 additions and 26 deletions
+9 -8
View File
@@ -22,14 +22,15 @@ git history for `temp_controller.py`/`temp_controller_smith.py`).
`temp_controller_smith.py` was rewritten to drop Kalman filtering
entirely (see below), so there's no shared tuning to split anymore.
- [ ] **`Pid.scale()` is a gain-scheduling hack, not anti-windup.**
`pid.py`'s `scale(k)` multiplies every gain by `1/heatrate_soll_set`
(called from `temp_controller*.py`'s `process()`), but it's framed
as overshoot compensation, conflated with the real anti-windup logic
a few lines below. `self.k` also never resets in `reset()`, so a
stale scale factor can survive a state-transition reset. Consider
moving this scheduling logic out of the generic `Pid` class and into
the temp controller, and resetting `k` in `reset()`. Still present.
- [x] **`Pid.scale()` is a gain-scheduling hack, not anti-windup.**
Fixed: removed `Pid.scale()`/`self.k` entirely. `Pid.process(err, d,
scale=1.0)` now takes the gain multiplier as a plain per-call
argument instead of mutable state, so there's nothing to go stale
across a `reset()`. `temp_controller*.py` compute `hold_scale =
1.0/heatrate_soll_set if heatrate_soll_set > 0 else 1.0` themselves
and pass it through `process_pid(theta_err, heatrate_err,
hold_scale)` — the overshoot-compensation scheduling logic now lives
entirely in the temp controller, not the generic `Pid` block.
- [ ] **No automated tests.** `tests/components/pid/` was added once
(stdlib `unittest`, no pytest) covering FSM transitions, anti-windup