removed all current communication code. Upper level main core code should be made first.
Upper level Core code, will also all be serde compatible anyways. Added in alot of comments to many methods and structs for core::motors Added in a Enum for each major data which will also support conversions from and to more useful dataTypes
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
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<f32>,
|
||||
unit: Unit,
|
||||
time_scale: TimeScale,
|
||||
}
|
||||
|
||||
impl MotorDriverShaftSpeed {
|
||||
///This returns the current shaft speed as an RPM Value, which is the default for display.
|
||||
/// It will be 0.0 if the data is none
|
||||
pub fn speed_as_rpm(&self) -> f32 {
|
||||
match self.shaft_speed {
|
||||
Some(mut speed) => {
|
||||
match self.unit {
|
||||
Unit::Radians => {speed /= core::f32::consts::PI * 2.0;}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
match self.time_scale {
|
||||
TimeScale::PerSecond => {speed *= 60.0;}
|
||||
_ => {}
|
||||
}
|
||||
speed
|
||||
}
|
||||
None => {
|
||||
0.0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for MotorDriverShaftSpeed {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
write!(f, "Motor Shaft Speed: {}", self.speed_as_rpm())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum Unit {
|
||||
Rotations,
|
||||
Radians,
|
||||
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum TimeScale {
|
||||
PerSecond,
|
||||
PerMinute,
|
||||
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
|
||||
pub struct MotorDriverDiagData {
|
||||
///Current draw of the motor if readable, reported in microAmps
|
||||
current: Option<i32>,
|
||||
///Voltage of the motor if readable, reported in microVolts
|
||||
voltage: Option<i32>,
|
||||
///Shaft speed of the motor if readable.
|
||||
shaft_speed: Option<MotorDriverShaftSpeed>,
|
||||
///Status of the hardware brake if present, none if not present.
|
||||
brake_status: Option<bool>,
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user