pub struct Pid {
pub kp: f64,
pub ki: f64,
pub kd: f64,
pub n: f64,
}Expand description
Parallel PID with a filtered derivative term, using the standard P, I, D, N (filter
coefficient) parameterization common to block-diagram continuous-time controller blocks:
$$C(s) = K_p + \frac{K_i}{s} + \frac{K_d N s}{s + N}$$
The pure-derivative term Kd*s alone is not realizable as a proper (causal) transfer
function, hence the filter pole at -N — a standard, universally-used approximation (a
larger N tracks the ideal derivative more closely but stiffens the resulting ODE).
This struct is the compiled gain set only — see general_mna::block_graph::BlockKind::Pid
for the netlist-facing component reference (parameters, errors, netlist form, example) and
the anti-windup behavior, which lives at the block-graph evaluation layer, not here.
Fields§
§kp: f64Proportional gain.
ki: f64Integral gain.
kd: f64Derivative gain.
n: f64Derivative filter coefficient; the filter pole sits at -n. Must be > 0 — see
Pid::new.
Implementations§
Source§impl Pid
impl Pid
pub fn new(kp: f64, ki: f64, kd: f64, n: f64) -> Result<Self, PidError>
Sourcepub fn to_transfer_function(&self) -> TransferFunction
pub fn to_transfer_function(&self) -> TransferFunction
Puts C(s) over the common denominator s*(s+N):
C(s) = [(Kp+Kd*N)*s^2 + (Kp*N+Ki)*s + Ki*N] / [s^2 + N*s]Derived by hand before implementation (see docs/architecture.md’s Milestone 5 note):
with Kd=0 this numerator factors exactly as (s+N)(Kp*s+Ki), so the filter pole/zero
cancel and the closed-loop step response of the resulting state-space realization
reduces to the ideal PI response y(t) = Kp + Ki*t for every t, not just
asymptotically — tests/step_responses.rs checks exactly this.