Skip to main content

SensorFusion

Trait SensorFusion 

Source
pub trait SensorFusion<T> {
    // Required methods
    fn set_gains(&mut self, gain0: T, gain1: T);
    fn requires_initialization() -> bool;
    fn fuse_acc_gyro(
        &mut self,
        acc: Vector3d<T>,
        gyro_rps: Vector3d<T>,
        delta_t: T,
    ) -> Quaternion<T>;
    fn fuse_acc_gyro_mag(
        &mut self,
        acc: Vector3d<T>,
        gyro: Vector3d<T>,
        mag: Vector3d<T>,
        delta_t: T,
    ) -> Quaternion<T>;
}
Expand description

Common interface for the sensor fusion filters (Madgwick, Mahony, complementary).

use vqm::{Vector3df32,Quaternionf32};
use sensor_fusion::{MadgwickFilterf32,SensorFusion};

let mut madgwick_filter = MadgwickFilterf32::default();

let delta_t: f32 = 0.0;
let acc = Vector3df32::default();
let gyro_rps = Vector3df32::default();

let orientation = madgwick_filter.fuse_acc_gyro(acc, gyro_rps, delta_t);
assert_eq!(orientation, Quaternionf32 { w: 1.0, x: 0.0, y: 0.0, z: 0.0 });

Required Methods§

Source

fn set_gains(&mut self, gain0: T, gain1: T)

Source

fn requires_initialization() -> bool

Source

fn fuse_acc_gyro( &mut self, acc: Vector3d<T>, gyro_rps: Vector3d<T>, delta_t: T, ) -> Quaternion<T>

Source

fn fuse_acc_gyro_mag( &mut self, acc: Vector3d<T>, gyro: Vector3d<T>, mag: Vector3d<T>, delta_t: T, ) -> Quaternion<T>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> SensorFusion<T> for ComplementaryFilter<T>
where T: Copy + One + Zero + Neg<Output = T> + PartialOrd + Sub<Output = T> + Div<Output = T> + TrigonometricMethods + SqrtMethods + Vector3dMath + QuaternionMath + SensorFusionMath,

Source§

impl<T> SensorFusion<T> for MadgwickFilter<T>

Madgwick AHRS algorithm, calculates orientation by fusing output from gyroscope and accelerometer. (No magnetometer is used in this implementation.)

The orientation is calculated as the integration of the gyroscope measurements summed with the measurement from the accelerometer multiplied by a gain. A low gain gives more weight to the gyroscope more and so is more susceptible to drift. A high gain gives more weight to the accelerometer and so is more susceptible to accelerometer noise, lag, and other accelerometer errors. A gain of zero means that orientation is determined by solely by the gyroscope.

See Sebastian Madgwick’s Phd thesis and also x-io Technologies sensor fusion library.

For computation efficiency this code refactors the code used in many implementations (Arduino, Adafruit, M5 Stack, Reefwing-AHRS), see Madgwick refactoring.

Source§

impl<T> SensorFusion<T> for MahonyFilter<T>
where T: Copy + One + Zero + Neg<Output = T> + PartialOrd + Sub<Output = T> + Div<Output = T> + TrigonometricMethods + MathConstants + SqrtMethods + QuaternionMath + Vector3dMath + SensorFusionMath,