Skip to content

Commit

Permalink
Merge pull request #34 from soloam/avoid_integral_saturation
Browse files Browse the repository at this point in the history
[fix] Avoid Integral Saturation
  • Loading branch information
soloam authored Nov 9, 2022
2 parents 7e1eb81 + f6daa76 commit d39bd48
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions custom_components/pid_controller/pidcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,17 @@ def update(self, feedback_value, in_time=None):
# Calculate delta error
delta_error = error - last_error

# Calculate terms
# Calculate P
self._p_term = self._kp * error
self._i_term += self._ki * error * delta_time
self._i_term = self.clamp_value(self._i_term, self._windup)

# Calculate I and avoids Sturation
if self._last_output is None or (
self._last_output > 0 and self._last_output < 100
):
self._i_term += self._ki * error * delta_time
self._i_term = self.clamp_value(self._i_term, self._windup)

# Calculate D
self._d_term = self._kd * delta_error / delta_time

# Compute final output
Expand Down

0 comments on commit d39bd48

Please sign in to comment.