created a generic "units" module, which should be helpful in keeping certain units Correct.
This commit is contained in:
+25
-14
@@ -1,5 +1,13 @@
|
||||
use core::fmt::Display;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::core::units::{
|
||||
Current,
|
||||
Voltage,
|
||||
Angle,
|
||||
};
|
||||
|
||||
///A simple enum for Counterclockwise or Clockwise direction semantics. Makes it easier much clear than a true/false bool
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||
pub enum Direction {
|
||||
@@ -10,6 +18,19 @@ pub enum Direction {
|
||||
|
||||
}
|
||||
|
||||
impl Direction {
|
||||
///Inverts the direction currently stored in this.
|
||||
/// Helps with a simple direction change without knowing the current direction.
|
||||
pub fn inv_dir(&mut self) {
|
||||
match *self {
|
||||
Self::CCW => {*self = Self::CW;}
|
||||
Self::CW => {*self = Self::CCW;}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
///A enum for containerizing speeds easily
|
||||
/// Lets the backend take in a Rotations per minute value from a user Sensor implementation and convert it to a Radians per second value
|
||||
///Pay attention to the units of each term
|
||||
@@ -47,19 +68,10 @@ impl Speed {
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Current {
|
||||
MilliAmps(u32),
|
||||
MicroAmps(u32),
|
||||
}
|
||||
|
||||
pub enum Voltage {
|
||||
MilliVolts(u32),
|
||||
MicroVolts(u32),
|
||||
}
|
||||
|
||||
pub enum Angle {
|
||||
Degrees(f32),
|
||||
Radians(f32),
|
||||
impl Display for Speed {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
write!(f, "")
|
||||
}
|
||||
}
|
||||
|
||||
///This trait is implemented on a motor struct to implement the motor DRIVER (like an ESC) capabalities in how it should control the motor.
|
||||
@@ -109,7 +121,6 @@ pub trait Sensor {
|
||||
/// IF properly returned in the correct Enum Data field, all other systems will use the value propely
|
||||
fn get_speed(&self) -> Speed;
|
||||
|
||||
|
||||
fn get_current(&self) -> Option<Current>;
|
||||
fn get_voltage(&self) -> Option<Voltage>;
|
||||
fn get_angle(&self) -> Option<Angle>;
|
||||
|
||||
Reference in New Issue
Block a user