Skip to main content

Crate stable_flight

Crate stable_flight 

Source
Expand description

github crates-io license


Flight-control core for the Stable Flight controller: the pipeline traits (Commander, StateSource + Actuator = Vehicle, Guidance, Stabilizer, Mixer, TelemetryPublisher), the data passed between them, copter guidance, the cascaded-PID stabilizers, the mixers, and FlightLoop, which sequences one control tick.

This crate is no_std and has no simulator, I/O, or timing dependencies, so the same code runs in software-in-the-loop simulation (stable-flight-sitl) and, later, on flight hardware. See the architecture overview.

Re-exports§

pub use view::View;
pub use estimation::wind::WindEstimate;
pub use nalgebra;

Modules§

commanders
Hardware-independent Commander implementations.
composition
Combinators that build one pipeline component out of several.
controllers
Flight Control Controllers
estimation
Estimates built from the vehicle state, beyond what the backend reports: wind.
flight_loop
One control-loop tick, independent of how ticks are scheduled.
guidance
Outer-loop Guidance implementations, which turn commands into the setpoints a Stabilizer tracks, and their building blocks (vtol’s transition state machine).
mixers
Provides functionality to translate generalized control outputs (thrust and moments) into specific actuator commands tailored to the vehicle configuration.
params
A flat name → f32 view over the config tree, for live tuning from a ground station.
stabilizers
Inner-loop control: track a Setpoint from guidance against vehicle state feedback.
testing
Test doubles for the pipeline traits. Enabled by the testing feature (and in this crate’s own tests); off by default.
timing
Fixed-rate scheduling driven by the flight loop’s dt, for streams (telemetry, heartbeats) that run slower than the loop.
tuning
PID autotune: measure a loop, turn the measurement into gains, and run it per loop.
view
View: runs a Guidance or Stabilizer in a body frame rotated by a constant, so a tailsitter hovers nose up on the copter controllers.

Macros§

conformance_tests
Generates a backend’s conformance tests: one #[test] per listed scenario, plus conformance_covers_every_scenario, which fails if any scenario in SCENARIOS has no test.

Structs§

AbsoluteAttitudeCommand
An absolute attitude and collective thrust, for ControlInput::AbsoluteAttitude: what an offboard app (e.g. MAVLink SET_ATTITUDE_TARGET) asks for, as opposed to the normalized stick positions of an AttitudeCommand.
AbsoluteRateCommand
Absolute body rates and collective thrust, for ControlInput::AbsoluteRate: what a maneuver or an offboard app (e.g. MAVLink SET_ATTITUDE_TARGET body rates) asks for, as opposed to the stick fractions of a RateCommand.
ActuatorCommand
One tick’s actuator outputs: motors and servos, as generic slots.
AttitudeCommand
Represents direct manual control of an aircraft’s attitude (orientation).
AttitudeSetpoint
Attitude target for the Stabilizer; see Setpoint.
BlendSetpoint
A hover and a wing-borne target flown together, for Setpoint::Blend: a lift+cruise VTOL (quadplane) in transition, its lift rotors flying hover and its surfaces and pusher flying plane.
BodyRateSetpoint
Absolute body-rate target, for Setpoint::BodyRate (copter) and Setpoint::PlaneRate (plane). The stabilizer saturates each rate to its limit (NaN as zero).
Command
One tick’s command from a Commander: whether the vehicle should be armed, which FlightRegime to fly in, and what to fly.
ComposedVehicle
A Vehicle made of a separate state source and actuator.
ControlOutput
Represents the high-level control outputs from the stabilization system.
CruiseOutput
A lift+cruise VTOL’s cruise output (ControlOutput::cruise): what its pusher and control surfaces fly while the lift rotors fly ControlOutput::thrust and ControlOutput::moments.
FlightLoop
Sequences one control tick: commander → estimate → guide → stabilize → mix → actuate → telemetry.
FlightModeReport
The flight mode guidance is flying, and why it isn’t the requested regime when it can’t be. From Guidance::flight_mode (or copter_only); FlightLoop puts it in TelemetryRecord::flight_mode.
LandCommand
Where to land, for ControlInput::Land: guidance holds position_m while it descends.
PlaneSetpoint
Wing-borne attitude target for a plane stabilizer, for Setpoint::Plane, in the frame contract’s body frame (a tailsitter’s airplane frame). Turns are coordinated, so there is no heading: the stabilizer derives the yaw rate from bank and airspeed. The stabilizer saturates roll and pitch to its limits; NaN means level.
RateCommand
Represents direct manual control of an aircraft’s rotational rates.
RateSetpoint
Body-rate target for the Stabilizer; see Setpoint.
Saturation
Which limits the pipeline hit on one tick, as reported by Guidance::saturation, Stabilizer::saturation, and Mixer::saturation, merged by FlightLoop into TelemetryRecord::saturation.
TelemetryRecord
One control-loop tick, as handed to a TelemetryPublisher.
VehicleState
Represents the physical state of a vehicle in 3D space.
WaypointCommand
Represents a navigational waypoint for autonomous flight.

Enums§

ControlInput
The control input part of a Command: what the flight system should fly.
ControlMode
The kind of a ControlInput, one variant per input variant: the flight mode, compact enough for a heartbeat. From ControlInput::mode.
FailsafeState
Which commander a FailsafeCommander let fly: its link-fed primary, or the fallback after the link went stale.
FlightMode
The regime guidance is actually flying, including the transitions between regimes. Owned by Guidance and reported in a FlightModeReport.
FlightRegime
How the vehicle flies: hovering on its rotors, or wing-borne. Requested by a Command; what is actually flown, including transitions, is a FlightMode.
ModeRefusal
Why guidance isn’t flying, or stopped moving toward, the requested FlightRegime.
Setpoint
What the Stabilizer should hold this tick, as produced by a Guidance.

Constants§

GRAVITY
Standard gravity, in m/s².

Traits§

Actuator
Component responsible for controlling the vehicle’s actuators.
Commander
Represents an entity that produces flight control commands.
Configurable
A pipeline component whose gains and limits can be read and replaced between ticks.
Guidance
Turns the commander’s ControlInput into an inner-loop Setpoint, in the requested FlightRegime.
Mixer
Component responsible for converting control outputs to actuator commands.
Stabilizer
Component responsible for flight control and stabilization: the inner loop.
StateSource
Where the flight loop’s vehicle state comes from.
TelemetryPublisher
Component responsible for publishing telemetry data from the flight system.
Vehicle
Represents a physical vehicle that can be controlled by the flight system.

Functions§

euler_angles
ZYX Euler angles (roll, pitch, yaw) in radians of an attitude quaternion, in the frame contract’s convention (the same as UnitQuaternion::euler_angles). Use this rather than nalgebra’s method to read Euler angles from VehicleState::attitude.
wrap_angle
Wraps an angle in radians to [-π, π); non-finite input gives NaN.

Type Aliases§

Vec2
2D vector used throughout the pipeline (waypoint positions, tilt, controller limits).
Vec3
3D vector used throughout the pipeline (state vectors, moments, rates). Element-wise products are component_mul; * between two vectors is a matrix product.