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
impl Fusion
pub fn new(sample_rate: u32, ahrs_settings: FusionAhrsSettings) -> Self
pub fn inertial_calibration( &self, uncalibrated: FusionVector, misalignment: FusionMatrix, sensitivity: FusionVector, offset: FusionVector, ) -> FusionVector
pub fn magnetic_calibration( &self, uncalibrated: FusionVector, soft_iron_matrix: FusionMatrix, hard_iron_offset: FusionVector, ) -> FusionVector
Sourcepub fn update_no_mag(
&mut self,
gyr: FusionVector,
acc: FusionVector,
timestamp: f32,
)
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
}
Sourcepub fn update_no_mag_by_duration_seconds(
&mut self,
gyr: FusionVector,
acc: FusionVector,
delta_t: f32,
)
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();
}
Sourcepub fn update_external_heading(
&mut self,
gyr: FusionVector,
acc: FusionVector,
heading: f32,
timestamp: f32,
)
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
}
Sourcepub fn update_external_heading_by_duration_seconds(
&mut self,
gyr: FusionVector,
acc: FusionVector,
heading: f32,
delta_t: f32,
)
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();
}
Sourcepub fn update(
&mut self,
gyr: FusionVector,
acc: FusionVector,
mag: FusionVector,
timestamp: f32,
)
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
}
Sourcepub fn update_by_duration_seconds(
&mut self,
gyr: FusionVector,
acc: FusionVector,
mag: FusionVector,
delta_t: f32,
)
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();
}
Sourcepub fn euler(&self) -> FusionEuler
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);
Sourcepub fn earth_acc(&self) -> FusionVector
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);
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.