#![doc = include_str!("../README.md")]
#![crate_name = "syact"]
#![no_std]
#![deny(missing_docs)]
extern crate alloc;
use alloc::boxed::Box;
use syunit::*;
mod asyn;
pub use asyn::AsyncActuator;
pub mod comps;
pub mod data;
pub mod meas;
pub mod parent;
pub use parent::{ActuatorParent, RatioActuatorParent};
pub mod sync;
pub use sync::{SyncActuator, SyncActuatorState, SyncActuatorBlocking, SyncActuatorNB};
pub mod prelude;
pub use syunit as units;
#[cfg(any(feature = "testing", test))]
mod tests;
#[cfg(any(feature = "testing", test))]
pub use tests::*;
use crate::data::ActuatorVars;
#[macro_export]
macro_rules! merge_actuator_traits {
($name:ident, $trait1:ident, $trait2:ident) => {
pub trait $name : $trait1 + $trait2 { }
impl<T : $trait1 + $trait2> $name for T { }
};
($name:ident, $trait1:ident, $trait2:ident, $trait3:ident) => {
pub trait $name : $trait1 + $trait2 + $trait3 { }
impl<T : $trait1 + $trait2 + $trait3> $name for T { }
};
($name:ident, $trait1:ident, $trait2:ident, $trait3:ident, $trait4:ident) => {
pub trait $name : $trait1 + $trait2 + $trait3 + $trait4 { }
impl<T : $trait1 + $trait2 + $trait3 + $trait4> $name for T { }
};
}
pub trait Interruptor<U : UnitSet = Rotary> {
fn dir(&self) -> Option<Direction>;
fn set_temp_dir(&mut self, dir_opt : Option<Direction>);
fn check(&mut self, pos : U::Position) -> Option<InterruptReason>;
}
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy)]
pub enum InterruptReason {
EndReached,
Overload,
Error
}
pub trait Interruptible<U : UnitSet = Rotary> {
fn add_interruptor(&mut self, interruptor : Box<dyn Interruptor<U> + Send>);
fn add_interruptor_inline(mut self, interruptor : Box<dyn Interruptor<U> + Send>) -> Self
where
Self : Sized
{
self.add_interruptor(interruptor);
self
}
fn intr_reason(&mut self) -> Option<InterruptReason>;
}
#[derive(Clone, Debug)]
pub enum ActuatorError<U : UnitSet = Rotary> {
InvaldRelativeDistance(U::Distance),
InvalidVelocity(U::Velocity),
VelocityTooHigh(U::Velocity, U::Velocity),
InvalidAcceleration(U::Acceleration),
InvalidJolt(U::Jolt),
InvalidTime(U::Time),
IOError,
Overload
}
impl<U : UnitSet> core::fmt::Display for ActuatorError<U> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_fmt(format_args!("ActuatorError: {:?}", self))
}
}
pub trait AdvancedActuator<U : UnitSet = Rotary> {
fn force_gen(&self) -> U::Force;
fn force_dir(&self) -> U::Force;
fn apply_gen_force(&mut self, force : U::Force) -> Result<(), ActuatorError<U>>;
fn apply_dir_force(&mut self, force : U::Force) -> Result<(), ActuatorError<U>>;
fn inertia(&self) -> U::Inertia;
fn apply_inertia(&mut self, inertia : U::Inertia) -> Result<(), ActuatorError<U>> ;
}
pub trait DefinedActuator<U : UnitSet = Rotary> {
fn ptp_time_for_distance(&self, abs_pos_0 : U::Position, abs_pos_t : U::Position) -> U::Time;
}