Struct Fusion

Source
pub struct Fusion {
    pub gyr_misalignment: FusionMatrix,
    pub gyr_sensitivity: FusionVector,
    pub gyr_offset: FusionVector,
    pub acc_misalignment: FusionMatrix,
    pub acc_sensitivity: FusionVector,
    pub acc_offset: FusionVector,
    pub soft_iron_matrix: FusionMatrix,
    pub hard_iron_offset: FusionVector,
    pub ahrs: FusionAhrs,
    pub offset: FusionGyrOffset,
    pub last_timestamp: f32,
}

Fields§

§gyr_misalignment: FusionMatrix§gyr_sensitivity: FusionVector§gyr_offset: FusionVector§acc_misalignment: FusionMatrix§acc_sensitivity: FusionVector§acc_offset: FusionVector§soft_iron_matrix: FusionMatrix§hard_iron_offset: FusionVector§ahrs: FusionAhrs§offset: FusionGyrOffset§last_timestamp: f32

Implementations§

Source§

impl Fusion

Source

pub fn new(sample_rate: u32, ahrs_settings: FusionAhrsSettings) -> Self

Source

pub fn inertial_calibration( &self, uncalibrated: FusionVector, misalignment: FusionMatrix, sensitivity: FusionVector, offset: FusionVector, ) -> FusionVector

Source

pub fn magnetic_calibration( &self, uncalibrated: FusionVector, soft_iron_matrix: FusionMatrix, hard_iron_offset: FusionVector, ) -> FusionVector

Source

pub fn update_no_mag( &mut self, gyr: FusionVector, acc: FusionVector, timestamp: f32, )

Updates the AHRS algorithm based on gyroscope data in degrees/s and acceleration data in g force.

The time is provided using an absolute timestamp in seconds since the first measurement. Note that if you provide unix timestamps, the precision of f32 will not be enough to correctly compute the time difference.

§Examples
use imu_fusion::{Fusion, FusionVector, FusionAhrsSettings};

const SAMPLE_RATE_HZ: u32 = 100;

let ahrs_settings = FusionAhrsSettings::new();
let mut fusion = imu_fusion::Fusion::new(SAMPLE_RATE_HZ, ahrs_settings);
let mut current_ts = 0f32;

loop {
    let gyr = FusionVector::new(0f32, 0f32, 0f32); // replace this with actual gyroscope data in degrees/s
    let acc = FusionVector::new(0f32, 0f32, 1.0f32); // replace this with actual accelerometer data in g
    fusion.update_no_mag(gyr, acc, current_ts);
    current_ts += 1.0 / SAMPLE_RATE_HZ as f32
}
Source

pub fn update_no_mag_by_duration_seconds( &mut self, gyr: FusionVector, acc: FusionVector, delta_t: f32, )

Updates the AHRS algorithm based on gyroscope data in degrees/s and acceleration data in g force.

The time is provided as a duration in seconds since the last measurement. Note that this won’t increase the internal timestamp and using the timestamp version of update functions will produce incorrect results.

§Examples
use imu_fusion::{Fusion, FusionVector, FusionAhrsSettings};
use std::time::{Duration, Instant};

const SAMPLE_RATE_HZ: u32 = 100;

let ahrs_settings = FusionAhrsSettings::new();
let mut fusion = imu_fusion::Fusion::new(SAMPLE_RATE_HZ, ahrs_settings);
let mut last_ts = Instant::now();

loop {
    let gyr = FusionVector::new(0f32, 0f32, 0f32); // replace this with actual gyroscope data in degrees/s
    let acc = FusionVector::new(0f32, 0f32, 1.0f32); // replace this with actual accelerometer data in g
    fusion.update_no_mag_by_duration_seconds(gyr, acc, last_ts.elapsed().as_secs_f32());
    last_ts = Instant::now();
}
Source

pub fn update_external_heading( &mut self, gyr: FusionVector, acc: FusionVector, heading: f32, timestamp: f32, )

Updates the AHRS algorithm based on gyroscope data in degrees/s, acceleration data in g force and a heading in degrees.

The time is provided using an absolute timestamp in seconds since the first measurement. Note that if you provide unix timestamps, the precision of f32 will not be enough to correctly compute the time difference.

§Examples
use imu_fusion::{Fusion, FusionVector, FusionAhrsSettings};

const SAMPLE_RATE_HZ: u32 = 100;

let ahrs_settings = FusionAhrsSettings::new();
let mut fusion = Fusion::new(SAMPLE_RATE_HZ, ahrs_settings);
let mut current_ts = 0f32;

loop {
    let gyr = FusionVector::new(0f32, 0f32, 0f32); // replace this with actual gyroscope data in degrees/s
    let acc = FusionVector::new(0f32, 0f32, 1.0f32); // replace this with actual accelerometer data in g
    let external_heading = 0f32; // replace this with actual heading in degrees
    fusion.update_external_heading(gyr, acc, external_heading, current_ts);
    current_ts += 1.0 / SAMPLE_RATE_HZ as f32
}
Source

pub fn update_external_heading_by_duration_seconds( &mut self, gyr: FusionVector, acc: FusionVector, heading: f32, delta_t: f32, )

Updates the AHRS algorithm based on gyroscope data in degrees/s, acceleration data in g force and a heading in degrees.

The time is provided using a duration in seconds since the last measurement. Note that this won’t increase the internal timestamp and using the timestamp version of update functions will produce incorrect results.

§Examples
use imu_fusion::{Fusion, FusionVector, FusionAhrsSettings};
use std::time::{Duration, Instant};

const SAMPLE_RATE_HZ: u32 = 100;

let ahrs_settings = FusionAhrsSettings::new();
let mut fusion = Fusion::new(SAMPLE_RATE_HZ, ahrs_settings);
let mut last_ts = Instant::now();

loop {
    let gyr = FusionVector::new(0f32, 0f32, 0f32); // replace this with actual gyroscope data in degrees/s
    let acc = FusionVector::new(0f32, 0f32, 1.0f32); // replace this with actual accelerometer data in g
    let external_heading = 0f32; // replace this with actual heading in degrees
    fusion.update_external_heading(gyr, acc, external_heading, last_ts.elapsed().as_secs_f32());
    last_ts = Instant::now();
}
Source

pub fn update( &mut self, gyr: FusionVector, acc: FusionVector, mag: FusionVector, timestamp: f32, )

Updates the AHRS algorithm based on gyroscope data in degrees/s, acceleration data in g force and magnetic measurements in degrees.

The time is provided using an absolute timestamp in seconds since the first measurement. Note that if you provide unix timestamps, the precision of f32 will not be enough to correctly compute the time difference.

§Examples
use imu_fusion::{Fusion, FusionAhrsSettings, FusionVector};

const SAMPLE_RATE_HZ: u32 = 100;

let ahrs_settings = FusionAhrsSettings::new();
let mut fusion = Fusion::new(SAMPLE_RATE_HZ, ahrs_settings);
let mut current_ts = 0f32;

loop {
    let gyr = FusionVector::new(0f32, 0f32, 0f32); // replace this with actual gyroscope data in degrees/s
    let acc = FusionVector::new(0f32, 0f32, 1.0f32); // replace this with actual accelerometer data in g
    let mag = FusionVector::new(0f32, 0f32, 1.0f32); // replace this with actual magnetic measurement in degrees
    fusion.update(gyr, acc, mag, current_ts);
    current_ts += 1.0 / SAMPLE_RATE_HZ as f32
}
Source

pub fn update_by_duration_seconds( &mut self, gyr: FusionVector, acc: FusionVector, mag: FusionVector, delta_t: f32, )

Updates the AHRS algorithm based on gyroscope data in degrees/s, acceleration data in g force and magnetic measurements in degrees.

The time is provided using a duration in seconds since the last measurement. Note that this won’t increase the internal timestamp and using the timestamp version of update functions will produce incorrect results.

§Examples
use imu_fusion::{Fusion, FusionAhrsSettings, FusionVector};
use std::time::{Duration, Instant};

const SAMPLE_RATE_HZ: u32 = 100;

let ahrs_settings = FusionAhrsSettings::new();
let mut fusion = Fusion::new(SAMPLE_RATE_HZ, ahrs_settings);
let mut last_ts = Instant::now();

loop {
    let gyr = FusionVector::new(0f32, 0f32, 0f32); // replace this with actual gyroscope data in degrees/s
    let acc = FusionVector::new(0f32, 0f32, 1.0f32); // replace this with actual accelerometer data in g
    let mag = FusionVector::new(0f32, 0f32, 1.0f32); // replace this with actual magnetic measurement in degrees
    fusion.update_by_duration_seconds(gyr, acc, mag, last_ts.elapsed().as_secs_f32());
    last_ts = Instant::now();
}
Source

pub fn euler(&self) -> FusionEuler

Obtain euler angle current sensor position

Euler angles are provided in degrees

§Examples
use imu_fusion::{Fusion, FusionAhrsSettings};

const SAMPLE_RATE_HZ: u32 = 100;

let ahrs_settings = FusionAhrsSettings::new();
let mut fusion = Fusion::new(SAMPLE_RATE_HZ, ahrs_settings);

// ...update sensor values

let euler = fusion.euler();
println!("Roll {}, Pitch {}, Yaw {}", euler.angle.roll, euler.angle.pitch, euler.angle.yaw);
Source

pub fn earth_acc(&self) -> FusionVector

Obtain acceleration of sensor in earth’s frame of reference

The values returned are provided in g force

§Examples
use imu_fusion::{Fusion, FusionAhrsSettings, FusionVector};

const SAMPLE_RATE_HZ: u32 = 100;

let ahrs_settings = FusionAhrsSettings::new();
let mut fusion = Fusion::new(SAMPLE_RATE_HZ, ahrs_settings);

// ...update sensor values

let acc = fusion.earth_acc();
println!("x {}, y {}, z {}", acc.x, acc.y, acc.z);
Source

pub fn quaternion(&self) -> FusionQuaternion

Auto Trait Implementations§

§

impl Freeze for Fusion

§

impl RefUnwindSafe for Fusion

§

impl Send for Fusion

§

impl Sync for Fusion

§

impl Unpin for Fusion

§

impl UnwindSafe for Fusion

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.