Blocks#

Every block of this toolkit, from its catalog.

control#

Block

Type

What it does

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.

Integrator

integrator

Accumulates its input over time. A feedback loop may pass through it.

Lag

lag

Smooths its input with a time constant: a first-order lag.

Delay

delay

Its input from a number of clock steps ago; any value.

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.

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.

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.

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).

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.

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.

Second order

second_order

A second-order system k wn² / (s² + 2 zeta wn s + wn²): natural frequency wn, damping zeta, dc gain k.

Zero-pole-gain

zpk

A transfer function from its zeros, poles and gain: k Π(s − z) / Π(s − p). Roots like -1 or -2+3j.

Lead-lag

lead_lag

A lead-lag compensator k (s/zero + 1) / (s/pole + 1): lead when zero < pole, lag when zero > pole.

Derivative

derivative

The rate of change of its input, filtered: s / (tau s + 1).

Washout

washout

Removes the steady part of its input, passing changes: tau s / (tau s + 1).

Notch

notch

Cuts one frequency: depth dB at freq, width sets how wide. For a resonance or mains hum.

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.

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).

Moving average

moving_average

The mean of its last window samples (every step, or every sample_time).

Median

median

The median of its last window samples: removes spikes and keeps edges.

Exponential average

ema

An exponential moving average: y += alpha (u − y) every step (or sample_time). Smaller alpha, smoother.

Rate limiter

rate_limiter

Follows its input no faster than rise up and fall down, per second: an actuator’s slew limit.

Backlash

backlash

Gear play: the output moves only once the input crosses a gap of width, then follows at its edge.

Quantizer

quantizer

The input in steps of interval, rounded or floored: what an ADC or an encoder reads.

Relay

relay

A switch with hysteresis: on_value once the input reaches on_at, off_value once it falls to off_at.

Friction

friction

The friction force at velocity u: Coulomb, viscous, and a Stribeck peak (static) near rest.

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.

Zero-order hold

zoh

Samples its input every sample_time and holds it: what a digital controller sees.

First-order hold

foh

Samples its input every sample_time and extends the line through the last two samples between.

Discrete derivative

discrete_derivative

The difference of its last two samples over the step (or sample_time); unfiltered, see derivative.

Tapped delay

tapped_delay

Its last taps samples as a numbers list, newest first (this step’s input included).

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.

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.

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.

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.

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.

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.

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).

MPC

mpc

Solves a condensed QP every clock step (A, B, Q, R, N, u bounds from a JSON file).

Dynamic LP

lp_step

Solves a linear program every clock step from a JSON file.

NMPC

nmpc

Solves a nonlinear program every clock step from a JSON file (needs Ipopt).

group#

Block

Type

What it does

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.

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.