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:
@@ -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>;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user