pub trait Commander {
// Required method
fn next_command(&mut self, dt: f32, current_state: &VehicleState) -> Command;
// Provided method
fn failsafe(&self) -> Option<FailsafeState> { ... }
}Expand description
Represents an entity that produces flight control commands.
The Commander trait is responsible for producing the next flight control command given the elapsed time (dt) and the current vehicle state (current_state).
This allows for time-dependent and state-dependent command generation, such as ramping values, coordinating timed sequences, or adjusting commands based on the aircraft’s position or velocity.
Implementors of this trait may include:
- User input handlers: Translate joystick/keyboard inputs into manual commands (e.g., ControlInput::Attitude or ControlInput::Rate).
- Navigation systems: Generate waypoint commands (e.g., ControlInput::Waypoint) for autonomous flight to specific locations.
- Mission controllers: Produce commands based on predefined flight plans or mission objectives.
- Formation controllers: Maintain relative positioning between multiple aircraft in a formation.
§Examples
Implementing a simple Commander that always returns a constant Attitude command:
use stable_flight::VehicleState;
use stable_flight::{AttitudeCommand, Command, Commander, ControlInput};
struct ConstantAttitudeCommander;
impl Commander for ConstantAttitudeCommander {
fn next_command(&mut self, dt: f32, current_state: &VehicleState) -> Command {
Command::armed(ControlInput::Attitude(AttitudeCommand {
throttle: 0.5, // 50% throttle
roll: 0.0, // No roll
pitch: 0.0, // No pitch
yaw: 0.0, // No yaw
mode: 0, // Default mode
}))
}
}Required Methods§
Sourcefn 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.
§Parameters
dt: The time elapsed since the last command was generated in seconds. This allows for time-dependent command generation, such as ramping up values gradually or handling timed sequences.current_state: The current state of the vehicle, as aVehicleState. Typically includes information like position, velocity, attitude, and other relevant data, allowing the commander to generate state-dependent commands.
§Returns
A Command: whether the vehicle should be armed, and the ControlInput to fly.
arm is a level, not an event: return the desired state every tick.
Provided Methods§
Sourcefn 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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".