Skip to main content

ComposedVehicle

Struct ComposedVehicle 

Source
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>

Source

pub fn new(source: S, actuator: A) -> Self

Pairs a state source with an actuator.

Source

pub fn source(&self) -> &S

The state-source half.

Source

pub fn actuator(&self) -> &A

The actuator half.

Source

pub fn into_parts(self) -> (S, A)

Splits back into (source, actuator).

Trait Implementations§

Source§

impl<S, A: Actuator> Actuator for ComposedVehicle<S, A>

Source§

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: Clone, A: Clone> Clone for ComposedVehicle<S, A>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: Debug, A: Debug> Debug for ComposedVehicle<S, A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: Default, A: Default> Default for ComposedVehicle<S, A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<S: StateSource, A> StateSource for ComposedVehicle<S, A>

Source§

fn state(&mut self, dt: Duration) -> VehicleState

Returns the current vehicle state. Read more

Auto Trait Implementations§

§

impl<S, A> Freeze for ComposedVehicle<S, A>
where S: Freeze, A: Freeze,

§

impl<S, A> RefUnwindSafe for ComposedVehicle<S, A>

§

impl<S, A> Send for ComposedVehicle<S, A>
where S: Send, A: Send,

§

impl<S, A> Sync for ComposedVehicle<S, A>
where S: Sync, A: Sync,

§

impl<S, A> Unpin for ComposedVehicle<S, A>
where S: Unpin, A: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Vehicle for T
where T: StateSource + Actuator,