Skip to content

Commit

Permalink
Merge pull request #20 from MageDelfador/master
Browse files Browse the repository at this point in the history
fix wrong derivative parameters
  • Loading branch information
soloam authored Oct 14, 2022
2 parents fedc9f5 + 50c4614 commit 2a37512
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions custom_components/pid_controller/pidcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,18 @@ def update(self, feedback_value, in_time=None):

# Calculate error
error = self._set_point - feedback_value

# Calculate delta Input
delta_input = feedback_value - (
self._last_input if self._last_input is not None else feedback_value
last_error = self._set_point - (
self._last_input if self._last_input is not None else self._set_point
)

# Calculate delta error
delta_error = error - last_error

# Calculate terms
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)
self._d_term = self._kd * delta_input / delta_time
self._d_term = self._kd * delta_error / delta_time

# Compute final output
self._output = self._p_term + self._i_term + self._d_term
Expand Down

0 comments on commit 2a37512

Please sign in to comment.