use core::time::Duration;
use evian_control::{Tolerances, loops::ControlLoop};
use evian_drivetrain::Drivetrain;
use evian_drivetrain::differential::Differential;
use evian_math::{Angle, Vec2};
use evian_tracking::{TracksHeading, TracksPosition, TracksVelocity};
mod boomerang;
mod move_to_point;
pub use boomerang::BoomerangFuture;
pub use move_to_point::MoveToPointFuture;
#[derive(PartialEq)]
pub struct Seeking<
L: ControlLoop<Input = f64, Output = f64> + Unpin + Clone,
A: ControlLoop<Input = Angle, Output = f64> + Unpin + Clone,
> {
pub linear_controller: L,
pub angular_controller: A,
pub tolerances: Tolerances,
pub timeout: Option<Duration>,
}
impl<
L: ControlLoop<Input = f64, Output = f64> + Unpin + Clone,
A: ControlLoop<Input = Angle, Output = f64> + Unpin + Clone,
> Seeking<L, A>
{
pub fn move_to_point<'a, T: TracksPosition + TracksHeading + TracksVelocity>(
&mut self,
drivetrain: &'a mut Drivetrain<Differential, T>,
point: impl Into<Vec2<f64>>,
) -> MoveToPointFuture<'a, L, A, T> {
MoveToPointFuture {
drivetrain,
reverse: false,
target_point: point.into(),
timeout: self.timeout,
tolerances: self.tolerances,
linear_controller: self.linear_controller.clone(),
angular_controller: self.angular_controller.clone(),
state: None,
}
}
pub fn boomerang<'a, T: TracksPosition + TracksHeading + TracksVelocity>(
&mut self,
drivetrain: &'a mut Drivetrain<Differential, T>,
point: impl Into<Vec2<f64>>,
heading: Angle,
lead: f64,
) -> BoomerangFuture<'a, L, A, T> {
BoomerangFuture {
drivetrain,
target_heading: heading,
lead,
target_point: point.into(),
timeout: self.timeout,
tolerances: self.tolerances,
linear_controller: self.linear_controller.clone(),
angular_controller: self.angular_controller.clone(),
state: None,
}
}
}