Added derive fields to the Data and PID struct

This commit is contained in:
2026-06-09 19:14:40 -05:00
parent 123f7f7030
commit f9bf19936b
2 changed files with 4 additions and 2 deletions
+3 -2
View File
@@ -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;