fix: allow gentle negative HOLD floor to fix steady-state overshoot

Testing the windup-fix rework live against sude/sud_0030.json surfaced a
distinct bug: a HOLD overshoot from grain-fill-in cooling never decayed -
process_pid()'s pid_outer_y floor clamped to exactly 0.0, so pid_inner
fought the pot's own ambient loss to hold the overshot temperature flat
instead of declining back to setpoint (see docs/overshoot2.png).

Replace the hardcoded 0.0 floor with a configurable Outer.y_hold_min
(default 0.0, backward compatible), set to -0.1 in config.json, both
.tpl templates, and the demo scripts - small enough to avoid
reintroducing the bb5af3c limit cycle while letting HOLD request a
gentle decline matching passive ambient cooling.

Adds TestHoldOvershootRecoversToSetpoint and documents the finding in
docs/overshoot_hold_windup.md's Follow-up section and
components/pid/TODO.md. Confirmed against a live sud_0030 re-run, not
just the unit test.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M2ierBoxW3v7nUbDw3M2pE
This commit is contained in:
2026-07-06 08:19:10 +02:00
co-authored by Claude Sonnet 5
parent 11c3d92f25
commit 2d032bf9b2
11 changed files with 274 additions and 13 deletions
+19 -6
View File
@@ -21,6 +21,7 @@ class TempControllerBase(TempControllerFsm, APid):
self.params = None
self._inner_heat_params = None
self._inner_hold_params = None
self._outer_hold_y_min = 0.0
self.y = -1
# Heat-rate pre-filter state (option A) - None until first process() tick
self.last_theta_ist = None
@@ -32,6 +33,11 @@ class TempControllerBase(TempControllerFsm, APid):
self.thresholds = {**DEFAULT_THRESHOLDS, **params.get('Thresholds', {})}
self.beta = params.get('beta', 0.05)
self.pid_outer.set_params(params['Outer'])
# How far into "actively cool" pid_outer is allowed to reach during
# HOLD - see the floor in process_pid() below. Defaults to 0.0
# (old flat-clamp behaviour) so configs that don't set it are
# unaffected.
self._outer_hold_y_min = params['Outer'].get('y_hold_min', 0.0)
self._inner_heat_params = params['Inner']['Heat']
self._inner_hold_params = params['Inner']['Hold']
self.pid_inner_cool.set_params(params['Inner']['Cool'])
@@ -135,14 +141,21 @@ class TempControllerBase(TempControllerFsm, APid):
def process_pid(self, theta_err, hold_scale=1.0):
self.pid_outer.process(theta_err, -self.theta_ist, hold_scale)
# In HOLD state, clamp pid_outer's output to [0, 1]: a small temperature
# overshoot makes pid_outer.y go negative, which would invert heatrate_soll
# and drive pid_inner's power to 0, causing a limit cycle (power on →
# overshoot → power off → coast down → repeat). Clamping to 0 lets the
# outer loop reduce the inner setpoint to zero but no further.
# In HOLD state, floor pid_outer's output at Outer.y_hold_min (<= 0)
# rather than letting it swing all the way to -1: a large negative
# heatrate_soll asks for a decline far steeper than the pot's own
# ambient heat loss can deliver, so pid_inner pins power at 0 for an
# extended stretch, undershoots, and swings back hard - a ~110s
# limit cycle (see git history for this clamp). A small negative
# floor instead lets HOLD ask for a gentle decline that roughly
# matches passive cooling, so a small overshoot coasts back down to
# setpoint instead of sitting in a permanent flat-clamp dead zone
# (the outer loop otherwise commands "stay flat" forever, and
# pid_inner actively fights the pot's own ambient loss to hold that
# flat line - see docs/overshoot_hold_windup.md).
pid_outer_y = self.pid_outer.get_y()
if self.state == States.HOLD:
pid_outer_y = max(0.0, pid_outer_y)
pid_outer_y = max(self._outer_hold_y_min, pid_outer_y)
self.heatrate_soll = self.heatrate_soll_set * pid_outer_y
heatrate_err = self.heatrate_soll - self.heatrate_ist