code wiki / (root) / nx_pid.nx

nx_pid.nx

buildroot/runtime/nx_pid.nx

2776 B83 linesdepth 3pulls 3 transitivereach 11 importersview sourcekind library
docsdependenciesstructsconstsfunctions

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

syscalls.nx nx_pid.nx nx_ferment_thermal.nx nx_ferment_thermal_test.nx nx_pid_test.nx

imports: syscalls.nx

imported by: nx_ferment_thermal.nxnx_ferment_thermal_test.nxnx_pid_test.nx

structs

30struct PID

consts

28const NX_PID_Q: i64 = 16384 // Q14

functions

40func nx_pid_init(p: *PID, kp_q14: i64, ki_q14: i64, kd_q14: i64,
52func nx_pid_reset(p: *PID) -> i64
called by 2: mainmain
62func nx_pid_update(p: *PID, setpoint: i64, measured: i64) -> i64