A minimal, dependency-free PID controller for Python.
Latest version:
pip install git+https://github.com/chrisfox9158/pidkit.gitv0.2.1:
pip install git+https://github.com/chrisfox9158/pidkit.git@v0.2.1from pidkit import PID
pid = PID(kp=1.0, ki=0.1, kd=0.05, setpoint=100)
correction = pid.compute(pv=95, dt=0.1)Don't know what gains to use for your sim? Let pidkit find them:
from pidkit import autotune_sim, PID
result = autotune_sim(
plant_factory=lambda: MyPlant(...),
setpoint=100,
dt=0.1,
steps=600,
)
pid = PID(kp=result.kp, ki=result.ki, kd=result.kd, setpoint=100)For full usage details:
- Controller — pidkit essential use; the
PIDclass, timing modes, output limiting - Autotuning —
autotune_sim, theaggressionparameter, validation results
- Bug fixes — resolved an
IndexErrorand a related logic gap in settling-time detection (_find_tolerance_margin).
autotune_sim— automatic PID gain discovery against any simulated plant, requiring only a minimalstep/get_stateinterface (pidkit.SimPlant).TuneResult— structured result object with tuned gains, the full final-trial trace, and diagnostic metrics (settling time, overshoot, oscillation count, final cost).- Keyword-only arguments on
PID.__init__andPID.compute(), preventing silent transposition of same-typed arguments likekp/ki.
See CHANGELOG.md for the full version history.
MIT License — see LICENSE