TempControllerBase: require PID gains via set_params(), not the constructor
Mirrors components/pid/pid.py's own Pid.set_params() pattern: params/ thresholds start out None, and set_params() configures pid_hold/pid_heat/ pid_cool from them. process()/process_fsm() fail naturally (TypeError on None) if called before set_params() - same as Pid.process() already does - rather than a new bespoke check. Updates all callers (server/brewpi.py, SudForecastEstimator, and the pid/sud demo scripts) to call set_params() right after construction. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DkkuG48uHFCGKe6dPSERFk
This commit is contained in:
@@ -27,7 +27,7 @@ class States(enum.Enum):
|
||||
|
||||
class TempControllerBase(APid):
|
||||
|
||||
def __init__(self, dt, params):
|
||||
def __init__(self, dt):
|
||||
APid.__init__(self)
|
||||
self.pid_hold = Pid(dt)
|
||||
self.pid_heat = Pid(dt)
|
||||
@@ -44,13 +44,13 @@ class TempControllerBase(APid):
|
||||
self.heatrate_soll = 1.0
|
||||
self.theta_ist = 0
|
||||
self.heatrate_ist = 0
|
||||
self.params = params
|
||||
self.thresholds = {**DEFAULT_THRESHOLDS, **params.get('Thresholds', {})}
|
||||
# None until set_params() is called - mirrors Pid's own
|
||||
# params/set_params() (components/pid/pid.py), whose process()
|
||||
# already relies on the same "None means not configured yet".
|
||||
self.params = None
|
||||
self.thresholds = None
|
||||
self.y = -1
|
||||
self.state = States.INIT
|
||||
self.pid_hold.set_params(params['Hold'])
|
||||
self.pid_heat.set_params(params['Heat'])
|
||||
self.pid_cool.set_params(params['Cool'])
|
||||
self.is_startup = True
|
||||
# Master on/off switch: while disabled, the FSM is held in IDLE and
|
||||
# the controller tries not to drive the heater at all (output
|
||||
@@ -58,6 +58,13 @@ class TempControllerBase(APid):
|
||||
# (manual mode) or by SudTask for the duration of a run.
|
||||
self.enabled = False
|
||||
|
||||
def set_params(self, params):
|
||||
self.params = params
|
||||
self.thresholds = {**DEFAULT_THRESHOLDS, **params.get('Thresholds', {})}
|
||||
self.pid_hold.set_params(params['Hold'])
|
||||
self.pid_heat.set_params(params['Heat'])
|
||||
self.pid_cool.set_params(params['Cool'])
|
||||
|
||||
def on_state_entered(self, state):
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user