simple-pid is a Python library that provides a simple and easy-to-use PID controller. It is designed to be robust and operate without external dependencies, making it suitable for various control system applications. The library is actively maintained, with the current version being 2.0.1, and new major versions released approximately every 2-3 years, supplemented by minor and patch releases as needed.
pip install simple-pidVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the basic usage of `simple-pid`. It initializes a `PID` controller with proportional, integral, and derivative gains, and a target setpoint. The controller is then used within a loop to regulate a simulated system, updating its control output periodically based on the system's current value. Key parameters like `sample_time` and `output_limits` are configured for robust operation.
Upgrade to Python 3.6 or newer to ensure full compatibility and support.
Always set meaningful `pid.output_limits = (lower, upper)` to prevent integral windup. The library uses these limits to constrain both the output and the integral term.
Understand the `differential_on_measurement` parameter (defaulting to `True` since v2.0.0) and adjust it based on your system's requirements to prevent derivative kick.
If providing a custom `time_fn`, ensure it is monotonic. If `sample_time` is `None` and you're manually managing `dt`, ensure `dt` reflects the actual time elapsed between calls.
For new PID instances or when enabling auto mode, provide a `starting_output` value to the constructor (v2.0.0+) or pass the system's `last_output` value when calling `pid.auto_mode = True` to provide a 'bumpless' transfer.
from simple_pid import PID
pid = PID(1.0, 0.1, 0.05, setpoint=50)
output = pid.compute(current_value)
from simple_pid import PID