Make FSM hysteresis thresholds configurable

THRESH_HOLD_IDLE/HOLD_HEAT/IDLE_HEAT/IDLE_HOLD/HEAT_HOLD/HEAT_IDLE in
tc_constants.py were hardcoded module-level constants shared by every
controller instance, so tuning the IDLE/HOLD/HEAT hysteresis required
a code change.

Replace them with DEFAULT_THRESHOLDS plus an optional
TempCtrl.Thresholds config section, merged at construction time in
TempControllerBase.__init__ so configs that omit the section keep
behaving exactly as before. Documented the new section in
config.json.templ; left config.json.sim without it to exercise the
default-fallback path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-18 22:09:39 +02:00
co-authored by Claude Sonnet 4.6
parent b2a5652290
commit 4256622e9d
4 changed files with 29 additions and 20 deletions
+8 -8
View File
@@ -1,7 +1,6 @@
from components import APid
from components.pid.pid import Pid
from components.pid.tc_constants import States, THRESH_HOLD_IDLE, THRESH_HOLD_HEAT, \
THRESH_IDLE_HEAT, THRESH_IDLE_HOLD, THRESH_HEAT_HOLD, THRESH_HEAT_IDLE
from components.pid.tc_constants import States, DEFAULT_THRESHOLDS
class TempControllerBase(APid):
@@ -17,6 +16,7 @@ class TempControllerBase(APid):
self.theta_ist = 0
self.heatrate_ist = 0
self.params = params
self.thresholds = {**DEFAULT_THRESHOLDS, **params.get('Thresholds', {})}
self.y = -1
self.state = States.INIT
self.use_kalman = True
@@ -72,22 +72,22 @@ class TempControllerBase(APid):
if not self.is_startup:
state_next = States.IDLE
elif self.state == States.IDLE:
if diff >= THRESH_IDLE_HEAT:
if diff >= self.thresholds['IdleHeat']:
state_next = States.HEAT
self.pid_rate.reset()
elif diff >= -THRESH_IDLE_HOLD:
elif diff >= -self.thresholds['IdleHold']:
state_next = States.HOLD
self.pid_rate.reset()
elif self.state == States.HOLD:
if diff >= THRESH_HOLD_HEAT:
if diff >= self.thresholds['HoldHeat']:
state_next = States.HEAT
self.pid_rate.reset()
elif diff <= -THRESH_HOLD_IDLE:
elif diff <= -self.thresholds['HoldIdle']:
state_next = States.IDLE
elif self.state == States.HEAT:
if diff <= -THRESH_HEAT_IDLE:
if diff <= -self.thresholds['HeatIdle']:
state_next = States.IDLE
elif diff <= THRESH_HEAT_HOLD:
elif diff <= self.thresholds['HeatHold']:
state_next = States.HOLD
self.pid_hold.reset()