#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use syunit::*;
use syunit::metric::*;
#[derive(Debug, Default, Clone, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ServoConst {
pub t_max : NewtonMeters,
pub velocity_max : RadPerSecond,
pub position_max : PositionRad,
pub pwm_min : Seconds,
pub pwm_max : Seconds,
pub f_pwm : Hertz
}
impl ServoConst {
pub const MG996R : Self = Self {
t_max: NewtonMeters(1.08),
velocity_max: RadPerSecond(8.5),
position_max: PositionRad(core::f32::consts::PI),
pwm_min: Seconds(0.00075),
pwm_max: Seconds(0.00225),
f_pwm: Hertz(50.0)
};
pub fn default_pulse(&self) -> Seconds {
(self.pwm_min + self.pwm_max) / 2.0
}
pub fn default_pos(&self) -> PositionRad {
self.position_max / 2.0
}
pub fn period_time(&self) -> Seconds {
1.0 / self.f_pwm
}
pub fn pulse_for_factor(&self, factor : Factor) -> Seconds {
self.pwm_min + (self.pwm_max - self.pwm_min) * factor
}
pub fn pulse_for_angle(&self, pos : PositionRad) -> Seconds {
self.pulse_for_factor(Factor::new(pos / self.position_max))
}
}