Replace Pid.scale()'s mutable gain factor with a stateless process() arg
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>
This commit is contained in:
+5
-10
@@ -5,8 +5,6 @@ class Pid:
|
||||
self.dt = dt
|
||||
self.params = None
|
||||
|
||||
self.k = 1.0
|
||||
|
||||
# Integrator
|
||||
self.yi = 0
|
||||
|
||||
@@ -21,9 +19,6 @@ class Pid:
|
||||
# Output
|
||||
self.y = 0
|
||||
|
||||
def scale(self, k):
|
||||
self.k = k
|
||||
|
||||
def set_params(self, params):
|
||||
self.params = params
|
||||
|
||||
@@ -32,12 +27,12 @@ class Pid:
|
||||
self.d = 0
|
||||
self.awu = 0
|
||||
|
||||
def process(self, err, d):
|
||||
def process(self, err, d, scale=1.0):
|
||||
dt = self.dt
|
||||
kp = self.params['kp'] * self.k
|
||||
ki = self.params['ki'] * self.k
|
||||
kd = self.params['kd'] * self.k
|
||||
kt = self.params['kt'] * self.k
|
||||
kp = self.params['kp'] * scale
|
||||
ki = self.params['ki'] * scale
|
||||
kd = self.params['kd'] * scale
|
||||
kt = self.params['kt'] * scale
|
||||
|
||||
self.yi = self.yi + ki*dt * err + kt*dt * self.awu
|
||||
yd = kd/dt*(d - self.d)
|
||||
|
||||
Reference in New Issue
Block a user