M5Unit-IMU 0.0.2 git rev:e5b00aa
Loading...
Searching...
No Matches
m5::imu::ComplementaryFilter Class Reference

Angle-based first-order complementary filter. More...

#include <complementary.hpp>

Inheritance diagram for m5::imu::ComplementaryFilter:
m5::imu::AhrsFilterBase

Public Member Functions

virtual void reset () override
 Reset the internal attitude estimate (and any filter state) to identity.
 
virtual void update (const float dt, const float accel[3], const float gyro[3], const float *mag) override
 Fuse one IMU sample into the attitude estimate.
 
virtual void quaternion (float &w, float &x, float &y, float &z) const override
 Current fused attitude.
 
bool writeAlpha (const float alpha)
 Set the complementary blend factor.
 
float readAlpha () const
 Current complementary blend factor.
 

Detailed Description

Angle-based first-order complementary filter.

Blends the gyro-integrated angle with a reference angle independently for roll, pitch and yaw: angle = alpha * (angle + gyro * dt) + (1 - alpha) * angle_ref. Roll/pitch reference angles come from the accelerometer; the yaw reference comes from a tilt-compensated magnetometer heading when a magnetometer sample is supplied (pure gyro integration otherwise). See filter_base.hpp for the unit and coordinate convention this filter assumes.

Member Function Documentation

◆ quaternion()

void m5::imu::ComplementaryFilter::quaternion ( float & w,
float & x,
float & y,
float & z ) const
overridevirtual

Current fused attitude.

Parameters
[out]wQuaternion scalar part
[out]xQuaternion vector part X
[out]yQuaternion vector part Y
[out]zQuaternion vector part Z

Implements m5::imu::AhrsFilterBase.

◆ reset()

void m5::imu::ComplementaryFilter::reset ( )
overridevirtual

Reset the internal attitude estimate (and any filter state) to identity.

Implements m5::imu::AhrsFilterBase.

◆ update()

void m5::imu::ComplementaryFilter::update ( const float dt,
const float accel[3],
const float gyro[3],
const float * mag )
overridevirtual

Fuse one IMU sample into the attitude estimate.

Parameters
dtTime elapsed since the previous update(), in seconds
accelAccelerometer reading (G), body frame, X/Y/Z
gyroGyroscope reading (dps), body frame, X/Y/Z
magMagnetometer reading (uT), body frame, X/Y/Z; pass nullptr for 6-axis (accel+gyro only) operation

Implements m5::imu::AhrsFilterBase.

◆ writeAlpha()

bool m5::imu::ComplementaryFilter::writeAlpha ( const float alpha)

Set the complementary blend factor.

Parameters
alphaWeight given to the gyro-integrated angle, must be in the open interval (0, 1)
Returns
False (and keeps the previous value) if alpha is out of range