Skip to content

patch: no_std support (libm, core::time, remove expect)#1

Open
InushaDeSilva wants to merge 2 commits into
oxkitsune:mainfrom
Horizon-Aerospace:no-std
Open

patch: no_std support (libm, core::time, remove expect)#1
InushaDeSilva wants to merge 2 commits into
oxkitsune:mainfrom
Horizon-Aerospace:no-std

Conversation

@InushaDeSilva

Copy link
Copy Markdown

No description provided.

@InushaDeSilva

Copy link
Copy Markdown
Author

Hey! We're using VQF on an embedded flight computer (Horizon-Aerospace/Flight-Computer) running on an STM32H745 (Cortex-M7, 480 MHz) with Embassy async. Great crate — the filter quality is excellent and the rest-detection/bias-estimation is exactly what we needed for our BMI088 IMU fusion pipeline.

What this PR changes

The vqf crate currently requires std due to a few things that have straightforward no_std replacements:

std usage no_std replacement
std::time::Duration core::time::Duration (stable since Rust 1.25)
.cos(), .sin(), .sqrt(), .tan() (bare float methods) libm::cosf, libm::sinf, libm::sqrtf, libm::tanf
.to_radians() * (core::f32::consts::PI / 180.0)
.powi(2) x * x
.expect() on try_inverse() match + early return (avoids pulling in panic formatting)

Cargo.toml changes

  • Added std feature (enabled by default) — existing users see zero changes
  • nalgebra switched to default-features = false, features = ["libm"] when std is off
  • Added libm = "0.2" dependency

Tested

  • cargo build --target thumbv7em-none-eabi --no-default-features — builds clean ✅
  • Default cargo build (with std) — unchanged behavior ✅
  • Running on hardware at 100 Hz fusion rate with BMI088 accel+gyro, producing stable roll/pitch/yaw + bias-corrected angular rates

Happy to adjust anything if you'd prefer a different approach. Thanks for the great crate!

@oxkitsune oxkitsune left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'd prefer to keep using std math for the std version if possible.

Comment thread src/lib.rs Outdated
@InushaDeSilva

InushaDeSilva commented Apr 1, 2026

Copy link
Copy Markdown
Author

Hey, thanks for the feedback! Both points have been addressed:

  1. std math for std version 0 Added a math.rs wrapper module that delegates to std float methods (.sqrt(), .sin(), .cos(), .tan()) when std is enabled, and falls back to libm only when building with no_std.

  2. Silent try_inverse failure - The else branch now panics in debug builds via #[cfg(debug_assertions)] so bugs surface early during development. In release/no_std builds it gracefully skips the bias update, which avoids pulling in panic formatting machinery on embedded targets. In practice this matrix should always be invertible, so the fallback is just a safety net.

Also cleaned up clippy lints and formatting. Let me know if anything else needs adjusting!

@InushaDeSilva InushaDeSilva requested a review from oxkitsune April 1, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants