pub struct FailsafeCommander<P, F> { /* private fields */ }Expand description
Flies a link-fed primary while it is fresh, and a fallback otherwise.
- Starts in the fallback: until the primary is heard, nothing it says is trusted.
- Falls back as soon as the primary has gone
timeout_swithout a message, engaging the fallback with the current state and arm state. - Returns once the primary has been fresh for
recover_after_swithout a break and the fallback can release. To an armed vehicle, sticks (an attitude or rate command) take over only once an axis has movedtakeover_stick_deltafrom where it was when the primary recovered, so a joystick left at low throttle can’t drop the vehicle out of a hold; a waypoint, or anything to a disarmed vehicle, takes over at once. - At the handover, the primary’s arm state is synced to the vehicle’s (disarmed if either the vehicle or the primary is), so an arm request made while the fallback flew doesn’t arm the vehicle; a new one does.
- Arming: the fallback may keep the vehicle armed or disarm it, but never arms it (a
HoldCommanderkeeps the arm state it was engaged with), and a fresh primary’s disarm is always honored, even while it waits to take over. - Landing: while an armed land (
ControlInput::Land) flies, from either commander, aTouchdownDetectorwatches it. On touchdown the vehicle disarms and the primary’s arm is synced to it, so it stays disarmed until the primary arms again. A land that carries on across a handover (aHoldCommanderfinishes the primary’s land when the link drops, #263) keeps its detector; anything else (a hold, a disarm, another input) starts it over, so a hold that follows a descent can’t read as touchdown.
The primary runs every tick, flying or not, so it keeps draining its link and timing its
freshness. failsafe reports which commander flew.
§Examples
use stable_flight::commanders::{
FailsafeCommander, FailsafeConfig, HoldCommander, LinkedCommander,
};
use stable_flight::{Command, Commander, FailsafeState, VehicleState};
/// A link that was last heard `since_s` ago.
struct Link {
since_s: Option<f32>,
}
impl Commander for Link {
fn next_command(&mut self, _dt: f32, _state: &VehicleState) -> Command {
Command::default()
}
}
impl LinkedCommander for Link {
fn since_update_s(&self) -> Option<f32> {
self.since_s
}
fn sync_arm(&mut self, _armed: bool) {}
}
let link = Link { since_s: None };
let mut commander =
FailsafeCommander::new(link, HoldCommander::default(), FailsafeConfig::default())?;
commander.next_command(0.004, &VehicleState::default());
assert_eq!(commander.failsafe(), Some(FailsafeState::Fallback)); // never heardImplementations§
Source§impl<P: LinkedCommander, F: Fallback> FailsafeCommander<P, F>
impl<P: LinkedCommander, F: Fallback> FailsafeCommander<P, F>
Sourcepub fn new(
primary: P,
fallback: F,
config: FailsafeConfig,
) -> Result<Self, InvalidConfig>
pub fn new( primary: P, fallback: F, config: FailsafeConfig, ) -> Result<Self, InvalidConfig>
Flies primary, falling back to fallback per config.
§Errors
InvalidConfig if config fails FailsafeConfig::validate.
Trait Implementations§
Source§impl<P: LinkedCommander, F: Fallback> Commander for FailsafeCommander<P, F>
impl<P: LinkedCommander, F: Fallback> Commander for FailsafeCommander<P, F>
Source§fn next_command(&mut self, dt: f32, current_state: &VehicleState) -> Command
fn next_command(&mut self, dt: f32, current_state: &VehicleState) -> Command
Produces the next command to be executed by the flight control system. Read more
Source§fn failsafe(&self) -> Option<FailsafeState>
fn failsafe(&self) -> Option<FailsafeState>
Which commander a failsafe let fly on the last
next_command
call, for a commander that has one
(FailsafeCommander). FlightLoop puts it in
the tick’s TelemetryRecord::failsafe. The default reports none, so a commander that
wraps another must forward this to report the inner one’s.Auto Trait Implementations§
impl<P, F> Freeze for FailsafeCommander<P, F>
impl<P, F> RefUnwindSafe for FailsafeCommander<P, F>where
P: RefUnwindSafe,
F: RefUnwindSafe,
impl<P, F> Send for FailsafeCommander<P, F>
impl<P, F> Sync for FailsafeCommander<P, F>
impl<P, F> Unpin for FailsafeCommander<P, F>
impl<P, F> UnsafeUnpin for FailsafeCommander<P, F>where
P: UnsafeUnpin,
F: UnsafeUnpin,
impl<P, F> UnwindSafe for FailsafeCommander<P, F>where
P: UnwindSafe,
F: 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<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.