Blocks ====== Every block of this toolkit, from its catalog. control ------- .. list-table:: :header-rows: 1 * - Block - Type - What it does * - :doc:`PID ` - ``pid`` - Drives an error to zero: proportional, integral and derivative terms. n filters the derivative; u\_min < u\_max limits the output, with anti-windup (clamp or back\_calc with kt). Equal limits: none. * - :doc:`Integrator ` - ``integrator`` - Accumulates its input over time. A feedback loop may pass through it. * - :doc:`Lag ` - ``lag`` - Smooths its input with a time constant: a first-order lag. * - :doc:`Delay ` - ``delay`` - Its input from a number of clock steps ago; any value. * - :doc:`Transfer function ` - ``transfer_fn`` - A transfer function H(s) or H(z) from its numerator and denominator coefficients (descending powers). s: integrated (controllable canonical form) or discretized by Tustin; z: direct form II transposed. * - :doc:`State space ` - ``state_space`` - A state-space model: x' = A x + B u and y = C x + D u for s, or x[k+1] = A x + B u and y = C x + D u for z. A is n x n, B n x m, C p x n, D p x m, and x0 is the initial state. * - :doc:`ODE RHS ` - ``rhs`` - User-supplied ODE right-hand side x' = f(t, x, u), separated by ';' for multi-state systems (x1..xn, u1..um, t). Integrated by the run's solver. * - :doc:`Bode ` - ``bode`` - The frequency response of num/den: magnitude in dB (20 log10 \|H\|) and phase in degrees. For z, sample\_time sets z = exp(j w sample\_time). * - :doc:`Controllability ` - ``controllability`` - The rank of the controllability matrix [B AB ... A^(n-1) B], the system order and whether the system is controllable. A and B are matrix text. * - :doc:`Observability ` - ``observability`` - The rank of the observability matrix [C; CA; ...; CA^(n-1)], the system order and whether the system is observable. A and C are matrix text. * - :doc:`Second order ` - ``second_order`` - A second-order system k wn² / (s² + 2 zeta wn s + wn²): natural frequency wn, damping zeta, dc gain k. * - :doc:`Zero-pole-gain ` - ``zpk`` - A transfer function from its zeros, poles and gain: k Π(s − z) / Π(s − p). Roots like -1 or -2+3j. * - :doc:`Lead-lag ` - ``lead_lag`` - A lead-lag compensator k (s/zero + 1) / (s/pole + 1): lead when zero < pole, lag when zero > pole. * - :doc:`Derivative ` - ``derivative`` - The rate of change of its input, filtered: s / (tau s + 1). * - :doc:`Washout ` - ``washout`` - Removes the steady part of its input, passing changes: tau s / (tau s + 1). * - :doc:`Notch ` - ``notch`` - Cuts one frequency: depth dB at freq, width sets how wide. For a resonance or mains hum. * - :doc:`Filter ` - ``filter`` - An IIR filter: Butterworth, Chebyshev I/II or Bessel; lowpass, highpass, bandpass or bandstop. Tustin with prewarped edges by default, so the cutoff is exact at any step. * - :doc:`Biquad ` - ``biquad`` - One second-order section from the Audio EQ Cookbook: lowpass, highpass, bandpass, notch, allpass, peak, lowshelf or highshelf at freq with q (and gain\_db for peak and shelves). * - :doc:`Moving average ` - ``moving_average`` - The mean of its last window samples (every step, or every sample\_time). * - :doc:`Median ` - ``median`` - The median of its last window samples: removes spikes and keeps edges. * - :doc:`Exponential average ` - ``ema`` - An exponential moving average: y += alpha (u − y) every step (or sample\_time). Smaller alpha, smoother. * - :doc:`Rate limiter ` - ``rate_limiter`` - Follows its input no faster than rise up and fall down, per second: an actuator's slew limit. * - :doc:`Backlash ` - ``backlash`` - Gear play: the output moves only once the input crosses a gap of width, then follows at its edge. * - :doc:`Quantizer ` - ``quantizer`` - The input in steps of interval, rounded or floored: what an ADC or an encoder reads. * - :doc:`Relay ` - ``relay`` - A switch with hysteresis: on\_value once the input reaches on\_at, off\_value once it falls to off\_at. * - :doc:`Friction ` - ``friction`` - The friction force at velocity u: Coulomb, viscous, and a Stribeck peak (static) near rest. * - :doc:`Discrete integrator ` - ``discrete_integrator`` - Sums its input times the step (or sample\_time): forward, backward or trapezoid. lower < upper limits it (equal: none); reset > 0.5 returns it to initial. * - :doc:`Zero-order hold ` - ``zoh`` - Samples its input every sample\_time and holds it: what a digital controller sees. * - :doc:`First-order hold ` - ``foh`` - Samples its input every sample\_time and extends the line through the last two samples between. * - :doc:`Discrete derivative ` - ``discrete_derivative`` - The difference of its last two samples over the step (or sample\_time); unfiltered, see derivative. * - :doc:`Tapped delay ` - ``tapped_delay`` - Its last taps samples as a numbers list, newest first (this step's input included). * - :doc:`Continuous to discrete ` - ``c2d`` - Discretizes x' = A x + B u at dt: Ad and Bd as matrix text, by zoh (exact for a held input) or tustin. * - :doc:`LQR ` - ``lqr`` - The optimal state-feedback gain K (u = −K x) for weights Q (states) and R (inputs), and the Riccati solution P, as matrix text. A number for Q or R is that times the identity. * - :doc:`Pole placement ` - ``place`` - The state-feedback gain K that puts the poles of A − B K at poles (like -1 -2+3j -2-3j), as matrix text. One input. * - :doc:`Kalman gain ` - ``kalman_gain`` - The steady-state Kalman gain L for process noise Q and measurement noise R, and the error covariance P, as matrix text: the gain an observer takes. * - :doc:`State feedback ` - ``state_feedback`` - u = −K x + N r. Wire an lqr or place block's K into the K input, or type K. N empty: the identity. * - :doc:`Observer ` - ``observer`` - Estimates the state from u and y: x̂' = A x̂ + B u + L (y − C x̂). L from kalman\_gain or by hand. No feedthrough, so it can close a loop with state\_feedback. * - :doc:`Kalman filter ` - ``kalman`` - A discrete Kalman filter: each sample (every step, or sample\_time) it predicts with A, B and u, then corrects with y. Q: process noise, R: measurement noise (a number is that times I). * - :doc:`MPC ` - ``mpc`` - Solves a condensed QP every clock step (A, B, Q, R, N, u bounds from a JSON file). * - :doc:`Dynamic LP ` - ``lp_step`` - Solves a linear program every clock step from a JSON file. * - :doc:`NMPC ` - ``nmpc`` - Solves a nonlinear program every clock step from a JSON file (needs Ipopt). group ----- .. list-table:: :header-rows: 1 * - Block - Type - What it does * - :doc:`In ` - ``inport`` - An input of the subsystem or story it is in: a port on the group's block outside, named by name, and its value here. * - :doc:`Out ` - ``outport`` - An output of the subsystem or story it is in: what is wired to it leaves by a port on the group's block outside, named by name. .. toctree:: :hidden: pid integrator lag delay transfer_fn state_space rhs bode controllability observability second_order zpk lead_lag derivative washout notch filter biquad moving_average median ema rate_limiter backlash quantizer relay friction discrete_integrator zoh foh discrete_derivative tapped_delay c2d lqr place kalman_gain state_feedback observer kalman mpc lp_step nmpc inport outport