Require TempController(Smith)'s model params/ambient via setters; add comprehensive process() checks
TempController(Smith).__init__ no longer takes model_params/theta_amb - set_model_plant_params() and the existing set_ambient_temperature() must be called instead (mirrors components/plant/pot.py's own Pot constructor refactor). temp_controller.py's now-pointless model_params/theta_amb constructor placeholders (kept only for "compatibility" with Smith) are dropped too. Both TempController variants now raise a clear RuntimeError from process() itself if set_params() wasn't called, instead of letting it surface deep inside Pid.process() as an opaque "'NoneType' object is not subscriptable". Smith additionally checks its internal models via Pot.is_configured() (new) and raises if set_model_plant_params()/set_ambient_temperature() weren't called either. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DkkuG48uHFCGKe6dPSERFk
This commit is contained in:
@@ -65,6 +65,16 @@ class TempControllerBase(APid):
|
||||
self.pid_heat.set_params(params['Heat'])
|
||||
self.pid_cool.set_params(params['Cool'])
|
||||
|
||||
def _require_params(self):
|
||||
"""Called by each subclass's process() before doing anything else -
|
||||
without it, a missing set_params() call would otherwise only
|
||||
surface as an unhelpful "'NoneType' object is not subscriptable"
|
||||
buried inside Pid.process() (components/pid/pid.py), once
|
||||
process_pid() below gets to it."""
|
||||
if self.params is None:
|
||||
raise RuntimeError(
|
||||
"{}.process(): PID gains not set - call set_params() first".format(type(self).__name__))
|
||||
|
||||
def on_state_entered(self, state):
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user