A complementary filter for a 6 axis IMU using quaternions.
More...
#include <filter.hpp>
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:
◆ 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
-
gyroFavoring | Determines 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
-
gyroFavoring | Determines 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. |
initialQ | The 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.
◆ getGyroFavoring()
num_t imunano33::Filter::getGyroFavoring |
( |
| ) |
const |
|
inline |
Gets gyroscope favoring.
- Returns
- gyro favoring
◆ getRotQ()
Gets rotation quaternion of the complementary filter.
- Returns
- rotation quaternion
◆ setGyroFavoring()
void imunano33::Filter::setGyroFavoring |
( |
const num_t |
favoring | ) |
|
|
inline |
Sets gyro favoring.
- Parameters
-
favoring | The 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
-
- 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()
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
-
accel | Accelerometer 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. |
gyro | Gyroscope reading (in rad/s) |
time | The 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
-
accel | Accelerometer 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
-
gyro | Gyroscope reading (in rad/s) |
time | The 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:
- /home/runner/work/imunano33/imunano33/include/imunano33/filter.hpp