6 #ifndef INCLUDE_IMUNANO33_FILTER_HPP_
7 #define INCLUDE_IMUNANO33_FILTER_HPP_
17 #ifdef IMUNANO33_EMBED
25 #ifdef IMUNANO33_EMBED
69 #ifdef IMUNANO33_EMBED
93 : m_qRot{initialQ.unit()} {
94 #ifdef IMUNANO33_EMBED
143 const Quaternion qGyroDelta{normalize(gyro), time * magn(gyro)};
144 m_qRot *= qGyroDelta;
168 m_qRot * qAccelBody *
172 const Vector3D vecAccelWorldNorm = normalize(qAccelWorld.
vec());
173 const Vector3D vecAccelGravity{0, 0, -1};
175 cross(vecAccelWorldNorm,
180 #ifdef IMUNANO33_EMBED
182 dot(vecAccelGravity, vecAccelWorldNorm) /
183 (magn(vecAccelGravity) * magn(vecAccelWorldNorm)),
187 const num_t rotAngle = std::acos(
189 (magn(vecAccelGravity) * magn(vecAccelWorldNorm)),
200 const Quaternion qAccelCur{normalize(vecRotAxis),
201 (1 - m_gyroFavoring) * rotAngle};
202 m_qRot = qAccelCur * m_qRot;
270 #ifdef IMUNANO33_EMBED
278 num_t m_gyroFavoring;
File containing the imunano33::MathUtil class.
File containing the imunano33::Quaternion class.
A minimized version of vectors for embedded devices without access to the STL (such as on an Arduino,...
Contains imunano33::TempUnit and imunano33::PressureUnit enums, in addition to number type.
double num_t
Alias to number type depending on embed.
Definition: unit.hpp:34
A complementary filter for a 6 axis IMU using quaternions.
Definition: filter.hpp:44
void updateAccel(const Vector3D &accel)
Updates filter with accelerometer data.
Definition: filter.hpp:158
Filter & operator=(Filter &&)=default
Move assignment.
num_t getGyroFavoring() const
Gets gyroscope favoring.
Definition: filter.hpp:249
Filter & operator=(const Filter &other)=default
Assignment operator.
void reset()
Resets quaternion to [1, 0, 0, 0], or facing towards position x direction.
Definition: filter.hpp:235
Filter()
Default Constructor.
Definition: filter.hpp:53
void update(const Vector3D &accel, const Vector3D &gyro, const num_t time)
Updates filter with both gyro and accel data.
Definition: filter.hpp:222
void setGyroFavoring(const num_t favoring)
Sets gyro favoring.
Definition: filter.hpp:269
~Filter()=default
Destructor.
Filter(const num_t gyroFavoring)
Constructor.
Definition: filter.hpp:68
Filter(const Filter &other)=default
Copy constructor.
void updateGyro(const Vector3D &gyro, const num_t time)
Updates filter with gyro data.
Definition: filter.hpp:136
void setRotQ(const Quaternion &q)
Sets rotation quaternion for the filter.
Definition: filter.hpp:259
Filter(Filter &&)=default
Move constructor.
Filter(const num_t gyroFavoring, const Quaternion &initialQ)
Constructor.
Definition: filter.hpp:92
Quaternion getRotQ() const
Gets rotation quaternion of the complementary filter.
Definition: filter.hpp:242
static T clamp(const T &num, const T &lo, const T &hi)
Restricts num between lo and hi.
Definition: mathutil.hpp:141
static bool nearZero(const num_t num)
Determines if number is near zero with given precision.
Definition: mathutil.hpp:48
A simple quaternion class for rotations.
Definition: quaternion.hpp:40
Quaternion unit() const
Gets equivalent unit quaternion.
Definition: quaternion.hpp:161
Quaternion conj() const
Gets the quaternion conjugate.
Definition: quaternion.hpp:124
Vector3D vec() const
Gets the vector component of the quaternion.
Definition: quaternion.hpp:117
A simple 3D vector representation.
Definition: simplevectors.hpp:844
A minimal 3D vector representation.
Definition: sv_embed.hpp:168