created a generic "units" module, which should be helpful in keeping certain units Correct.
This commit is contained in:
+2
-1
@@ -6,4 +6,5 @@ pub mod communication;
|
|||||||
pub mod logic;
|
pub mod logic;
|
||||||
|
|
||||||
pub mod positional;
|
pub mod positional;
|
||||||
pub mod motor;
|
pub mod motor;
|
||||||
|
pub mod units;
|
||||||
+25
-14
@@ -1,5 +1,13 @@
|
|||||||
|
use core::fmt::Display;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
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
|
///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)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||||
pub enum Direction {
|
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
|
///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
|
/// 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
|
///Pay attention to the units of each term
|
||||||
@@ -47,19 +68,10 @@ impl Speed {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Current {
|
impl Display for Speed {
|
||||||
MilliAmps(u32),
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
MicroAmps(u32),
|
write!(f, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Voltage {
|
|
||||||
MilliVolts(u32),
|
|
||||||
MicroVolts(u32),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum Angle {
|
|
||||||
Degrees(f32),
|
|
||||||
Radians(f32),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///This trait is implemented on a motor struct to implement the motor DRIVER (like an ESC) capabalities in how it should control the motor.
|
///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
|
/// IF properly returned in the correct Enum Data field, all other systems will use the value propely
|
||||||
fn get_speed(&self) -> Speed;
|
fn get_speed(&self) -> Speed;
|
||||||
|
|
||||||
|
|
||||||
fn get_current(&self) -> Option<Current>;
|
fn get_current(&self) -> Option<Current>;
|
||||||
fn get_voltage(&self) -> Option<Voltage>;
|
fn get_voltage(&self) -> Option<Voltage>;
|
||||||
fn get_angle(&self) -> Option<Angle>;
|
fn get_angle(&self) -> Option<Angle>;
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ impl XYZData for XYZDataBucket {
|
|||||||
/// If you need to send a unit not listed here please use Unit::Custom
|
/// If you need to send a unit not listed here please use Unit::Custom
|
||||||
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug, )]
|
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug, )]
|
||||||
pub enum Unit {
|
pub enum Unit {
|
||||||
Meters = 1,
|
Meters,
|
||||||
Radians = 2,
|
Radians,
|
||||||
Custom = 3,
|
Custom,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
pub enum Current {
|
||||||
|
MilliAmps(u32),
|
||||||
|
MicroAmps(u32),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Voltage {
|
||||||
|
MilliVolts(u32),
|
||||||
|
MicroVolts(u32),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Angle {
|
||||||
|
Degrees(f32),
|
||||||
|
Radians(f32),
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user