diff --git a/src/core/logic/motor.rs b/src/core/logic/motor.rs index 3ddce2a..0bf9839 100644 --- a/src/core/logic/motor.rs +++ b/src/core/logic/motor.rs @@ -3,6 +3,7 @@ use crate::core::motor::{Direction, Speed}; use crate::core::logic::pid; +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Data { pub max_speed: Speed, pub pid: pid::PID, @@ -16,14 +17,14 @@ pub trait Controller: motor::Driver + motor::Sensor { ///Uses the given set_speed and then will handle the rest of the control logic to accurately* hit the requested speed fn control(&mut self, set_speed: Speed) { - let data: &mut Data = &mut self.data(); + let data = &mut self.data(); let max_speed_rads = data.max_speed.rads(); let set_speed_rads = set_speed.rads().clamp(-max_speed_rads, max_speed_rads); data.pid.set_point(set_speed_rads); let pid_output = data.pid.pid_step(self.get_speed().rads()); - data.current_direction.dir_from_f32(pid_output); + self.data().current_direction.dir_from_f32(pid_output); let motor_command = (pid_output * 65535.0) as u16; diff --git a/src/core/logic/pid.rs b/src/core/logic/pid.rs index 510857e..b1f6fba 100644 --- a/src/core/logic/pid.rs +++ b/src/core/logic/pid.rs @@ -19,6 +19,7 @@ pub struct Config { ///A PID, the config field is used to handle all the needed configuration. /// This PID using pid_step() then attempts to output a value between -1.0 and 1.0 to attempt to make the "current_value" passed in, match the "set_point" +#[derive(Debug, PartialEq, Clone, Copy)] pub struct PID { pub config: Config,