-
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.
Move simulation example code into modules
Signed-off-by: Markus Mayer <[email protected]>
- Loading branch information
Showing
5 changed files
with
278 additions
and
215 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use coordinate_frame::EastNorthUp; | ||
use serde::Deserialize; | ||
|
||
use marg_orientation::types::GyroscopeReading; | ||
|
||
use crate::simulation_utils::{Time, Timed}; | ||
|
||
/// L3GD20 gyroscope readings. | ||
#[derive(Debug, Deserialize)] | ||
pub struct L3GD20Gyro { | ||
/// The sample time, in seconds, relative to the Unix epoch. | ||
#[serde(rename = "host_time")] | ||
pub time: f64, | ||
/// Gyroscope reading on the x-axis. | ||
#[serde(rename = "x")] | ||
pub gyro_x: f32, | ||
/// Gyroscope reading on the y-axis. | ||
#[serde(rename = "y")] | ||
pub gyro_y: f32, | ||
/// Gyroscope reading on the z-axis. | ||
#[serde(rename = "z")] | ||
pub gyro_z: f32, | ||
} | ||
|
||
impl L3GD20Gyro { | ||
pub fn vec_into_timed(vec: Vec<Self>, time_offset: f64) -> Vec<Timed<GyroscopeReading<f32>>> { | ||
vec.into_iter() | ||
.map(Timed::from) | ||
.map(|t| t.with_time_offset(time_offset)) | ||
.collect() | ||
} | ||
} | ||
|
||
impl Time for L3GD20Gyro { | ||
fn time(&self) -> f64 { | ||
self.time | ||
} | ||
} | ||
|
||
impl From<&L3GD20Gyro> for GyroscopeReading<f32> { | ||
fn from(value: &L3GD20Gyro) -> Self { | ||
// The L3GD20 gyroscope on the STM32F3 Discovery board measures East, North, Up. | ||
let frame = EastNorthUp::new(value.gyro_x, value.gyro_y, value.gyro_z); | ||
// Normalize by the sensor value range. | ||
let frame = frame / 5.714285; | ||
GyroscopeReading::north_east_down(frame) | ||
} | ||
} | ||
|
||
impl From<L3GD20Gyro> for GyroscopeReading<f32> { | ||
fn from(value: L3GD20Gyro) -> Self { | ||
Self::from(&value) | ||
} | ||
} | ||
|
||
impl From<L3GD20Gyro> for Timed<GyroscopeReading<f32>> { | ||
fn from(value: L3GD20Gyro) -> Self { | ||
Self { | ||
time: value.time, | ||
reading: value.into(), | ||
} | ||
} | ||
} |
Oops, something went wrong.