nx_pid.nx
buildroot/runtime/nx_pid.nx
about
nx_pid.nx -- PID controller (proportional-integral-derivative).
u(t) = Kp*e + Ki*integral(e) + Kd*derivative(e)
Closes the loop from Kalman state estimation to control actuation.
Pure i64 with Q14 gains.
What this unlocks:
+ temperature / motor / position control
+ auto-stabilization (drone attitude, robot balance)
+ feedback loops with arbitrary measurement source
+ paired with Kalman: estimate state -> drive actuator
Anti-windup: integral term is clamped to [-i_limit, +i_limit] so
long error sustains don't destroy the controller.
genealogy_id: ziegler_nichols_1942 + minorsky_1922_first_pid
lineage_id: feedback_control_loop
dependencies 1 imports · 3 importers
imports: syscalls.nx
imported by: nx_ferment_thermal.nxnx_ferment_thermal_test.nxnx_pid_test.nx
structs
| 30 | struct PID |
consts
| 28 | const NX_PID_Q: i64 = 16384 // Q14 |
functions
| 40 | func nx_pid_init(p: *PID, kp_q14: i64, ki_q14: i64, kd_q14: i64, |
| 52 | func nx_pid_reset(p: *PID) -> i64 |
| 62 | func nx_pid_update(p: *PID, setpoint: i64, measured: i64) -> i64 |