Introduction¶
py_pidx¶
py_pidx is an advanced Python library for PID control that provides robust, real-world-ready features, including:
Gain scheduling
Deadband handling (error & output)
Anti-windup
Slew rate limiting
Derivative filtering
Feedforward support
Precision control with dynamic time steps
Integral and derivative-on-measurement option
Installation¶
pip install py_pidx
Features Overview¶
Basic Usage¶
from py_pidx import PID
pid = PID(Kp=1.2, Ki=0.5, Kd=0.05, setpoint=100)
while True:
pv = read_sensor() # Your process variable
control_signal = pid.run(pv)
send_to_actuator(control_signal)
time.sleep(0.01)
Advanced Features¶
Gain Scheduling¶
from py_pidx.gain_scheduler import GainScheduler
class MyScheduler(GainScheduler):
def get_gains(self, pv):
if pv < 10:
return (2.0, 0.1, 0.01)
elif pv < 20:
return (1.5, 0.05, 0.005)
else:
return (1.0, 0.01, 0.001)
pid = PID(gain_scheduler=MyScheduler())
Deadbands¶
pid = PID(
output_deadband_limits=(-0.1, 0.1),
error_deadband_limits=(-0.05, 0.05)
)
Anti-Windup and Slew Rate¶
pid = PID(
Ki=0.3,
anti_windup=True,
max_output_rate=10.0 # Max 10 units/sec change
)
Derivative Filtering and Feedforward¶
pid = PID(
Kd=0.2,
derivative_filter=0.3, # Low-pass smoothing factor (0.0–1.0)
feedforward=1.5
)
Testing / Resetting / Toggling¶
pid.set_auto_mode(False) # Pause control
pid.set_auto_mode(True) # Resume control
pid.reset() # Clear internal state
Contact & Support¶
Maintained by Mehrab Mahdian.
License¶
This project is licensed under the terms of the MIT license.