imunano33  0.1.1
imunano33.hpp
Go to the documentation of this file.
1 
30 #ifndef INCLUDE_IMUNANO33_IMUNANO33_HPP_
31 #define INCLUDE_IMUNANO33_IMUNANO33_HPP_
32 
33 #include "imunano33/climate.hpp"
34 #include "imunano33/filter.hpp"
35 #include "imunano33/quaternion.hpp"
36 #ifdef IMUNANO33_EMBED
37 #include "imunano33/sv_embed.hpp"
38 #else
40 #endif
41 #include "imunano33/unit.hpp"
42 
43 namespace imunano33 {
44 #ifdef IMUNANO33_EMBED
45 using Vector3D =
47 #else
48 using svector::Vector3D;
49 #endif
50 
87 class IMUNano33 {
88 public:
95  IMUNano33() = default;
96 
112  IMUNano33(const num_t gyroFavoring) : m_filter{gyroFavoring} {}
113 
131  IMUNano33(const num_t gyroFavoring, const Quaternion &initialQ)
132  : m_initialQ{initialQ}, m_filter{gyroFavoring, initialQ} {}
133 
137  IMUNano33(const IMUNano33 &other) = default;
138 
142  IMUNano33 &operator=(const IMUNano33 &other) = default;
143 
147  ~IMUNano33() = default;
148 
152  IMUNano33(IMUNano33 &&) = default;
153 
157  IMUNano33 &operator=(IMUNano33 &&) = default;
158 
169  void updateClimate(const num_t temperature, const num_t humidity,
170  const num_t pressure) {
171  m_climate.update(temperature, humidity, pressure);
172  }
173 
189  void updateIMU(const Vector3D &accel, const Vector3D &gyro,
190  const num_t deltaT) {
191  m_filter.update(accel, gyro, deltaT);
192  }
193 
201  void updateIMUAccel(const Vector3D &accel) { m_filter.updateAccel(accel); }
202 
215  void updateIMUGyro(const Vector3D &gyro, const num_t deltaT) {
216  m_filter.updateGyro(gyro, deltaT);
217  }
218 
240  void update(const Vector3D &accel, const Vector3D &gyro, const num_t deltaT,
241  const num_t temperature, const num_t humidity,
242  const num_t pressure) {
243  updateIMU(accel, gyro, deltaT);
244  updateClimate(temperature, humidity, pressure);
245  }
246 
254  void resetIMU() { m_filter.setRotQ(m_initialQ); }
255 
262  void zeroIMU() { m_filter.reset(); }
263 
269  void resetClimate() { m_climate.reset(); }
270 
281  void setRotQ(const Quaternion &q) { m_filter.setRotQ(q); }
282 
294  void setGyroFavoring(const num_t favoring) {
295  m_filter.setGyroFavoring(favoring);
296  }
297 
303  Quaternion getRotQ() const { return m_filter.getRotQ(); }
304 
310  num_t getGyroFavoring() const { return m_filter.getGyroFavoring(); }
311 
322  template <TempUnit U> num_t getTemperature() const {
323  return m_climate.getTemp<U>();
324  }
325 
336  template <PressureUnit U> num_t getPressure() const {
337  return m_climate.getPressure<U>();
338  }
339 
350  num_t getHumidity() const { return m_climate.getHumidity(); }
351 
360  bool climateDataExists() const { return m_climate.dataExists(); }
361 
362 private:
363  Quaternion m_initialQ;
364  Filter m_filter;
365  Climate m_climate;
366 };
367 } // namespace imunano33
368 #endif
File containing the imunano33::Climate class.
File containing the imunano33::Filter 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
Handles climate data from Nano 33 (or other) sensors.
Definition: climate.hpp:25
bool dataExists() const
Determines if climate data exists.
Definition: climate.hpp:67
num_t getPressure() const
Gets pressure.
Definition: climate.hpp:115
num_t getTemp() const
Gets temperature.
Definition: climate.hpp:78
void update(const num_t temp, const num_t humid, const num_t pressure)
Updates climate data.
Definition: climate.hpp:166
num_t getHumidity() const
Gets relative humidity.
Definition: climate.hpp:157
void reset()
Resets climate data.
Definition: climate.hpp:178
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
num_t getGyroFavoring() const
Gets gyroscope favoring.
Definition: filter.hpp:249
void reset()
Resets quaternion to [1, 0, 0, 0], or facing towards position x direction.
Definition: filter.hpp:235
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
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
Quaternion getRotQ() const
Gets rotation quaternion of the complementary filter.
Definition: filter.hpp:242
A data processor for IMU and climate data from an Arduino Nano 33 BLE Sense.
Definition: imunano33.hpp:87
IMUNano33 & operator=(IMUNano33 &&)=default
Move assignment.
void zeroIMU()
Sets current IMU orientation to be facing the positive X-axis..
Definition: imunano33.hpp:262
bool climateDataExists() const
Determines if climate data exists.
Definition: imunano33.hpp:360
void updateIMUGyro(const Vector3D &gyro, const num_t deltaT)
Updates IMU gyroscope data.
Definition: imunano33.hpp:215
void updateIMUAccel(const Vector3D &accel)
Updates IMU acceleration data.
Definition: imunano33.hpp:201
num_t getTemperature() const
Gets temperature.
Definition: imunano33.hpp:322
num_t getHumidity() const
Gets relative humidity.
Definition: imunano33.hpp:350
void resetClimate()
Resets climate data.
Definition: imunano33.hpp:269
void updateClimate(const num_t temperature, const num_t humidity, const num_t pressure)
Updates climate data.
Definition: imunano33.hpp:169
IMUNano33(IMUNano33 &&)=default
Move constructor.
IMUNano33(const num_t gyroFavoring)
Constructor.
Definition: imunano33.hpp:112
Quaternion getRotQ() const
Gets rotation quaternion of the complementary filter.
Definition: imunano33.hpp:303
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.
Definition: imunano33.hpp:240
~IMUNano33()=default
Destructor.
void resetIMU()
Resets IMU orientation to the initialQ argument provided in the constructor.
Definition: imunano33.hpp:254
num_t getGyroFavoring() const
Gets gyroscope favoring.
Definition: imunano33.hpp:310
IMUNano33(const IMUNano33 &other)=default
Copy constructor.
void setGyroFavoring(const num_t favoring)
Sets gyro favoring.
Definition: imunano33.hpp:294
IMUNano33 & operator=(const IMUNano33 &other)=default
Assignment operator.
IMUNano33()=default
Default constructor.
IMUNano33(const num_t gyroFavoring, const Quaternion &initialQ)
Constructor.
Definition: imunano33.hpp:131
void updateIMU(const Vector3D &accel, const Vector3D &gyro, const num_t deltaT)
Updates IMU data.
Definition: imunano33.hpp:189
num_t getPressure() const
Gets pressure.
Definition: imunano33.hpp:336
void setRotQ(const Quaternion &q)
Sets rotation quaternion for the filter.
Definition: imunano33.hpp:281
A simple quaternion class for rotations.
Definition: quaternion.hpp:40
A simple 3D vector representation.
Definition: simplevectors.hpp:844
A minimal 3D vector representation.
Definition: sv_embed.hpp:168