imunano33  0.1.1
imunano33::Filter Class Reference

A complementary filter for a 6 axis IMU using quaternions. More...

#include <filter.hpp>

Public Member Functions

 Filter ()
 Default Constructor. More...
 
 Filter (const num_t gyroFavoring)
 Constructor. More...
 
 Filter (const num_t gyroFavoring, const Quaternion &initialQ)
 Constructor. More...
 
 Filter (const Filter &other)=default
 Copy constructor.
 
Filteroperator= (const Filter &other)=default
 Assignment operator.
 
 ~Filter ()=default
 Destructor.
 
 Filter (Filter &&)=default
 Move constructor.
 
Filteroperator= (Filter &&)=default
 Move assignment.
 
void updateGyro (const Vector3D &gyro, const num_t time)
 Updates filter with gyro data. More...
 
void updateAccel (const Vector3D &accel)
 Updates filter with accelerometer data. More...
 
void update (const Vector3D &accel, const Vector3D &gyro, const num_t time)
 Updates filter with both gyro and accel data. More...
 
void reset ()
 Resets quaternion to [1, 0, 0, 0], or facing towards position x direction.
 
Quaternion getRotQ () const
 Gets rotation quaternion of the complementary filter. More...
 
num_t getGyroFavoring () const
 Gets gyroscope favoring. More...
 
void setRotQ (const Quaternion &q)
 Sets rotation quaternion for the filter. More...
 
void setGyroFavoring (const num_t favoring)
 Sets gyro favoring. More...
 

Detailed Description

A complementary filter for a 6 axis IMU using quaternions.

Integrates the gyro measurements, then uses a small fraction of the gravity measurements (from the accelerometer) to correct the orientation given from the gyro measurements. The fraction is specified through the gyroFavoring parameter in the constructor.

The math and details are based on these lectures from Stanford:

Constructor & Destructor Documentation

◆ Filter() [1/3]

imunano33::Filter::Filter ( )
inline

Default Constructor.

Initializes intiial quaternion to [1, 0, 0, 0] (or facing towards +x direction) and gyro favoring to 0.98. See other constructors for more information about gyro favoring.

◆ Filter() [2/3]

imunano33::Filter::Filter ( const num_t  gyroFavoring)
inline

Constructor.

Parameters
gyroFavoringDetermines how much gravity should correct, in the range [0, 1]. 0 means that gravity should fully correct the error (does not mean that orientation is solely determined by gravity), and 1 means that gravity does not correct error at all.
Note
If gyroFavoring is less than 0 or greater than 1, it gets clamped to 0 or 1.
If favoring is too high (> 0.99), then there might be latency in gravity correction.

◆ Filter() [3/3]

imunano33::Filter::Filter ( const num_t  gyroFavoring,
const Quaternion initialQ 
)
inline

Constructor.

Parameters
gyroFavoringDetermines how much gravity should correct, in the range [0, 1]. 0 means that gravity should fully correct the error (does not mean that orientation is solely determined by gravity), and 1 means that gravity does not correct error at all.
initialQThe initial rotation quaternion.
Note
If gyroFavoring is less than 0 or greater than 1, it gets clamped to 0 or 1.
If initialQ is unnormalized, then the method will normalize it. If initialQ is set to be zeroes, this will result in undefined behavior.
If favoring is too high (> 0.99), then there might be latency in gravity correction.

Member Function Documentation

◆ getGyroFavoring()

num_t imunano33::Filter::getGyroFavoring ( ) const
inline

Gets gyroscope favoring.

Returns
gyro favoring

◆ getRotQ()

Quaternion imunano33::Filter::getRotQ ( ) const
inline

Gets rotation quaternion of the complementary filter.

Returns
rotation quaternion

◆ setGyroFavoring()

void imunano33::Filter::setGyroFavoring ( const num_t  favoring)
inline

Sets gyro favoring.

Parameters
favoringThe new gyro favoring, in the range [0, 1]
Note
If favoring is less than 0 or greater than 1, it will be clamped to 0 or 1.

◆ setRotQ()

void imunano33::Filter::setRotQ ( const Quaternion q)
inline

Sets rotation quaternion for the filter.

Parameters
qThe rotation quaternion
Note
If q is unnormalized, then this method will normalize it. If q is set to be zeros, this will result in undefined behavior.

◆ update()

void imunano33::Filter::update ( const Vector3D accel,
const Vector3D gyro,
const num_t  time 
)
inline

Updates filter with both gyro and accel data.

If you plan on only using the gyroscope measurements, then pass in a zero vector for the acceleration, as accelerometer corrections will not be performed if the acceleration vector is zero.

Parameters
accelAccelerometer reading, in <x, y, z>, where positive z is up (important for gravity corrections), and xy is translational motion. The note comes with more details specific to the Arduino Nano 33.
gyroGyroscope reading (in rad/s)
timeThe time it took for the reading to happen (in s)
Note
With the opening of the USB port facing front and the Arduino's sensors facing up, the positive x axis is to the front, the positive y axis is to the left, and the positive z axis is to the top.

◆ updateAccel()

void imunano33::Filter::updateAccel ( const Vector3D accel)
inline

Updates filter with accelerometer data.

Parameters
accelAccelerometer reading, in <x, y, z>, where positive z is up (important for gravity corrections), and xy is translational motion. The note comes with more details specific to the Arduino Nano 33.
Note
With the opening of the USB port facing front and the Arduino's sensors facing up, the positive x axis is to the front, the positive y axis is to the left, and the positive z axis is to the top.

◆ updateGyro()

void imunano33::Filter::updateGyro ( const Vector3D gyro,
const num_t  time 
)
inline

Updates filter with gyro data.

Parameters
gyroGyroscope reading (in rad/s)
timeThe time it took for the reading to happen (in s)
Note
With the opening of the USB port facing front and the Arduino's sensors facing up, the positive x axis is to the front, the positive y axis is to the left, and the positive z axis is to the top.

The documentation for this class was generated from the following file: