Skip to main content

Crate continuous_blocks

Crate continuous_blocks 

Source
Expand description

Continuous-time block-diagram elements — transfer function, state-space, PID, voltage-controlled oscillator, hysteresis (Schmitt-trigger) comparator, and stateless math ops (gain, sum, product, saturation) — matching the standard Continuous/Math Operations block sets common to block-diagram simulation tools. Each block does one job and is meant to be wired to the others by the caller — an error signal is a Sum block’s output, not something a controller computes internally, and a frequency-modulated PWM carrier is Pid -> Gain -> Vco, not a single fused “closed loop” function. See dae-runtime’s closed_loop module for how a circuit’s ideal-switch gates get wired to a chain of these blocks.

Every dynamic block compiles to a StateSpace — the same descriptor-DAE shape general-mna already uses for circuits (A x + K dx/dt = B u, with K here called e for descriptor systems). See docs/architecture.md, “One descriptor system for circuit and continuous blocks alike,” for why this is the organizing idea of the whole general-simulator project, not just this crate.

This crate is deliberately standalone (no dependency on general-mna, pwl-devices, or dae-runtime): block parameters (gains, pole/zero locations, PID coefficients) are known numbers at model-build time, not symbolic netlist parameters, and every block here is verified against a hand-derived result on its own before anything wires it into a whole circuit’s global system — the same incremental-verification discipline lcp-solver and pwl-devices were built with. Wiring a compiled block’s (A, K, B) into dae-runtime’s global descriptor system, and stateless math_ops blocks into its per-timestep assembly, is a later milestone.

Re-exports§

pub use coordinate_transforms::CoordinateTransform;
pub use logic::FlipFlopKind;
pub use logic::LatchPriority;
pub use logic::LogicOp;
pub use waveform_arithmetic::MathFn1;
pub use waveform_arithmetic::MathFn2;
pub use waveform_arithmetic::MathFn3;

Modules§

coordinate_transforms
Clarke/Park coordinate transforms — the standard change of basis between a three-phase abc signal, its stationary two-axis alpha/beta (plus zero-sequence) projection, and a rotating d/q (plus zero-sequence) frame locked to a reference angle theta. Used to turn a three-phase grid or motor-drive quantity into DC-like d/q values a Pid can regulate directly, and the matching angle-tracking utility (anglewrap) that closes the loop (a synchronous-reference-frame PLL is Clarke -> anglewrap -> Park, feeding a Pid on the q output back into the tracked angle).
logic
Digital/logic signal blocks: combinational gates (LogicOp), an SR/fault latch (level-triggered, LatchPriority), and the shared edge-detection + next-state rules edge-triggered flip-flops/counters both need (FlipFlopKind). See book/dev-guide/src/logic-signals.md for the full design survey this module implements.
math_ops
Math Operations-style blocks that don’t need state: gain, sum, product, saturation. These are pure functions of their inputs, not descriptor-DAE fragments — a dae-runtime integration (a later milestone) would evaluate them inline while assembling the global system rather than adding unknowns/rows for them, the same way a resistor’s Ohm’s-law relationship needs no extra unknown.
waveform_arithmetic
A standard real-valued scalar function library — trig, exponential/log, rounding, sign, select/clamp, and table lookup — offered here as ordinary stateless blocks alongside crate::math_ops’s gain/sum/product/saturation. This is the common vocabulary most waveform-arithmetic/expression languages across circuit simulation tools converge on (trig, exponential/log, sign, min/max, a select/if, a clamp, a lookup table), offered here as composable blocks instead of a second expression language. Each function is a pure function of its argument(s), evaluated fresh every step, exactly like the rest of math_ops.

Structs§

DiscretePid
A discrete PID’s own configuration — kp/ki/kd the usual gains, n the derivative filter coefficient (this codebase’s own existing name for the concept the source manual calls Kf — same idea, kept consistent with the continuous crate::Pid’s own field name rather than importing a second spelling for it), period the sample period T baked in at construction (from the declaring block’s own SampleTimeSpec::Periodic, not a separate netlist field — the discretized recursion’s own coefficients need the same period the block is scheduled at, so there is exactly one place to declare it).
DiscretePidState
DiscretePid’s own persisted state — two small scalars per branch that needs memory (the proportional action is stateless). int_prev_e is only ever read/written when method is ForwardEuler/Trapezoidal (both need a remembered previous error); BackwardEuler never touches it, but it’s still always present in this struct rather than modeled as an Option/per-method enum, since a fixed-shape state is simpler for dae-runtime to hold regardless of which method a given instance happens to use.
Hysteresis
A Schmitt-trigger comparator: stays HIGH until the input drops below low, stays LOW until the input rises above high — the standard bang-bang/hysteresis-band block (block-diagram simulation tools typically offer an equivalent “Relay”/hysteresis block) used for current-mode control when there’s no fixed switching frequency to modulate a duty command onto, unlike crate::Pid feeding a PWM carrier. Deliberately not a crate::StateSpace: the on/off memory is a genuine discrete latch, not a linear dynamic, the same reason crate::Vco’s wraparound is evaluated directly rather than folded into one.
Pid
Pmsm
Motor parameters (SI units): stator resistance r_s (ohm), d/q-axis inductance l_d/ l_q (H — equal for a surface-mount PMSM, unequal for an interior-PM motor with reluctance torque), permanent-magnet flux linkage lambda_pm (Wb), pole_pairs (electrical cycles per mechanical revolution), rotor+load inertia inertia (kgm^2), and viscous friction coefficient friction (Nm*s/rad).
StateSpace
TransferFunction
A single-input single-output transfer function N(s) / D(s), coefficients highest-degree first (e.g. s + 1 is [1.0, 1.0]). D must be nonzero-leading (degree = den.len() - 1) and deg(N) <= deg(D) — a proper transfer function; this is what every realizable continuous-time physical system is.
Vco
A voltage-controlled oscillator: given a frequency command (Hz, clamped to [f_min, f_max]), outputs a repeating ramp in [0, 1) — the same standard block block-diagram simulation tools provide (their own “VCO”/“Repeating Sequence” blocks), used here to build a frequency-modulated PWM carrier. LLC-family resonant converters regulate by switching frequency, not duty, unlike buck/boost, which is why this block exists alongside Pid rather than folding frequency modulation into Pid or into dae-runtime directly — a closed loop wires Sum -> Pid -> Gain -> Vco as separate, independently reusable blocks, the same way a real block-diagram tool would, rather than one function that hardcodes the whole topology.

Enums§

DiscreteIntegrationMethod
How the integral action’s own discrete integrator advances — see each variant’s own recursion in DiscretePid::step. Verified directly against the source manual’s own PDF (not the initial, swapped automated conversion — see this module’s own doc comment).
HysteresisError
PidError
PmsmError
SettledStateError
Why TransferFunction::settled_state/TransferFunction::settled_state_discrete could not produce a state for the requested output.
StateSpaceError
TransferFunctionError
VcoError