cargo fmt

This commit is contained in:
2026-06-07 00:36:22 -05:00
parent 2eae22cb9b
commit 35fd1e8532
10 changed files with 98 additions and 94 deletions
+1
View File
@@ -0,0 +1 @@
+2 -2
View File
@@ -1,4 +1,4 @@
pub mod sensing;
pub mod motor;
pub mod drivetrain;
pub mod motor;
pub mod sensing;
pub mod wheel;
+1
View File
@@ -0,0 +1 @@
+1
View File
@@ -0,0 +1 @@
+1
View File
@@ -0,0 +1 @@
+1 -2
View File
@@ -1,10 +1,9 @@
#[cfg(feature = "core_communication")]
pub mod communication;
#[cfg(feature = "core_logic")]
pub mod logic;
pub mod positional;
pub mod motor;
pub mod positional;
pub mod units;
+20 -22
View File
@@ -2,9 +2,10 @@ use core::fmt::Display;
use serde::{Deserialize, Serialize};
use crate::core::{motor::Direction::{CCW, CW}, units::{
Angle, Current, Voltage
}};
use crate::core::{
motor::Direction::{CCW, CW},
units::{Angle, Current, Voltage},
};
///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)]
@@ -12,8 +13,7 @@ pub enum Direction {
///CounterClockWise
CCW,
///ClockWise
CW
CW,
}
impl Direction {
@@ -21,8 +21,12 @@ impl Direction {
/// 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;}
Self::CCW => {
*self = Self::CW;
}
Self::CW => {
*self = Self::CCW;
}
}
}
@@ -30,7 +34,9 @@ impl Direction {
///Recommended to use this over the "From" impl for directions that already exist, to prevent werid 0.0 case and NaN problems
/// This handles 0.0 and NaN by just doing nothing. The "From" impl defualts to CCW for both
pub fn dir_from_f32(&mut self, value: f32) {
if value == 0.0 || value.is_nan() { return; }
if value == 0.0 || value.is_nan() {
return;
}
*self = value.into();
}
@@ -38,7 +44,9 @@ impl Direction {
///Recommended to use this over the "From" impl for directions that already exist, to prevent weird 0 case problems
///This handles 0 by just doing nothing. The "From" impl defaults to CCW
pub fn dir_from_i32(&mut self, value: i32) {
if value == 0 { return; }
if value == 0 {
return;
}
*self = value.into();
}
}
@@ -47,11 +55,7 @@ impl Direction {
/// This defaults to CCW for 0.0 and NaN.
impl From<f32> for Direction {
fn from(value: f32) -> Self {
if value < 0.0 {
CW
} else {
CCW
}
if value < 0.0 { CW } else { CCW }
}
}
@@ -59,11 +63,7 @@ impl From<f32> for Direction {
/// This defaults to CCW for 0.
impl From<i32> for Direction {
fn from(value: i32) -> Self {
if value < 0 {
CW
} else {
CCW
}
if value < 0 { CW } else { CCW }
}
}
@@ -96,7 +96,7 @@ impl Speed {
///Returns the value as Rotations Per minute regardles of what the enum contains
/// Uses no runtime division
#[inline]
pub fn rpm(&self) -> f32{
pub fn rpm(&self) -> f32 {
match *self {
Self::RPM(rpm) => rpm,
Self::RADS(rps) => rps * RPM_TO_RADS,
@@ -141,7 +141,6 @@ pub trait Driver {
self.spin(dir);
self.set_speed(speed);
}
}
///This trait is implemented on motors that have some form of sensory feedback. Note that this does not require the motor ITSELF provide feedback, just that the setup the motor is in supports it. IE, a Current draw based ESC
@@ -169,5 +168,4 @@ pub trait Sensor {
///Returns the current angle from the sensor if it is capable.
/// This should be non-blocking. Keep a cached value ready.
fn get_angle(&self) -> Option<Angle>;
}
+42 -40
View File
@@ -1,9 +1,9 @@
use core::{fmt::{Display}};
use core::fmt::Display;
use serde::{Deserialize, Serialize};
///Generic Positional Data Struct, This can contain XYZ positions in meters or Radians
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Debug, )]
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Debug)]
pub struct XYZPos {
x: Option<f32>,
y: Option<f32>,
@@ -12,7 +12,7 @@ pub struct XYZPos {
}
///Generic Velocity Data Struct, This can contain XYZ velocities in Meters Per Second or Radians Per Second
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Debug, )]
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Debug)]
pub struct XYZVel {
x: Option<f32>,
y: Option<f32>,
@@ -21,8 +21,8 @@ pub struct XYZVel {
}
///Generic Acceleration Data Struct, This can contain XYZ accelerations in Meters Per Second Squared or Radians Per Second
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Debug, )]
pub struct XYZAccel{
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Debug)]
pub struct XYZAccel {
x: Option<f32>,
y: Option<f32>,
z: Option<f32>,
@@ -95,68 +95,68 @@ impl XYZData for XYZAccel {
}
}
impl Position for XYZPos {
impl Position for XYZPos {}
}
impl Velocity for XYZVel {}
impl Velocity for XYZVel {
}
impl Acceleration for XYZAccel {
}
impl Acceleration for XYZAccel {}
impl Display for XYZPos {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let unit_str = match self.unit {
Unit::Meters => {"m"}
Unit::Radians => {"rad"}
Unit::Custom => {"custom"}
Unit::Meters => "m",
Unit::Radians => "rad",
Unit::Custom => "custom",
};
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
)
}
}
impl Display for XYZVel {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let unit_str = match self.unit {
Unit::Meters => {"m"}
Unit::Radians => {"rad"}
Unit::Custom => {"custom"}
Unit::Meters => "m",
Unit::Radians => "rad",
Unit::Custom => "custom",
};
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
)
}
}
impl Display for XYZAccel {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let unit_str = match self.unit {
Unit::Meters => {"m"}
Unit::Radians => {"rad"}
Unit::Custom => {"custom"}
Unit::Meters => "m",
Unit::Radians => "rad",
Unit::Custom => "custom",
};
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
)
}
}
///Structs that impl this trait, mean they are positions. Determine what type of position by reading the unit.
pub trait Position : XYZData {
}
pub trait Position: XYZData {}
///Structs that impl this trait mean they are Velocities. Determine what type of velocity by reading the unit.
pub trait Velocity : XYZData{
}
pub trait Velocity: XYZData {}
///Structs that impl this trait mean they are Accelerations. Determine what type of Acceleration by reading the unit.
pub trait Acceleration : XYZData{
}
pub trait Acceleration: XYZData {}
///This is the data backbone for the XYZ Position, Velocity, and Acceleration Data structs.
///They MUST implmenent this so it possible to easily and quickly get the data from the struct.
@@ -171,7 +171,11 @@ pub 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] {
[self.x().unwrap_or(0.0), self.y().unwrap_or(0.0), self.z().unwrap_or(0.0)]
[
self.x().unwrap_or(0.0),
self.y().unwrap_or(0.0),
self.z().unwrap_or(0.0),
]
}
fn is_pos(&self) -> bool {
@@ -185,8 +189,7 @@ pub trait XYZData {
}
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, )]
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
pub enum XYZDataBucket {
Pos(XYZPos),
Vel(XYZVel),
@@ -237,10 +240,9 @@ impl XYZData for XYZDataBucket {
}
}
///Represents the unit this position struct is carrying. Combining the Unit + Trait it impls lets you determine what this message contains
/// 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 {
Meters,
Radians,
+6 -6
View File
@@ -30,9 +30,9 @@ impl From<f32> for Current {
impl Into<f32> for Current {
fn into(self) -> f32 {
match self {
Self::MicroAmps(micro) => {micro as f32 * FROM_MICRO}
Self::MilliAmps(milli) => {milli as f32 * FROM_MILLI}
Self::Amps(amps) => {amps}
Self::MicroAmps(micro) => micro as f32 * FROM_MICRO,
Self::MilliAmps(milli) => milli as f32 * FROM_MILLI,
Self::Amps(amps) => amps,
}
}
}
@@ -58,9 +58,9 @@ impl From<f32> for Voltage {
impl Into<f32> for Voltage {
fn into(self) -> f32 {
match self {
Self::MicroVolts(micro) => {micro as f32 * FROM_MICRO}
Self::MilliVolts(milli) => {milli as f32 * FROM_MILLI}
Self::Volts(volts) => {volts}
Self::MicroVolts(micro) => micro as f32 * FROM_MICRO,
Self::MilliVolts(milli) => milli as f32 * FROM_MILLI,
Self::Volts(volts) => volts,
}
}
}
+1
View File
@@ -0,0 +1 @@