Added new method for the controller struct.
This commit is contained in:
+11
-1
@@ -11,11 +11,12 @@ use crate::core::logic::pid;
|
|||||||
/// ## Usage
|
/// ## Usage
|
||||||
///
|
///
|
||||||
/// Creating this allows for the controller a motor via a simple PID f32 signed Speed command, rather than u16 speed commands
|
/// Creating this allows for the controller a motor via a simple PID f32 signed Speed command, rather than u16 speed commands
|
||||||
|
/// Notice that this also TAKES the motor from your manual controller, you loose access to the manual hand control you had before.
|
||||||
pub struct Controller<T>
|
pub struct Controller<T>
|
||||||
where
|
where
|
||||||
T: motor::Driver + motor::Sensor,
|
T: motor::Driver + motor::Sensor,
|
||||||
{
|
{
|
||||||
pub motor: T,
|
motor: T,
|
||||||
max_speed: Speed,
|
max_speed: Speed,
|
||||||
pid: pid::PID,
|
pid: pid::PID,
|
||||||
current_direction: Direction,
|
current_direction: Direction,
|
||||||
@@ -38,4 +39,13 @@ impl<T: motor::Driver + motor::Sensor> Controller<T> {
|
|||||||
self.motor
|
self.motor
|
||||||
.set_speed_and_direction(motor_command, self.current_direction);
|
.set_speed_and_direction(motor_command, self.current_direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new(motor: T, max_speed: Speed, pid: pid::PID) -> Self {
|
||||||
|
Controller {
|
||||||
|
motor: motor,
|
||||||
|
max_speed: max_speed,
|
||||||
|
pid: pid,
|
||||||
|
current_direction: Direction::CCW,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user