A Rust port of Sebastian Madgwick's AHRS algorithm.
Add ahrs-rs to your Cargo.toml
:
toml
[dependencies]
ahrs = "0.3"
Here's a simple example that updates the filter state with arbitrary sensor data:
```rust use ahrs::{Ahrs, Madgwick}; use nalgebra::{Vector3, Quaternion}; use std::f64;
fn main() { // Initialize filter with default values let mut ahrs = Madgwick::default();
// Obtain sensor values from a source
let gyroscope = Vector3::new(60.1, 30.2, 20.3);
let accelerometer = Vector3::new(0.1, 0.2, 0.3);
let magnetometer = Vector3::new(0.5, 0.6, 0.7);
// Run inputs through AHRS filter (gyroscope must be radians/s)
let quat: &Quaternion<f64> = ahrs.update(
&(gyroscope * (f64::consts::PI/180.0)),
&accelerometer,
&magnetometer
).unwrap();
// Do something with the updated state quaternion
println!("{}", quat);
}
```
Crate nalgebra is also needed as a dependency for its algebraic types Vector3
and Quaternion
.
field_access
Gives [im]mutable access to inner algorithm struct fields that aren't normally exposed. The exposed API is considered unstable for the time-being, but is nevertheless a useful feature. For example:
```rust use ahrs::Madgwick;
let mut ahrs = Madgwick::default();
{ let sampleperiod: &mut f64 = ahrs.sampleperiodmut(); *sampleperiod = 0.5; } ```
GPLv3