-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from peterkrull/master
Add non-fallible update function
- Loading branch information
Showing
4 changed files
with
90 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,42 @@ | ||
use nalgebra::{Scalar, UnitQuaternion, Vector3}; | ||
use simba::simd::SimdValue; | ||
|
||
#[derive(Debug)] | ||
pub enum AhrsError { | ||
AccelerometerNormZero, | ||
MagnetometerNormZero, | ||
} | ||
|
||
/// Trait for implementing an AHRS filter. | ||
pub trait Ahrs<N: Scalar + SimdValue> { | ||
/// Attempts to update the current state quaternion using 9dof IMU values, made up by `gyroscope`, | ||
/// `accelerometer`, and `magnetometer`. | ||
/// | ||
/// Returns a reference to the updated quaternion on success, or in the case of failure, an | ||
/// `Err(&str)` containing the reason. | ||
/// `AhrsError` enum, which describes the reason. | ||
fn update( | ||
&mut self, | ||
gyroscope: &Vector3<N>, | ||
accelerometer: &Vector3<N>, | ||
magnetometer: &Vector3<N>, | ||
) -> Result<&UnitQuaternion<N>, &str>; | ||
) -> Result<&UnitQuaternion<N>, AhrsError>; | ||
|
||
/// Attempts to update the current state quaternion using 6dof IMU values, made up by `gyroscope` & | ||
/// `accelerometer`. | ||
/// | ||
/// Returns a reference to the updated quaternion on success, or in the case of failure, an | ||
/// `Err(&str)` containing the reason. | ||
/// `AhrsError` enum, which describes the reason. | ||
fn update_imu( | ||
&mut self, | ||
gyroscope: &Vector3<N>, | ||
accelerometer: &Vector3<N>, | ||
) -> Result<&UnitQuaternion<N>, &str>; | ||
) -> Result<&UnitQuaternion<N>, AhrsError>; | ||
|
||
/// Updates the current state quaternion using only 3dof IMU values, made up by `gyroscope`. | ||
/// | ||
/// Returns a reference to the updated quaternion. | ||
fn update_gyro( | ||
&mut self, | ||
gyroscope: &Vector3<N>, | ||
) -> &UnitQuaternion<N>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters