Skip to content

Commit

Permalink
feature: reset PID method
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Mousset authored and m-lundberg committed Aug 26, 2019
1 parent 2d5a125 commit 60c9d68
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions simple_pid/PID.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class PID(object):
"""
A simple PID controller. No fuss.
"""

def __init__(self,
Kp=1.0, Ki=0.0, Kd=0.0,
setpoint=0,
Expand Down Expand Up @@ -60,13 +61,7 @@ def __init__(self,
self._auto_mode = auto_mode
self.proportional_on_measurement = proportional_on_measurement

self._proportional = 0
self._integral = 0
self._derivative = 0

self._last_time = _current_time()
self._last_output = None
self._last_input = None
self.reset()

def __call__(self, input_):
"""
Expand Down Expand Up @@ -141,6 +136,19 @@ def auto_mode(self, enabled):
"""Enable or disable the PID controller"""
self.set_auto_mode(enabled)

def reset(self):
"""
Reset the PID controller internals, setting each term à 0 as well as cleaning the integral,
the last output and the last input (derivative calculation).
"""
self._proportional = 0
self._integral = 0
self._derivative = 0

self._last_time = _current_time()
self._last_output = None
self._last_input = None

def set_auto_mode(self, enabled, last_output=None):
"""
Enable or disable the PID controller, optionally setting the last output value.
Expand Down

0 comments on commit 60c9d68

Please sign in to comment.