Skip to content

Commit fde3afe

Browse files
committed
Sleepy
1 parent 016131e commit fde3afe

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

packages/evian-tracking/src/lib.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ pub mod wheeled;
5151
pub use sensor::RotarySensor;
5252

5353
use evian_math::{Angle, Vec2};
54-
use vexide::devices::smart::imu::{InertialError, InertialSensor};
5554

5655
/// A tracking system that localizes a robot's 2D position.
5756
///
@@ -115,27 +114,3 @@ pub trait TracksForwardTravel {
115114
/// values indicate backwards movement from the origin.
116115
fn forward_travel(&self) -> f64;
117116
}
118-
119-
/// A "gyroscope," or a sensor that measures the robot's heading and angular velocity
120-
pub trait Gyro {
121-
/// The error returned when [`Gyro::heading`] or [`Gyro::angular_velocity`] fails. This
122-
/// describes a hardware error.
123-
type Error;
124-
125-
/// Returns the heading of the robot as an [`Angle`]
126-
fn heading(&self) -> Result<Angle, Self::Error>;
127-
/// Returns the horizontal angular velocity
128-
fn angular_velocity(&self) -> Result<f64, Self::Error>;
129-
}
130-
131-
impl Gyro for InertialSensor {
132-
type Error = InertialError;
133-
134-
fn heading(&self) -> Result<Angle, Self::Error> {
135-
InertialSensor::heading(self).map(Angle::from_radians)
136-
}
137-
138-
fn angular_velocity(&self) -> Result<f64, Self::Error> {
139-
InertialSensor::gyro_rate(self).map(|rate| rate.z)
140-
}
141-
}

packages/evian-tracking/src/sensor.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use core::cell::RefCell;
22

33
use alloc::{rc::Rc, vec::Vec};
4+
use evian_math::Angle;
5+
use vexide::devices::smart::imu::{InertialError, InertialSensor};
46
use vexide::devices::{
57
PortError,
68
adi::AdiEncoder,
@@ -128,3 +130,37 @@ impl<T: RotarySensor> RotarySensor for Rc<RefCell<T>> {
128130
self.borrow().position()
129131
}
130132
}
133+
134+
/// A "gyroscope," or a sensor that measures the robot's heading and angular velocity
135+
pub trait Gyro {
136+
/// The error returned when [`Gyro::heading`] or [`Gyro::angular_velocity`] fails. This
137+
/// describes a hardware error.
138+
type Error;
139+
140+
/// Returns the heading of the robot as an [`Angle`]
141+
fn heading(&self) -> Result<Angle, Self::Error>;
142+
/// Returns the horizontal angular velocity
143+
fn angular_velocity(&self) -> Result<f64, Self::Error>;
144+
}
145+
146+
impl Gyro for InertialSensor {
147+
type Error = InertialError;
148+
149+
fn heading(&self) -> Result<Angle, Self::Error> {
150+
InertialSensor::heading(self).map(Angle::from_radians)
151+
}
152+
153+
fn angular_velocity(&self) -> Result<f64, Self::Error> {
154+
InertialSensor::gyro_rate(self).map(|rate| rate.z)
155+
}
156+
}
157+
impl<const N: usize> Gyro for [InertialSensor; N] {
158+
type Error = [Option<InertialError>; N];
159+
160+
fn angular_velocity(&self) -> Result<f64, Self::Error> {
161+
Ok(1.0)
162+
}
163+
fn heading(&self) -> Result<Angle, Self::Error> {
164+
Ok(Angle::from_degrees(1.0))
165+
}
166+
}

packages/evian-tracking/src/wheeled.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use vexide::{
1313
time::Instant,
1414
};
1515

16-
use crate::{Gyro, sensor::RotarySensor};
1716
use crate::{TracksForwardTravel, TracksHeading, TracksPosition};
17+
use crate::{sensor::Gyro, sensor::RotarySensor};
1818

1919
use super::TracksVelocity;
2020

0 commit comments

Comments
 (0)