imunano33  0.1.1
imunano33::IMUNano33 Class Reference

A data processor for IMU and climate data from an Arduino Nano 33 BLE Sense. More...

#include <imunano33.hpp>

Public Member Functions

 IMUNano33 ()=default
 Default constructor. More...
 
 IMUNano33 (const num_t gyroFavoring)
 Constructor. More...
 
 IMUNano33 (const num_t gyroFavoring, const Quaternion &initialQ)
 Constructor. More...
 
 IMUNano33 (const IMUNano33 &other)=default
 Copy constructor.
 
IMUNano33operator= (const IMUNano33 &other)=default
 Assignment operator.
 
 ~IMUNano33 ()=default
 Destructor.
 
 IMUNano33 (IMUNano33 &&)=default
 Move constructor.
 
IMUNano33operator= (IMUNano33 &&)=default
 Move assignment.
 
void updateClimate (const num_t temperature, const num_t humidity, const num_t pressure)
 Updates climate data. More...
 
void updateIMU (const Vector3D &accel, const Vector3D &gyro, const num_t deltaT)
 Updates IMU data. More...
 
void updateIMUAccel (const Vector3D &accel)
 Updates IMU acceleration data. More...
 
void updateIMUGyro (const Vector3D &gyro, const num_t deltaT)
 Updates IMU gyroscope data. More...
 
void update (const Vector3D &accel, const Vector3D &gyro, const num_t deltaT, const num_t temperature, const num_t humidity, const num_t pressure)
 Updates both IMU and climate data. More...
 
void resetIMU ()
 Resets IMU orientation to the initialQ argument provided in the constructor. More...
 
void zeroIMU ()
 Sets current IMU orientation to be facing the positive X-axis.. More...
 
void resetClimate ()
 Resets climate data. More...
 
void setRotQ (const Quaternion &q)
 Sets rotation quaternion for the filter. More...
 
void setGyroFavoring (const num_t favoring)
 Sets gyro favoring. More...
 
Quaternion getRotQ () const
 Gets rotation quaternion of the complementary filter. More...
 
num_t getGyroFavoring () const
 Gets gyroscope favoring. More...
 
template<TempUnit U>
num_t getTemperature () const
 Gets temperature. More...
 
template<PressureUnit U>
num_t getPressure () const
 Gets pressure. More...
 
num_t getHumidity () const
 Gets relative humidity. More...
 
bool climateDataExists () const
 Determines if climate data exists. More...
 

Detailed Description

A data processor for IMU and climate data from an Arduino Nano 33 BLE Sense.

This processor includes a 6-axis complementary filter which can determine the orientation of the Arduino from its built-in IMU, the LSM9DS1, and the 3-axis acceleration and 3-axis angular velocity measurements. The reason why the magnetometer is not used is due to unknown magnetic interference which could affect sensor measurements, which means that the yaw measurement will inevitably drift over time. Note that the filter assumes that the gyro and accelerometer are calibrated.

The xyz axes are defined as following for the Nano 33 BLE sense (or any Arduino Nano): With the Arduino flat on a table and the sensors facing up and the opening of the Micro USB port facing towards the front, the positive x direction points towards the front, the positive y direction points perpendicular and to the left, and the positive z direction points directly up. Note that the Arduino may not measure the angular velocities and accelerations with respect to these axes, so you may need to correct the measured values.

The processor also takes in climate (temperature, humidity, and pressure) from the HTS221 (for temperature and humidity) and the LPS22HB sensors (for the pressure). These values should be measured in celsius (for temperature), kilopascals (for pressure), and percent relative humidity. The temperature and pressure units can later be converted to other units (see imunano33::TempUnit and imunano33::PressureUnit for supported units).

This can also be used outside the context of a Nano 33 BLE Sense (such as with an external MPU-6050 IMU or a DHT22 temperature and humidity sensor). If certain values are unknown, you can substitute zerores for these values, or not call the corresponding update() method. For example, if you do not want to have an accelerometer ccorrect gyro measurements, pass a zero vector for the accelerometer measurement so that there will be no correction. If you do not know climate data, do not call updateClimate() and only call updateIMU().

Constructor & Destructor Documentation

◆ IMUNano33() [1/3]

imunano33::IMUNano33::IMUNano33 ( )
default

Default constructor.

Sets filter gyro favoring to 0.98 and initial orientation to be pointing in the positive x-direction.

◆ IMUNano33() [2/3]

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

Constructor.

Sets initial orientation to be pointing in the positive x-direction.

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.

◆ IMUNano33() [3/3]

imunano33::IMUNano33::IMUNano33 ( 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. When resetIMU() is called, the orientation quaternion will be set to this value.
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

◆ climateDataExists()

bool imunano33::IMUNano33::climateDataExists ( ) const
inline

Determines if climate data exists.

This only returns false if the object is initialized but none of update() or updateClimate() have not been called yet.

Returns
If data exists.

◆ getGyroFavoring()

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

Gets gyroscope favoring.

Returns
gyro favoring

◆ getHumidity()

num_t imunano33::IMUNano33::getHumidity ( ) const
inline

Gets relative humidity.

Check that this humidity measurement is valid with climateDataExists() first.

Unit is percent humidity.

Returns
Relative humidity

◆ getPressure()

template<PressureUnit U>
num_t imunano33::IMUNano33::getPressure ( ) const
inline

Gets pressure.

Check that this pressure measurement is valid with climateDataExists() first.

Template Parameters
UPressure unit.
Returns
Pressure in given unit.

◆ getRotQ()

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

Gets rotation quaternion of the complementary filter.

Returns
rotation quaternion

◆ getTemperature()

template<TempUnit U>
num_t imunano33::IMUNano33::getTemperature ( ) const
inline

Gets temperature.

Check that this temperature measurement is valid with climateDataExists() first.

Template Parameters
UTemperature unit.
Returns
Temperature in given unit.

◆ resetClimate()

void imunano33::IMUNano33::resetClimate ( )
inline

Resets climate data.

climateDataExists() will be false after this is called.

◆ resetIMU()

void imunano33::IMUNano33::resetIMU ( )
inline

Resets IMU orientation to the initialQ argument provided in the constructor.

All measurements from this point on will be in the frame of reference of the initial quaternion.

◆ setGyroFavoring()

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

Sets gyro favoring.

Parameters
favoringDetermines 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 favoring is less than 0 or greater than 1, it will be clamped to 0 or 1.

◆ setRotQ()

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

Sets rotation quaternion for the filter.

All measurements from this point on will be relative to this quaternion.

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::IMUNano33::update ( const Vector3D accel,
const Vector3D gyro,
const num_t  deltaT,
const num_t  temperature,
const num_t  humidity,
const num_t  pressure 
)
inline

Updates both IMU and climate data.

It is important that the gyroscope is given in radians per second, or the orientation data will be inaccurate. The accelerometer measurement can be in any unit, but m / s^2 is preferred as it is SI.

It is important that you retrieve the data in the units listed below, or the units will not be accurate.

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 (<roll, pitch, yaw> in rad/s)
deltaTThe time between this measurement and the previous measurement, in seconds. If this is the first measurement, deltaT would refer to the time since startup (when initialQ was measured).
temperatureTemperature, in C
humidityRelative humidity, in percent
pressurePressure, in kPa

◆ updateClimate()

void imunano33::IMUNano33::updateClimate ( const num_t  temperature,
const num_t  humidity,
const num_t  pressure 
)
inline

Updates climate data.

It is important that you retrieve the data in the units listed below, or the units will not be accurate.

Parameters
temperatureTemperature, in C
humidityRelative humidity, in percent
pressurePressure, in kPa

◆ updateIMU()

void imunano33::IMUNano33::updateIMU ( const Vector3D accel,
const Vector3D gyro,
const num_t  deltaT 
)
inline

Updates IMU data.

It is important that the gyroscope is given in radians per second, or the orientation data will be inaccurate. The accelerometer measurement can be in any unit, but m / s^2 is preferred as it is SI.

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 (<roll, pitch, yaw> in rad/s)
deltaTThe time between this measurement and the previous measurement, in seconds. If this is the first measurement, deltaT would refer to the time since startup (when initialQ was measured).

◆ updateIMUAccel()

void imunano33::IMUNano33::updateIMUAccel ( const Vector3D accel)
inline

Updates IMU acceleration 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.

◆ updateIMUGyro()

void imunano33::IMUNano33::updateIMUGyro ( const Vector3D gyro,
const num_t  deltaT 
)
inline

Updates IMU gyroscope data.

It is important that the gyroscope is given in radians per second, or the orientation data will be inaccurate. The accelerometer measurement can be in any unit, but m / s^2 is preferred as it is SI.

Parameters
gyroGyroscope reading (<roll, pitch, yaw> in rad/s)
deltaTThe time between this measurement and the previous measurement, in seconds. If this is the first measurement, deltaT would refer to the time since startup (when initialQ was measured).

◆ zeroIMU()

void imunano33::IMUNano33::zeroIMU ( )
inline

Sets current IMU orientation to be facing the positive X-axis..

All measurements from this point on will be relative to where you set the orientation to be the positive X-axis.


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