diff --git a/src/core/communication/general.rs b/src/core/communication/general.rs deleted file mode 100644 index 9a69f7d..0000000 --- a/src/core/communication/general.rs +++ /dev/null @@ -1,24 +0,0 @@ -use serde::{Deserialize, Serialize}; - -///Represents the unit this struct is carrying. Combining the Unit + Trait it impls lets you determine what this message contatains -/// A value of 0 or Unknown means the data is malformed or something is was wrong on the sending side, it should be treated a failure case. -/// If you need to send a unit not listed here please use Unit::Custom instead of Unit::Unknown -#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug, )] -#[repr(u8)] -pub enum Unit { - Unknown = 0, - Meters = 1, - Radians = 2, - Custom = 3, -} - -impl From for Unit { - fn from(value: u8) -> Self { - match value { - 1 => {Self::Meters} - 2 => {Self::Radians} - 3 => {Self::Custom} - _ => {Self::Unknown} - } - } -} diff --git a/src/core/communication/mod.rs b/src/core/communication/mod.rs index 400aa4d..b001942 100644 --- a/src/core/communication/mod.rs +++ b/src/core/communication/mod.rs @@ -1,6 +1,4 @@ pub mod sensing; pub mod motor; -pub mod positional; -pub mod general; pub mod drivetrain; pub mod wheel; \ No newline at end of file diff --git a/src/core/communication/motor.rs b/src/core/communication/motor.rs index 9e01730..d72e5fd 100644 --- a/src/core/communication/motor.rs +++ b/src/core/communication/motor.rs @@ -1,4 +1,65 @@ -use serde::{Deserialize, Serialize}; -pub struct MotorRPM{ +use core::fmt::Display; + +use serde::{Deserialize, Serialize}; + +///Motor Drivers reported shaft speed. This can be in any of the given unit types by the Unit enum and timescalse given by the TimeScales enum +#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)] +pub struct MotorDriverShaftSpeed { + shaft_speed: Option, + unit: Unit, + time_scale: TimeScale, +} + +impl MotorDriverShaftSpeed { + +} + +impl Display for MotorDriverShaftSpeed { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self.shaft_speed { + Some(speed) => { + let unit = match self.unit { + Unit::Radians => "rad", + Unit::Rotations => "R", + _ => "", + }; + + + write!(f, "") + } + None => {write!(f, "No Given Speeds")} + } + } +} + +#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] +#[repr(u8)] +pub enum Unit { + Unknown = 0, + Rotations = 1, + Radians = 2, + +} + +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] +#[repr(u8)] +pub enum TimeScale { + Unknown = 0, + PerSecond = 1, + PerMinute = 2, + +} + +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)] +pub struct MotorDriverDiagData { + ///Current draw of the motor if readable, reported in microAmps + current: Option, + ///Voltage of the motor if readable, reported in microVolts + voltage: Option, + ///Shaft speed of the motor if readable. + shaft_speed: Option, + ///Status of the hardware brake if present, none if not present. + brake_status: Option, + +} -} \ No newline at end of file diff --git a/src/core/mod.rs b/src/core/mod.rs index 654adc7..8feb5d7 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -3,4 +3,6 @@ pub mod communication; #[cfg(feature = "core_logic")] -pub mod logic; \ No newline at end of file +pub mod logic; + +pub mod positional; \ No newline at end of file diff --git a/src/core/communication/positional.rs b/src/core/positional.rs similarity index 84% rename from src/core/communication/positional.rs rename to src/core/positional.rs index 468f8e4..03c7b20 100644 --- a/src/core/communication/positional.rs +++ b/src/core/positional.rs @@ -1,9 +1,7 @@ -use core::{fmt::{Display}, u8}; +use core::{fmt::{Display}}; use serde::{Deserialize, Serialize}; -use crate::core::communication::general::Unit; - ///Generic Positional Data Struct, This can contain XYZ positions in meters or Radians #[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Debug, )] pub struct XYZPos { @@ -153,12 +151,12 @@ trait Position : XYZData { } -///Structs that impl this trait mean they are Velocities. Determine the type of velocity by reading the unit. +///Structs that impl this trait mean they are Velocities. Determine what type of velocity by reading the unit. trait Velocity : XYZData{ } -///Structs that impl this trait mean they are Accelerations. Determine the type of Acceleration by reading the unit. +///Structs that impl this trait mean they are Accelerations. Determine what type of Acceleration by reading the unit. trait Acceleration : XYZData{ } @@ -176,8 +174,7 @@ trait XYZData { ///Any option field in the array that are None are returned as 0.0 here. ///Do not forget to check the unit, this may be in radians or meters. fn xyz_array(&self) -> [f32; 3] { - let arr = [self.x().unwrap_or(0.0), self.y().unwrap_or(0.0), self.z().unwrap_or(0.0)]; - arr + [self.x().unwrap_or(0.0), self.y().unwrap_or(0.0), self.z().unwrap_or(0.0)] } fn is_pos(&self) -> bool { @@ -241,4 +238,28 @@ impl XYZData for XYZDataBucket { Self::Accel(a) => a.unit(), } } -} \ No newline at end of file +} + + +///Represents the unit this position struct is carrying. Combining the Unit + Trait it impls lets you determine what this message contatains +/// A value of 0 or Unknown means the data is malformed or something is was wrong on the sending side, it should be treated a failure case. +/// If you need to send a unit not listed here please use Unit::Custom instead of Unit::Unknown +#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug, )] +#[repr(u8)] +pub enum Unit { + Unknown = 0, + Meters = 1, + Radians = 2, + Custom = 3, +} + +impl From for Unit { + fn from(value: u8) -> Self { + match value { + 1 => {Self::Meters} + 2 => {Self::Radians} + 3 => {Self::Custom} + _ => {Self::Unknown} + } + } +}