use syunit::*;
#[derive(Debug, Clone, Default)]
pub struct Limits<U : UnitSet> {
pub min : Option<U::Position>,
pub max : Option<U::Position>
}
impl<U : UnitSet> Limits<U> {
const NONE : Self = Self { min: None, max: None };
}
#[derive(Clone, Debug, Default)]
pub struct ActuatorVars<U : UnitSet = Rotary> {
pub force_load_gen : U::Force,
pub force_load_dir : U::Force,
pub inertia_load : U::Inertia,
pub lim : Limits<U>
}
impl<U : UnitSet> ActuatorVars<U> {
pub const ZERO : Self = Self {
force_load_gen: U::Force::ZERO,
force_load_dir: U::Force::ZERO,
inertia_load: U::Inertia::ZERO,
lim: Limits::NONE
};
pub fn force_after_load(&self, force : U::Force, direction : Direction) -> Option<U::Force> {
let mut force = force - self.force_load_gen;
if direction.as_bool() {
force -= self.force_load_dir;
} else {
force += self.force_load_dir;
}
if force > U::Force::ZERO {
Some(force)
} else {
None
}
}
pub fn force_after_load_lower(&self, force : U::Force) -> Option<U::Force> {
let force = force - self.force_load_gen - self.force_load_dir.abs();
if force > U::Force::ZERO {
Some(force)
} else {
None
}
}
#[inline]
pub fn inertia_after_load(&self, inertia : U::Inertia) -> U::Inertia {
inertia + self.inertia_load
}
}