removed #[repr(u8)] from many structs across the project, I found out that rust by default makes small structs u8s, it is uneeded to do it manually.
This commit is contained in:
@@ -11,6 +11,8 @@ pub struct MotorDriverShaftSpeed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MotorDriverShaftSpeed {
|
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 {
|
pub fn speed_as_rpm(&self) -> f32 {
|
||||||
match self.shaft_speed {
|
match self.shaft_speed {
|
||||||
Some(mut speed) => {
|
Some(mut speed) => {
|
||||||
@@ -34,37 +36,21 @@ impl MotorDriverShaftSpeed {
|
|||||||
|
|
||||||
impl Display for MotorDriverShaftSpeed {
|
impl Display for MotorDriverShaftSpeed {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
match self.shaft_speed {
|
write!(f, "Motor Shaft Speed: {}", self.speed_as_rpm())
|
||||||
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)]
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
#[repr(u8)]
|
|
||||||
pub enum Unit {
|
pub enum Unit {
|
||||||
Unknown = 0,
|
Rotations,
|
||||||
Rotations = 1,
|
Radians,
|
||||||
Radians = 2,
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
#[repr(u8)]
|
|
||||||
pub enum TimeScale {
|
pub enum TimeScale {
|
||||||
Unknown = 0,
|
PerSecond,
|
||||||
PerSecond = 1,
|
PerMinute,
|
||||||
PerMinute = 2,
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -5,4 +5,5 @@ pub mod communication;
|
|||||||
#[cfg(feature = "core_logic")]
|
#[cfg(feature = "core_logic")]
|
||||||
pub mod logic;
|
pub mod logic;
|
||||||
|
|
||||||
pub mod positional;
|
pub mod positional;
|
||||||
|
pub mod motor;
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
pub enum Direction {
|
||||||
|
CCW,
|
||||||
|
CW
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Driver {
|
||||||
|
///Spins in the provided direction
|
||||||
|
///This is best not called manually, use set_speed_and_direction_raw instead
|
||||||
|
fn spin(&mut self, dir: Direction);
|
||||||
|
|
||||||
|
///Commands the motor to stop
|
||||||
|
fn stop(&mut self);
|
||||||
|
|
||||||
|
///This method uses a full u16 to set the motor speed. This does not change spin direction, if already spinning
|
||||||
|
///Uses a number between 0 and 65535
|
||||||
|
///This is best to not call manually, use set_speed_and_direction_raw instead
|
||||||
|
fn set_speed_raw(&mut self, speed: u16);
|
||||||
|
|
||||||
|
///Commands the motors to use the speed and spin in the same command.
|
||||||
|
///Uses a number between 0 and 65535
|
||||||
|
///This should be used in most cases, unless the motor has the core::logic::motor::controller Trait, then the the methods from that should be used instead.
|
||||||
|
fn set_speed_and_direction_raw(&mut self, speed: u16, dir: Direction) {
|
||||||
|
//Set direction before speed, so it won't start spinning in one direction, then snap to the other.
|
||||||
|
//Most MCUs should execute these two lines of code so fast, that it should be neglible though.
|
||||||
|
self.spin(dir);
|
||||||
|
self.set_speed_raw(speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Sensor {
|
||||||
|
fn get_speed(&self) -> f32;
|
||||||
|
fn get_current(&self) -> Option<u32>;
|
||||||
|
fn get_voltage(&self) -> Option<u32>;
|
||||||
|
fn get_angle(&self) -> Option<f32>;
|
||||||
|
|
||||||
|
}
|
||||||
+2
-19
@@ -113,7 +113,6 @@ impl Display for XYZPos {
|
|||||||
Unit::Meters => {"m"}
|
Unit::Meters => {"m"}
|
||||||
Unit::Radians => {"rad"}
|
Unit::Radians => {"rad"}
|
||||||
Unit::Custom => {"custom"}
|
Unit::Custom => {"custom"}
|
||||||
_ => {return write!(f, "Unknown Data");}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
write!(f, "[X: {:?}{unit_str} | Y: {:?}{unit_str} | Z: {:?}{unit_str}]", self.x, self.y, self.z)
|
write!(f, "[X: {:?}{unit_str} | Y: {:?}{unit_str} | Z: {:?}{unit_str}]", self.x, self.y, self.z)
|
||||||
@@ -126,7 +125,6 @@ impl Display for XYZVel {
|
|||||||
Unit::Meters => {"m"}
|
Unit::Meters => {"m"}
|
||||||
Unit::Radians => {"rad"}
|
Unit::Radians => {"rad"}
|
||||||
Unit::Custom => {"custom"}
|
Unit::Custom => {"custom"}
|
||||||
_ => {return write!(f, "Unknown Data");}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
write!(f, "[X: {:?}{unit_str}/s | Y: {:?}{unit_str}/s | Z: {:?}{unit_str}/s]", self.x, self.y, self.z)
|
write!(f, "[X: {:?}{unit_str}/s | Y: {:?}{unit_str}/s | Z: {:?}{unit_str}/s]", self.x, self.y, self.z)
|
||||||
@@ -139,7 +137,6 @@ impl Display for XYZAccel {
|
|||||||
Unit::Meters => {"m"}
|
Unit::Meters => {"m"}
|
||||||
Unit::Radians => {"rad"}
|
Unit::Radians => {"rad"}
|
||||||
Unit::Custom => {"custom"}
|
Unit::Custom => {"custom"}
|
||||||
_ => {return write!(f, "Unknown Data");}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
write!(f, "[X: {:?}{unit_str}/s^2 | Y: {:?}{unit_str}/s^2 | Z: {:?}{unit_str}/s^2]", self.x, self.y, self.z)
|
write!(f, "[X: {:?}{unit_str}/s^2 | Y: {:?}{unit_str}/s^2 | Z: {:?}{unit_str}/s^2]", self.x, self.y, self.z)
|
||||||
@@ -241,25 +238,11 @@ impl XYZData for XYZDataBucket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///Represents the unit this position struct is carrying. Combining the Unit + Trait it impls lets you determine what this message contatains
|
///Represents the unit this position struct is carrying. Combining the Unit + Trait it impls lets you determine what this message contains
|
||||||
/// 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
|
||||||
/// 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, )]
|
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug, )]
|
||||||
#[repr(u8)]
|
|
||||||
pub enum Unit {
|
pub enum Unit {
|
||||||
Unknown = 0,
|
|
||||||
Meters = 1,
|
Meters = 1,
|
||||||
Radians = 2,
|
Radians = 2,
|
||||||
Custom = 3,
|
Custom = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u8> for Unit {
|
|
||||||
fn from(value: u8) -> Self {
|
|
||||||
match value {
|
|
||||||
1 => {Self::Meters}
|
|
||||||
2 => {Self::Radians}
|
|
||||||
3 => {Self::Custom}
|
|
||||||
_ => {Self::Unknown}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,4 +5,3 @@ compile_error!(
|
|||||||
Please use '--no-default-features --features embassy' to build for MCU\n\
|
Please use '--no-default-features --features embassy' to build for MCU\n\
|
||||||
or verify that you have not included a different feature that requires'std'"
|
or verify that you have not included a different feature that requires'std'"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user