Skip to main content

ComplementaryFilter

Struct ComplementaryFilter 

Source
pub struct ComplementaryFilter { /* private fields */ }
Expand description

A first-order Complementary Filter for attitude estimation.

The internal state represents the filtered angle, blending integrated angular rates with an absolute reference.

Implementations§

Source§

impl ComplementaryFilter

Source

pub fn new(alpha: f32) -> Self

Alpha is the trust coefficient for the gyroscope measurement. A value of 1.0 means we trust the gyro completely, while 0.0 means we trust the accelerometer completely. Typically set to 0.98 for flight controllers.

Source

pub fn set_alpha(&mut self, alpha: f32)

Dynamically updates the trust coefficient.

Useful for adaptive filtering where trust in the accelerometer might decrease during high-G maneuvers.

Trait Implementations§

Source§

impl Filter for ComplementaryFilter

Source§

fn update(&mut self, input: Self::Input, dt: f32) -> Self::Output

Processes a new sensor sample to update the attitude estimate.

This method implements the discrete-time fusion equation: θ = α * (θ + ω * dt) + (1 - α) * a

§Mathematical Steps
  1. Prediction: Integrate the angular rate (gyro) into the current state.
  2. Correction: Apply the reference angle (accel) to cancel integration drift.
Source§

fn reset(&mut self)

Resets the filter’s internal state to zero.

Should be called during the ‘Disarm’ phase to ensure the next takeoff sequence starts from a clean level-reference.

Source§

type Input = InertialInput

The raw sensor data or multi-sensor packet to be processed.
Source§

type Output = Radians

The filtered estimate, usually a physical unit like Radians.
Source§

fn new(alpha: f32) -> Self

Factory method to initialize a filter with a smoothing or trust coefficient. Read more

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> 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.