-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
40 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use core::mem::MaybeUninit; | ||
|
||
use fusion_imu_sys as sys; | ||
|
||
use crate::Vector; | ||
|
||
/// Gyroscope offset algorithm structure. | ||
pub struct FusionOffset { | ||
inner: sys::FusionOffset, | ||
} | ||
|
||
impl FusionOffset { | ||
/// Create a new `FusionOffset` instance. | ||
/// | ||
/// Sample rate in Hz. | ||
pub fn new(sample_rate: u32) -> Self { | ||
let mut offset = MaybeUninit::uninit(); | ||
unsafe { | ||
sys::FusionOffsetInitialise(offset.as_mut_ptr(), sample_rate); | ||
FusionOffset { | ||
inner: offset.assume_init(), | ||
} | ||
} | ||
} | ||
|
||
/// Updates the gyroscope offset algorithm and returns the corrected | ||
/// gyroscope measurement. Values are in degrees per second. | ||
pub fn update(&mut self, gyroscope: Vector) -> Vector { | ||
unsafe { | ||
sys::FusionOffsetUpdate(&mut self.inner as *mut sys::FusionOffset, gyroscope.into()) | ||
.into() | ||
} | ||
} | ||
} |