use crate::loops::ControlLoop;
pub struct DcMotorFeedforward {
ks: f64,
kv: f64,
ka: f64,
target_acceleration: f64,
}
impl DcMotorFeedforward {
pub fn new(ks: f64, kv: f64, ka: f64, target_acceleration: f64) -> Self {
Self {
ks,
kv,
ka,
target_acceleration,
}
}
#[must_use]
pub const fn constants(&self) -> (f64, f64, f64) {
(self.ks, self.kv, self.ka)
}
#[must_use]
pub const fn ks(&self) -> f64 {
self.ks
}
#[must_use]
pub const fn kv(&self) -> f64 {
self.kv
}
#[must_use]
pub const fn ka(&self) -> f64 {
self.ka
}
pub const fn set_constants(&mut self, ks: f64, kv: f64, ka: f64) {
self.ks = ks;
self.kv = kv;
self.ka = ka;
}
pub const fn set_ks(&mut self, ks: f64) {
self.ks = ks;
}
pub const fn set_kv(&mut self, kv: f64) {
self.kv = kv;
}
pub const fn set_ka(&mut self, ka: f64) {
self.ka = ka;
}
}
impl ControlLoop for DcMotorFeedforward {
type Input = f64;
type Output = f64;
fn update(
&mut self,
_measurement: Self::Input,
setpoint: Self::Input,
_dt: core::time::Duration,
) -> Self::Output {
self.ks * setpoint.signum() + self.kv * setpoint + self.ka * self.target_acceleration
}
}