diff --git a/components/pid/temp_controller.py b/components/pid/temp_controller.py index 986fa3d..a23e95a 100644 --- a/components/pid/temp_controller.py +++ b/components/pid/temp_controller.py @@ -5,7 +5,15 @@ class TempController(TempControllerBase): def __init__(self, dt): TempControllerBase.__init__(self, dt) self.dt = dt - self.last_theta_ist = 20 + # None until the first process() tick - rather than hardcoding a + # starting point (e.g. 20), which would make that very first + # tick's heatrate come out as a bogus spike whenever the real + # starting temperature isn't actually 20 (see + # components/sud_forecast.py's SudForecastEstimator, which builds + # a fresh TempController on every call - unlike the real one, + # which only ever goes through this exactly once, it has no + # earlier ticks to have already settled past that spike by). + self.last_theta_ist = None self.heatrate_ist = 0 def process(self): @@ -13,7 +21,7 @@ class TempController(TempControllerBase): # Process Kalman self.theta_ist = self.theta_ist_set - heatrate = (self.theta_ist - self.last_theta_ist)/self.dt*60 + heatrate = 0 if self.last_theta_ist is None else (self.theta_ist - self.last_theta_ist)/self.dt*60 alpha = 0.1 self.heatrate_ist = (1-alpha) * self.heatrate_ist + alpha*heatrate diff --git a/components/pid/temp_controller_smith.py b/components/pid/temp_controller_smith.py index a806c2c..18bb534 100755 --- a/components/pid/temp_controller_smith.py +++ b/components/pid/temp_controller_smith.py @@ -6,7 +6,15 @@ class TempController(TempControllerBase): def __init__(self, dt): TempControllerBase.__init__(self, dt) self.dt = dt - self.last_theta_ist = 20 + # None until the first process() tick - rather than hardcoding a + # starting point (e.g. 20), which would make that very first + # tick's heatrate come out as a bogus spike whenever the real + # starting temperature isn't actually 20 (see + # components/sud_forecast.py's SudForecastEstimator, which builds + # a fresh TempController on every call - unlike the real one, + # which only ever goes through this exactly once, it has no + # earlier ticks to have already settled past that spike by). + self.last_theta_ist = None self.heatrate_ist = 0 # Fast model: same plant model but with zero transport delay, used @@ -60,7 +68,7 @@ class TempController(TempControllerBase): # so the dead time drops out of the feedback path. self.theta_ist = self.theta_ist_model + (self.theta_ist_plant - self.theta_ist_model_delay) - heatrate = (self.theta_ist - self.last_theta_ist)/self.dt*60 + heatrate = 0 if self.last_theta_ist is None else (self.theta_ist - self.last_theta_ist)/self.dt*60 alpha = 0.1 self.heatrate_ist = (1-alpha) * self.heatrate_ist + alpha*heatrate