Pid.scale(k) set self.k as persistent state, mutated from outside the class and never reset in reset(), so a stale scale factor could survive a state-transition reset. Replace it with a plain scale=1.0 argument on Pid.process(), and have temp_controller.py/temp_controller_smith.py compute the heat-rate-overshoot compensation factor themselves and pass it through process_pid() each tick instead of mutating pid_hold's state. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
30 lines
963 B
Python
30 lines
963 B
Python
from components.pid.temp_controller_base import TempControllerBase
|
|
|
|
|
|
class TempController(TempControllerBase):
|
|
def __init__(self, dt, params):
|
|
TempControllerBase.__init__(self, dt, params)
|
|
self.dt = dt
|
|
self.last_theta_ist = 20
|
|
self.heatrate_ist = 0
|
|
|
|
def process(self):
|
|
# Process Kalman
|
|
self.theta_ist = self.theta_ist_set
|
|
heatrate = (self.theta_ist - self.last_theta_ist)/self.dt*60
|
|
|
|
alpha = 0.1
|
|
self.heatrate_ist = (1-alpha) * self.heatrate_ist + alpha*heatrate
|
|
self.last_theta_ist = self.theta_ist
|
|
|
|
# Compensate for max heat rate to reduce overshoot
|
|
hold_scale = 1.0/self.heatrate_soll_set if self.heatrate_soll_set > 0 else 1.0
|
|
|
|
self.heatrate_soll = self.heatrate_soll_set * self.pid_hold.get_y()
|
|
theta_err = self.theta_soll_set - self.theta_ist
|
|
heatrate_err = self.heatrate_soll - self.heatrate_ist
|
|
|
|
diff = self.theta_soll_set - self.theta_ist
|
|
self.process_fsm(diff)
|
|
self.process_pid(theta_err, heatrate_err, hold_scale)
|