Skip to content

Commit 1757e9f

Browse files
Remove redundant testing option
The `dt` option was added when `time_fn` was not available to initialize PID instances. Now that `time_fn` allows the time function to be injected as a dependency, the `dt` option is redundant. It could be kept around for backward compatibility, but I'd personally remove it because IMHO the simpler the code the better.
1 parent 67ec6dc commit 1757e9f

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

simple_pid/pid.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,19 @@ def __init__(
100100
# Set initial state of the controller
101101
self._integral = _clamp(starting_output, output_limits)
102102

103-
def __call__(self, input_, dt=None):
103+
def __call__(self, input_):
104104
"""
105105
Update the PID controller.
106106
107107
Call the PID controller with *input_* and calculate and return a control output if
108108
sample_time seconds has passed since the last update. If no new output is calculated,
109109
return the previous output instead (or None if no value has been calculated yet).
110-
111-
:param dt: If set, uses this value for timestep instead of real time. This can be used in
112-
simulations when simulation time is different from real time.
113110
"""
114111
if not self.auto_mode:
115112
return self._last_output
116113

117114
now = self.time_fn()
118-
if dt is None:
119-
dt = now - self._last_time if (now - self._last_time) else PID.MIN_DT
120-
elif dt <= 0:
121-
raise ValueError('dt has negative value {}, must be positive'.format(dt))
115+
dt = now - self._last_time if (now - self._last_time) else PID.MIN_DT
122116

123117
if (
124118
self.sample_time is not None

simple_pid/pid.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class PID(object):
3131
time_fn: Optional[Callable[[], float]] = ...,
3232
starting_output: float = ...,
3333
) -> None: ...
34-
def __call__(self, input_: float, dt: Optional[float] = ...) -> Optional[float]: ...
34+
def __call__(self, input_: float) -> Optional[float]: ...
3535
def __repr__(self) -> str: ...
3636
@property
3737
def components(self) -> _Components: ...

0 commit comments

Comments
 (0)