File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed
Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change 1919DERIVATIVE_ALPHA1 = 0.2
2020DERIVATIVE_ALPHA2 = 0.1
2121DERIVATIVE_RAW_CAP = 5.0
22+ DEADBAND_EPSILON = 1e-6
2223
2324PID_UPDATE_INTERVAL = 60
2425
@@ -183,7 +184,7 @@ def update(self, state: TemperatureState) -> None:
183184
184185 def _update_integral (self , state : TemperatureState ) -> None :
185186 """Update the integral value in the PID controller."""
186- if abs (state .error ) > DEADBAND :
187+ if abs (state .error ) > ( DEADBAND + DEADBAND_EPSILON ) :
187188 self ._integral = 0.0
188189 return
189190
@@ -219,6 +220,11 @@ def _update_derivative(self, state: TemperatureState) -> None:
219220
220221 derivative = - temperature_delta / delta_time
221222
223+ if abs (derivative ) >= DERIVATIVE_RAW_CAP :
224+ self ._raw_derivative = max (- DERIVATIVE_RAW_CAP , min (derivative , DERIVATIVE_RAW_CAP ))
225+ self ._last_derivative_updated = state .last_changed .timestamp ()
226+ return
227+
222228 # Apply the first low-pass filter.
223229 filtered_derivative = DERIVATIVE_ALPHA1 * derivative + (1 - DERIVATIVE_ALPHA1 ) * self ._raw_derivative
224230
You can’t perform that action at this time.
0 commit comments