pub trait Vehicle: StateSource + Actuator { }Expand description
Represents a physical vehicle that can be controlled by the flight system.
A Vehicle is anything that is both a StateSource and an Actuator; the blanket
impl below provides it automatically, so implement those two traits rather than this one.
The split mirrors hardware, where sensing (IMU, estimator) and actuation (ESC/servo output)
are usually separate drivers, while a simulator bridge can implement both on one type.
Examples: a simulator bridge such as RealFlightVehicle, a hardware IMU/estimator paired
with an ESC driver (see ComposedVehicle), or a test double such as
testing::NullVehicle (testing feature).
§Timing contract
FlightLoop::step calls StateSource::state once, then
Actuator::actuate once, every tick. A backend must:
- report state in the
VehicleStateframe contract; - talk to its simulator or hardware at most once per call, and should not block for longer than a tick (document it if a blocking link can);
- document how old the state from
stateis relative to the lastactuate. A backend whose link sends controls and returns state in one round-trip exchanges inactuateand returns the cached result, so tick n stabilizes on state reported when the simulator received tick n − 1’s controls. A backend with a separate sensor read should read fresh state instate; - produce real state on the priming call (
dt == Duration::ZERO, made once byFlightLoop::primebefore anyactuate), contacting the simulator if it must, and document what it returns if that fails.
§Examples
use std::time::Duration;
use stable_flight::{Actuator, ActuatorCommand, StateSource, Vehicle, VehicleState};
struct HoverSim {
state: VehicleState,
}
impl StateSource for HoverSim {
fn state(&mut self, _dt: Duration) -> VehicleState {
self.state.clone()
}
}
impl Actuator for HoverSim {
fn actuate(&mut self, _command: &ActuatorCommand) {}
}
fn requires_vehicle(_: &impl Vehicle) {}
requires_vehicle(&HoverSim { state: VehicleState::default() });Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".