Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions simple_pid/pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def __call__(self, input_, dt=None):

# Compute integral and derivative terms
self._integral += self.Ki * error * dt
self._integral = _clamp(self._integral, self.output_limits) # Avoid integral windup

if self.differential_on_measurement:
self._derivative = -self.Kd * d_input / dt
Expand All @@ -151,6 +150,7 @@ def __call__(self, input_, dt=None):
# Compute final output
output = self._proportional + self._integral + self._derivative
output = _clamp(output, self.output_limits)
self._integral = output - (self._proportional + self._derivative)

# Keep track of state
self._last_output = output
Expand Down Expand Up @@ -246,9 +246,13 @@ def output_limits(self, limits):

self._min_output = min_output
self._max_output = max_output

self._integral = _clamp(self._integral, self.output_limits)

self._last_output = _clamp(self._last_output, self.output_limits)
if (self._proportional is None) or (self._derivative is None) or (self._last_output is None):
self._integral = _clamp(self._integral, self.output_limits)
else:
self._integral = self._last_output - (self._proportional + self._derivative)


def reset(self):
"""
Expand Down