Skip to main content

Module advanced

Module advanced 

Source
Expand description

Advanced control algorithms — adaptive PID tuning, Model Predictive Control, and MIMO state-space — complementing the PID/anti-windup loops in the parent module. Pure f64 math, zero-heap (caller-supplied buffers; bounded loops).

Functions§

adaptive_gains
Scale a PID gain triple by a scalar adaptation factor — the simplest gain-scheduling step (retune as the operating regime changes). Returns (kp, ki, kd).
mimo_output
MIMO output equation y = C·x + D·u with p outputs: c is p×n (row-major), d is p×m (row-major); the output is written to out (len p). Zero-heap. Returns false on a mismatch.
mimo_step
MIMO state transition x' = A·x + B·u for a system with n states and m inputs. a is the n×n state matrix (row-major), b the n×m input matrix (row-major), x the state (len n), u the input (len m); the next state is written to out (len n). Zero-heap. Returns false on a dimension mismatch.
mit_rule_adapt
MIT-rule online gain adaptation (model-reference adaptive control): nudge gain to reduce the tracking errorgain + adaptation_rate · error · signal. One adaptation step.
mpc_control
One-step Model Predictive Control for a scalar LTI plant x_{k+1} = a·x_k + b·u: search candidate controls across [u_min, u_max] (a grid of steps+1 points), simulate horizon steps holding u, and return the u minimising Σ (setpoint − x_k)² + control_penalty·u². The optimal FIRST move of the receding horizon. Zero-heap (bounded loops, no allocation).
scheduled_gain
Gain scheduling: linearly interpolate the gain between low_gain (at op_min) and high_gain (at op_max) for the current op_point — adaptive tuning across the operating envelope. Clamps outside [op_min, op_max].