so2nostd
Second-Order no_std Controller for Embedded Systems
so2nostd is a lightweight, high-performance no_std Rust crate implementing a discrete-time second-order (SO2) control system. Designed for embedded environments like MCUs (e.g., RP2040), it provides stable, physics-based dynamics using Euler integration.
GPL-2.0-or-later licensed to ensure community protection against privatization. Optimized for minimal footprint and maximal reliability.
Table of Contents
π Features
- β
Pure
no_std: Zero standard library dependencies, perfect for bare-metal/RTOS. - β‘ Flexible Floating-Point:
f64(default) orf32feature for memory-constrained devices. - π§ Size-Optimized: Compatible with
opt-level="z"and LTO for tiny binary footprints. - π‘οΈ Numerical Safety: Robust handling of
dt <= 0to prevent system divergence. - π Physics-Based: Models natural frequency (
Ο_n), damping ratio (ΞΆ), and static gain.
π οΈ Installation
Add to your Cargo.toml:
[]
= { = "[https://github.com/jorgeandrecastro/so2nostd.git](https://github.com/jorgeandrecastro/so2nostd.git)" }
Cortex-M optimization):Ini, TOMLso2nostd = { git = "[https://github.com/jorgeandrecastro/so2nostd.git](https://github.com/jorgeandrecastro/so2nostd.git)", features = ["f32"] }
π QuickstartRustuse so2nostd::So2Controller;
{
// w_n=10 rad/s, zeta=0.7 (underdamped), initial=0.0, gain=1.0
= So2Controller::new(10.0, 0.7, 0.0, 1.0);
= 0.01; // 10ms timestep
= 1.0;
// Simulate convergence
100 {
= controller.update(target, dt);
// output smoothly approaches 1.0 following SO2 dynamics
}
}
π API ReferenceMethodSignatureDescriptionnewnew(w_n: Float, zeta: Float, initial: Float, gain: Float)Creates a new controller. w_n: rad/s, zeta: damping.updateupdate(input: Float, dt: Float) -> FloatAdvances system state. Safe for dt <= 0.set_targetset_target(target: Float)Updates the internal setpoint.resetreset(value: Float)Hard reset of internal states to value.Note: Float is an alias for f64 (default) or f32 (with feature).
β‘ Performance & OptimizationZero Allocation: No heap usage, strictly stack-based.Predictable CPU: Constant time O(1) update cycles.Binary Size: Minimal footprint when compiled with panic = "abort" and strip = true.π§ͺ TestingThe crate includes tests for:Step response stability and convergence.Zero/Negative delta time safety.Run tests with:Bashcargo test
βοΈ LicenseGPL-2.0-or-later Β© 2026 Jorge Andre Castro.Free to use, modify, and distribute. In accordance with the GPL, any derivative works or larger projects incorporating this code must also be released under the GPL-2.0-or-later.