Madgwick Filter
The MadgwickFilter implements the Madgwick algorithm for orientation estimation using an IMU. The algorithm is based on the paper `An efficient orientation filter for inertial and inertial/magnetic sensor arrays`_ by Sebastian Madgwick. It supports state / orientation estimation for both 6-axis IMUs as well as for 9-axis IMUs.
API Reference
Header File
Classes
-
class MadgwickFilter
Madgwick filter for IMU data Based on: https://x-io.co.uk/open-source-imu-and-ahrs-algorithms/ (now https://github.com/xioTechnologies/Fusion)
Public Functions
-
inline explicit MadgwickFilter(float beta = 0.1f)
Constructor.
- Parameters
beta – Filter gain
-
inline void update(float dt, float ax, float ay, float az, float gx, float gy, float gz, float mx, float my, float mz)
Update the filter with new data.
Note
Accelerometer values should be normalized
Note
Gyroscope values should be in rad/s
Note
Magnetometer values should be normalized
Note
If magnetometer values are not available (all 0), this function will fallback to using only accelerometer and gyroscope values
- Parameters
dt – Time step in seconds
ax – Accelerometer x value in g
ay – Accelerometer y value in g
az – Accelerometer z value in g
gx – Gyroscope x value in rad/s
gy – Gyroscope y value in rad/s
gz – Gyroscope z value in rad/s
mx – Magnetometer x value in uT
my – Magnetometer y value in uT
mz – Magnetometer z value in uT
-
inline void update(float dt, float ax, float ay, float az, float gx, float gy, float gz)
Update the filter with new data.
Note
Accelerometer values should be normalized
Note
Gyroscope values should be in rad/s
- Parameters
dt – Time step in seconds
ax – Accelerometer x value in g
ay – Accelerometer y value in g
az – Accelerometer z value in g
gx – Gyroscope x value in rad/s
gy – Gyroscope y value in rad/s
gz – Gyroscope z value in rad/s
-
inline void get_euler(float &pitch, float &roll, float &yaw) const
Get the current quaternion values as euler angles.
Note
Euler angles are in degrees
- Parameters
pitch – [out] Pitch angle in degrees
roll – [out] Roll angle in degrees
yaw – [out] Yaw angle in degrees
-
inline explicit MadgwickFilter(float beta = 0.1f)