use crate::kinematics::differential_drive::BodyTwist;
use crate::linear_algebra::{Vector, Vector3D};
use crate::scalar::Numeric;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Unicycle<T: Numeric = f64> {
twist: BodyTwist<T>,
}
impl<T: Numeric> Unicycle<T> {
#[inline]
#[must_use]
pub fn new(twist: BodyTwist<T>) -> Self {
Unicycle { twist }
}
#[inline]
pub fn derivative(self, state: &Vector3D<T>) -> Vector3D<T> {
let v = self.twist.linear();
let theta = state[2];
Vector::new([v * theta.cos(), v * theta.sin(), self.twist.angular()])
}
#[inline]
pub fn field(self) -> impl Fn(T, &Vector3D<T>) -> Vector3D<T> {
move |_t, y| self.derivative(y)
}
}