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 term
- 🧪 Precision control with dynamic time steps
- 🔄 Integral and derivative-on-measurement option
🔧 Installation
pip install py_pidx
| Feature | Description |
|---|---|
Kp, Ki, Kd |
Tunable proportional, integral, and derivative gains |
GainScheduler |
Dynamically adjust PID gains at runtime |
| Deadbands | Zero out small control efforts or errors to reduce actuator jitter |
| Anti-windup | Prevents runaway integral values during saturation |
| Derivative on Measurement | Optionally compute D-term from PV instead of error |
| Integral on Measurement | Optionally compute I-term on process variable instead of error |
| Low-pass Filtering | Smooths noisy derivative term using alpha filtering |
| Feedforward | Optional term to improve open-loop response |
| Slew Rate Limiting | Prevents rapid output changes that may shock actuators |
🔧 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
PID Controller Methods
| Method | Description |
|---|---|
run(pv, delta_time=None) |
Compute the control output |
reset() |
Clear internal PID state |
set_auto_mode(enabled) |
Enable/disable PID control loop |
set_output_limits(min, max) |
Clamp controller output |
__repr__() |
Debug string with current gains and output |
📄 Documentation
👉 Full API Reference and usage examples: 📖 https://mehrabmahdian.github.io/py_pidx/
🧠 Why Use py_pidx?
- Designed with real control systems in mind
- Great for robotics, automation, process control, and simulations
- Extensible and highly configurable
- Clean, readable, and well-documented
📃 License
This project is licensed under the terms of the MIT license.
🤝 Contributing
Pull requests and feature ideas are welcome! Please open an issue for bugs or enhancement suggestions.
⭐️ Show Your Support
If you find this library useful, consider starring the repo or sharing it with others in the controls/automation community!
📬 Contact
Maintained by Mehrab Mahdian.
If you have questions, feature requests, or would like to collaborate, feel free to reach out:
📧 Email:
memahdian@outlook.com
mehrab.mahdian@taltech.ee
🧑💻 GitHub: @mehrabmahdian
💼 LinkedIn: Mehrab Mahdian
I’m always happy to connect with fellow developers, engineers, and researchers.
Metadata
Release files for py-pidx 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| py_pidx-1.1.1.tar.gz | 8.0 kB | Without provenance | Details for py_pidx-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_pidx-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for py_pidx-1.1.1-py3-none-any.whl |
Total release size: 15.4 kB
Release files / py_pidx-1.1.1.tar.gz
| Download URL | py_pidx-1.1.1.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a6a5953e35e34b594fa30bac45a1c25b3f8a02da93024c9c0c4f701721a1061
|
|
BLAKE2b-256 checksum How to use checksums |
7c079f9a021654a07d7280d548ab2dc2f201543a89a05dd4b3071d24ceb3eb8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|
Release files / py_pidx-1.1.1-py3-none-any.whl
| Download URL | py_pidx-1.1.1-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e438ff22d175a4cf1146cc909d8ecee19fc69cb36ed5ee62f2a3b02cea24b4af
|
|
BLAKE2b-256 checksum How to use checksums |
853b5e385b2f1c13f89689b68ca700de43607179518530dd91e2f16ff08f4d9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|
Security for py-pidx 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.