Skip to main content

Stabilizer

Struct Stabilizer 

Source
pub struct Stabilizer<F, M>
where F: Filter<Input = InertialInput, Output = Radians>, M: Mixer,
{ pub attitude_controller: AttitudeController<F>, pub arming_state: ArmingState, pub mixer: M, pub failsafe_monitor: FailsafeMonitor, }
Expand description

The top-level interface for the flight control system.

The Stabilizer manages state estimation and PID calculation for all axes, eventually producing motor signals for the mixer.

Fields§

§attitude_controller: AttitudeController<F>§arming_state: ArmingState§mixer: M§failsafe_monitor: FailsafeMonitor

Implementations§

Source§

impl<F, M> Stabilizer<F, M>
where F: Filter<Input = InertialInput, Output = Radians>, M: Mixer,

Source

pub fn new( roll_cfg: PidConfig, pitch_cfg: PidConfig, yaw_cfg: PidConfig, alpha: f32, mixer: M, failsafe_timeout: f32, ) -> Self

Source

pub fn set_armed(&mut self, state: ArmingState)

Transitions the flight state and handles critical hardware resets.

When disarming, all PID integrals and filters are cleared to prevent “jump-on-arm” behavior caused by stale data accumulation (I-term windup).

Source

pub fn tick( &mut self, roll_input: InertialInput, pitch_input: InertialInput, yaw_input: InertialInput, target: Attitude, throttle: f32, dt: f32, current_time: f32, ) -> M::Output

Executes a single iteration of the flight control loop.

This is the “Heartbeat” of the aircraft, typically running at 400Hz to 1kHz. It coordinates safety checks, sensor fusion, and actuator mixing.

§Logic Flow
  1. Failsafe Evaluation: Checks the system health/heartbeat against current_time.
  2. Command Override: If a failsafe is active, pilot inputs are overridden with emergency values (e.g., leveling out and reducing throttle).
  3. Arming Interlock: Ensures zero motor output if the aircraft is disarmed.
  4. Axis Processing: Filters raw IMU data and calculates PID corrections for Roll/Pitch.
  5. Heading Control: Calculates the shortest-path error for Yaw (circular normalization).
  6. Actuator Mixing: Maps 3-axis demands and throttle into airframe-specific motor signals.
§Returns

Returns M::Output, which for a Quadcopter is QuadMotorSignals.

Auto Trait Implementations§

§

impl<F, M> Freeze for Stabilizer<F, M>
where M: Freeze, F: Freeze,

§

impl<F, M> RefUnwindSafe for Stabilizer<F, M>

§

impl<F, M> Send for Stabilizer<F, M>
where M: Send, F: Send,

§

impl<F, M> Sync for Stabilizer<F, M>
where M: Sync, F: Sync,

§

impl<F, M> Unpin for Stabilizer<F, M>
where M: Unpin, F: Unpin,

§

impl<F, M> UnsafeUnpin for Stabilizer<F, M>
where M: UnsafeUnpin, F: UnsafeUnpin,

§

impl<F, M> UnwindSafe for Stabilizer<F, M>
where M: UnwindSafe, F: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.