pub struct Stabilizer<F, M>{
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: FailsafeMonitorImplementations§
Source§impl<F, M> Stabilizer<F, M>
impl<F, M> Stabilizer<F, M>
pub fn new( roll_cfg: PidConfig, pitch_cfg: PidConfig, yaw_cfg: PidConfig, alpha: f32, mixer: M, failsafe_timeout: f32, ) -> Self
Sourcepub fn set_armed(&mut self, state: ArmingState)
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).
Sourcepub fn tick(
&mut self,
roll_input: InertialInput,
pitch_input: InertialInput,
yaw_input: InertialInput,
target: Attitude,
throttle: f32,
dt: f32,
current_time: f32,
) -> M::Output
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
- Failsafe Evaluation: Checks the system health/heartbeat against
current_time. - Command Override: If a failsafe is active, pilot inputs are overridden with emergency values (e.g., leveling out and reducing throttle).
- Arming Interlock: Ensures zero motor output if the aircraft is disarmed.
- Axis Processing: Filters raw IMU data and calculates PID corrections for Roll/Pitch.
- Heading Control: Calculates the shortest-path error for Yaw (circular normalization).
- 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>
impl<F, M> RefUnwindSafe for Stabilizer<F, M>where
M: RefUnwindSafe,
F: RefUnwindSafe,
impl<F, M> Send for Stabilizer<F, M>
impl<F, M> Sync for Stabilizer<F, M>
impl<F, M> Unpin for Stabilizer<F, M>
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> 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