Skip to main content

ControlInput

Enum ControlInput 

Source
#[non_exhaustive]
pub enum ControlInput { Attitude(AttitudeCommand), Rate(RateCommand), Waypoint(WaypointCommand), AbsoluteAttitude(AbsoluteAttitudeCommand), Land(LandCommand), }
Expand description

The control input part of a Command: what the flight system should fly.

The ControlInput enum encapsulates different types of commands that can be issued to control an aircraft. It supports five types of commands, categorized into four control paradigms:

  • Manual - Low-level direct control inputs typically generated from user input devices. This includes:
    • Attitude: Controls the aircraft’s orientation (roll, pitch, yaw).
    • Rate: Controls the aircraft’s rotational rates (rate of change of roll, pitch, yaw).
  • AbsoluteAttitude - An absolute roll, pitch, and heading with collective thrust, from an offboard app (e.g. MAVLink SET_ATTITUDE_TARGET).
  • Waypoint - High-level navigational commands used for autonomous flight.
  • Land - Descend in place until touchdown.

This separation allows the flight control system to handle both manual piloting and automated navigation with a unified command interface.

§Examples

Creating a manual attitude command:

use stable_flight::{ControlInput, AttitudeCommand};

let manual_cmd = ControlInput::Attitude(AttitudeCommand {
    throttle: 0.75,  // 75% throttle
    roll: 0.1,       // Slight right bank
    pitch: -0.05,    // Slight nose down
    yaw: 0.0,        // No yaw input
    ..Default::default()
});

Creating a manual rate command:

use stable_flight::{ControlInput, RateCommand};

let rate_cmd = ControlInput::Rate(RateCommand {
    throttle: 0.5,   // 50% throttle
    roll_rate: 0.2,  // Moderate roll rate
    pitch_rate: 0.1, // Moderate pitch rate
    yaw_rate: 0.0,   // No yaw rate
    ..Default::default()
});

Creating a waypoint command:

use stable_flight::{ControlInput, Vec2, WaypointCommand};

let waypoint_cmd = ControlInput::Waypoint(WaypointCommand {
    position_m: Vec2::new(1000.0, 2000.0),    // Target position in world coordinates
    velocity_mps: Some(Vec2::new(15.0, 0.0)), // Optional velocity to fly through it with
    altitude_m: 500.0,                        // Target altitude in meters
    cruise_speed_mps: 25.0,                   // Speed cap on the way
    roll_rad: Some(0.05),                     // Optional roll angle in radians
});

§Notes

  • For WaypointCommand, optional fields like velocity_mps and roll_rad can be None. When None, the flight controller may use default values or ignore the parameter, depending on its implementation.
  • #[non_exhaustive]: new command kinds (e.g. fixed-wing) can be added without a breaking change. A Guidance that can’t fly a variant must fall back to neutral, not panic (see Guidance::guide).

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Attitude(AttitudeCommand)

Direct manual control inputs for the aircraft’s attitude (orientation).

These values typically range from -1.0 to 1.0 (or 0.0 to 1.0 for throttle) and directly influence the aircraft’s roll, pitch, and yaw orientation. The ranges are conventional and may not be enforced by the system.

§

Rate(RateCommand)

Direct manual control inputs for the aircraft’s rotational rate.

These values typically range from -1.0 to 1.0 (or 0.0 to 1.0 for throttle) and directly influence the rate of change of roll, pitch, and yaw. The ranges are conventional and may not be enforced by the system.

§

Waypoint(WaypointCommand)

Autonomous navigation command specifying a destination point.

This command provides high-level navigational instructions that are translated into appropriate control surface and throttle settings by the flight controller.

§

AbsoluteAttitude(AbsoluteAttitudeCommand)

An absolute attitude in radians and collective thrust, typically from an offboard app.

Unlike ControlInput::Attitude, the angles are not stick positions: roll and pitch are flown as given (the stabilizer saturates them to its maximum tilt), and the heading is an angle, not a rate.

§

Land(LandCommand)

Hold a horizontal position and descend at a steady rate until the ground stops the vehicle. Guidance only descends; deciding it has touched down and disarming is the commander’s job (TouchdownDetector).

Implementations§

Source§

impl ControlInput

Source

pub fn is_sticks(&self) -> bool

Whether this is pilot stick input (attitude or rate). After a link outage, the failsafe hands an armed vehicle back to sticks only once they move, so a stick left deflected can’t take over unattended. Sticks are also a stream.

§Examples
use stable_flight::ControlInput;

assert!(ControlInput::Attitude(Default::default()).is_sticks());
assert!(ControlInput::Rate(Default::default()).is_sticks());
assert!(!ControlInput::AbsoluteAttitude(Default::default()).is_sticks());
assert!(!ControlInput::Waypoint(Default::default()).is_sticks());
assert!(!ControlInput::Land(Default::default()).is_sticks());
Source

pub fn is_stream(&self) -> bool

Whether this input is a stream that must keep arriving to stay valid (sticks and absolute attitudes), unlike a waypoint or a land, which stays valid until replaced. A link-fed commander treats a stream as stale once commands stop, even if other messages arrive.

§Examples
use stable_flight::ControlInput;

assert!(ControlInput::Attitude(Default::default()).is_stream());
assert!(ControlInput::Rate(Default::default()).is_stream());
assert!(ControlInput::AbsoluteAttitude(Default::default()).is_stream());
assert!(!ControlInput::Waypoint(Default::default()).is_stream());
assert!(!ControlInput::Land(Default::default()).is_stream());
Source

pub fn mode(&self) -> ControlMode

Which kind of input this is, without its values: the flight mode a ground station shows.

§Examples
use stable_flight::{ControlInput, ControlMode};

assert_eq!(ControlInput::Attitude(Default::default()).mode(), ControlMode::Attitude);
assert_eq!(ControlInput::Rate(Default::default()).mode(), ControlMode::Rate);
assert_eq!(ControlInput::Waypoint(Default::default()).mode(), ControlMode::Waypoint);
assert_eq!(
    ControlInput::AbsoluteAttitude(Default::default()).mode(),
    ControlMode::AbsoluteAttitude,
);
assert_eq!(ControlInput::Land(Default::default()).mode(), ControlMode::Land);

Trait Implementations§

Source§

impl Clone for ControlInput

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 Copy for ControlInput

Source§

impl Debug for ControlInput

Source§

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

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

impl Default for ControlInput

Zero-throttle, centered-stick ControlInput::Attitude.

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for ControlInput

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ControlInput

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ControlInput

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ControlInput

Auto Trait Implementations§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

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.