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
abcsignal, its stationary two-axisalpha/beta(plus zero-sequence) projection, and a rotatingd/q(plus zero-sequence) frame locked to a reference angletheta. Used to turn a three-phase grid or motor-drive quantity into DC-liked/qvalues aPidcan regulate directly, and the matching angle-tracking utility (anglewrap) that closes the loop (a synchronous-reference-frame PLL isClarke -> anglewrap -> Park, feeding aPidon theqoutput 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). Seebook/dev-guide/src/logic-signals.mdfor 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 — adae-runtimeintegration (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’sgain/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 ofmath_ops.
Structs§
- Discrete
Pid - A discrete PID’s own configuration —
kp/ki/kdthe usual gains,nthe derivative filter coefficient (this codebase’s own existing name for the concept the source manual callsKf— same idea, kept consistent with the continuouscrate::Pid’s own field name rather than importing a second spelling for it),periodthe sample periodTbaked in at construction (from the declaring block’s ownSampleTimeSpec::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). - Discrete
PidState DiscretePid’s own persisted state — two small scalars per branch that needs memory (the proportional action is stateless).int_prev_eis only ever read/written whenmethodisForwardEuler/Trapezoidal(both need a remembered previous error);BackwardEulernever touches it, but it’s still always present in this struct rather than modeled as anOption/per-method enum, since a fixed-shape state is simpler fordae-runtimeto 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 abovehigh— 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, unlikecrate::Pidfeeding a PWM carrier. Deliberately not acrate::StateSpace: the on/off memory is a genuine discrete latch, not a linear dynamic, the same reasoncrate::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 inductancel_d/l_q(H — equal for a surface-mount PMSM, unequal for an interior-PM motor with reluctance torque), permanent-magnet flux linkagelambda_pm(Wb),pole_pairs(electrical cycles per mechanical revolution), rotor+load inertiainertia(kgm^2), and viscous friction coefficientfriction(Nm*s/rad). - State
Space - Transfer
Function - A single-input single-output transfer function
N(s) / D(s), coefficients highest-degree first (e.g.s + 1is[1.0, 1.0]).Dmust be nonzero-leading (degree =den.len() - 1) anddeg(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 alongsidePidrather than folding frequency modulation intoPidor intodae-runtimedirectly — a closed loop wiresSum -> Pid -> Gain -> Vcoas separate, independently reusable blocks, the same way a real block-diagram tool would, rather than one function that hardcodes the whole topology.
Enums§
- Discrete
Integration Method - 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). - Hysteresis
Error - PidError
- Pmsm
Error - Settled
State Error - Why
TransferFunction::settled_state/TransferFunction::settled_state_discretecould not produce a state for the requested output. - State
Space Error - Transfer
Function Error - VcoError