fix: split inner-loop yi_max clamp to fix HOLD-state windup overshoot
Renames pid_hold/pid_heat/pid_cool to pid_outer/pid_inner/pid_inner_cool
to match what actually runs when, and splits inner-loop config into
Inner.Heat/Inner.Hold/Inner.Cool so the same PID instance gets a tight
yi_max ceiling only while HOLD drives it, without capping legitimate
1.5 K/min ramps. Fixes the overshoot from docs/overshoot_hold_windup.md
where a cold-water disturbance during HOLD wound up pid_heat's integral
term with no anti-windup engagement, taking ~35s+ to unwind naturally.
Breaking config change: Hold/Heat/Cool -> Outer/Inner.{Heat,Hold,Cool}
in config.json, both .tpl templates, the pid/sud demo scripts, and
replay_sim.py's CLI flags. Adds tests/components/pid/ (stdlib unittest)
covering the Pid clamp/recovery behavior and closed-loop disturbance,
ramp, and HOLD<->HEAT transition cases.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DGQhVQ2Y3yXAQTXhrxVd5u
This commit is contained in:
@@ -19,6 +19,8 @@ class TempControllerBase(TempControllerFsm, APid):
|
||||
# params/set_params() (components/pid/pid.py), whose process()
|
||||
# already relies on the same "None means not configured yet".
|
||||
self.params = None
|
||||
self._inner_heat_params = None
|
||||
self._inner_hold_params = None
|
||||
self.y = -1
|
||||
# Heat-rate pre-filter state (option A) - None until first process() tick
|
||||
self.last_theta_ist = None
|
||||
@@ -29,9 +31,10 @@ class TempControllerBase(TempControllerFsm, APid):
|
||||
self.params = params
|
||||
self.thresholds = {**DEFAULT_THRESHOLDS, **params.get('Thresholds', {})}
|
||||
self.beta = params.get('beta', 0.05)
|
||||
self.pid_hold.set_params(params['Hold'])
|
||||
self.pid_heat.set_params(params['Heat'])
|
||||
self.pid_cool.set_params(params['Cool'])
|
||||
self.pid_outer.set_params(params['Outer'])
|
||||
self._inner_heat_params = params['Inner']['Heat']
|
||||
self._inner_hold_params = params['Inner']['Hold']
|
||||
self.pid_inner_cool.set_params(params['Inner']['Cool'])
|
||||
|
||||
def _compute_heatrate(self, theta_ist):
|
||||
"""Pre-filter theta_ist, then differentiate and low-pass to get heatrate_ist.
|
||||
@@ -131,31 +134,33 @@ class TempControllerBase(TempControllerFsm, APid):
|
||||
return self.heatrate_soll_set
|
||||
|
||||
def process_pid(self, theta_err, hold_scale=1.0):
|
||||
self.pid_hold.process(theta_err, -self.theta_ist, hold_scale)
|
||||
# In HOLD state, clamp pid_hold's output to [0, 1]: a small temperature
|
||||
# overshoot makes pid_hold.y go negative, which would invert heatrate_soll
|
||||
# and drive pid_heat's power to 0, causing a limit cycle (power on →
|
||||
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.
|
||||
pid_hold_y = self.pid_hold.get_y()
|
||||
pid_outer_y = self.pid_outer.get_y()
|
||||
if self.state == States.HOLD:
|
||||
pid_hold_y = max(0.0, pid_hold_y)
|
||||
self.heatrate_soll = self.heatrate_soll_set * pid_hold_y
|
||||
pid_outer_y = max(0.0, pid_outer_y)
|
||||
self.heatrate_soll = self.heatrate_soll_set * pid_outer_y
|
||||
heatrate_err = self.heatrate_soll - self.heatrate_ist
|
||||
|
||||
# Only the PID actually driving y is advanced - otherwise the
|
||||
# inactive one (e.g. pid_heat while COOL has pid_cool driving)
|
||||
# inactive one (e.g. pid_inner while COOL has pid_inner_cool driving)
|
||||
# would keep silently integrating against a heatrate_err that
|
||||
# isn't actually under its control, building a stale windup that
|
||||
# causes a discontinuity in y the moment it takes back over.
|
||||
if self.state == States.IDLE:
|
||||
self.y = 0
|
||||
elif self.state == States.COOL:
|
||||
self.pid_cool.process(heatrate_err, -self.heatrate_ist)
|
||||
self.y = self.pid_cool.get_y()
|
||||
self.pid_inner_cool.process(heatrate_err, -self.heatrate_ist)
|
||||
self.y = self.pid_inner_cool.get_y()
|
||||
else:
|
||||
self.pid_heat.process(heatrate_err, -self.heatrate_ist)
|
||||
self.y = self.pid_heat.get_y()
|
||||
inner_params = self._inner_heat_params if self.state == States.HEAT else self._inner_hold_params
|
||||
self.pid_inner.set_params(inner_params)
|
||||
self.pid_inner.process(heatrate_err, -self.heatrate_ist)
|
||||
self.y = self.pid_inner.get_y()
|
||||
|
||||
self.post_pid()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user