pub struct ComposedVehicle<S, A> { /* private fields */ }Expand description
A Vehicle made of a separate state source and actuator.
state goes to S, actuate to A; Vehicle itself comes from the blanket
impl. Use it when sensing and actuation are different components, which is the normal
case on hardware.
§Examples
use std::time::Duration;
use stable_flight::{
Actuator, ActuatorCommand, ComposedVehicle, StateSource, Vehicle, VehicleState,
};
struct Imu;
impl StateSource for Imu {
fn state(&mut self, _dt: Duration) -> VehicleState {
VehicleState::default()
}
}
struct Escs {
last: ActuatorCommand,
}
impl Actuator for Escs {
fn actuate(&mut self, command: &ActuatorCommand) {
self.last = *command;
}
}
fn fly(vehicle: &mut impl Vehicle) {
let _state = vehicle.state(Duration::from_millis(4));
vehicle.actuate(&ActuatorCommand { motors: [0.5; 8], ..Default::default() });
}
let mut vehicle = ComposedVehicle::new(Imu, Escs { last: ActuatorCommand::default() });
fly(&mut vehicle);
assert_eq!(vehicle.actuator().last.motors[0], 0.5);Implementations§
Source§impl<S, A> ComposedVehicle<S, A>
impl<S, A> ComposedVehicle<S, A>
Trait Implementations§
Source§impl<S, A: Actuator> Actuator for ComposedVehicle<S, A>
impl<S, A: Actuator> Actuator for ComposedVehicle<S, A>
Source§fn actuate(&mut self, actuator_command: &ActuatorCommand)
fn actuate(&mut self, actuator_command: &ActuatorCommand)
Actuates the vehicle’s control surfaces and/or motors based on the command. Read more
Source§impl<S: StateSource, A> StateSource for ComposedVehicle<S, A>
impl<S: StateSource, A> StateSource for ComposedVehicle<S, A>
Auto Trait Implementations§
impl<S, A> Freeze for ComposedVehicle<S, A>
impl<S, A> RefUnwindSafe for ComposedVehicle<S, A>where
S: RefUnwindSafe,
A: RefUnwindSafe,
impl<S, A> Send for ComposedVehicle<S, A>
impl<S, A> Sync for ComposedVehicle<S, A>
impl<S, A> Unpin for ComposedVehicle<S, A>
impl<S, A> UnsafeUnpin for ComposedVehicle<S, A>where
S: UnsafeUnpin,
A: UnsafeUnpin,
impl<S, A> UnwindSafe for ComposedVehicle<S, A>where
S: UnwindSafe,
A: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.