uas-ugv/main/ugv_io_mpu.hh

67 lines
1.0 KiB
C++
Raw Normal View History

2019-01-17 19:44:14 -08:00
#pragma once
#include <stdint.h>
#include <MPU.hpp>
namespace ugv {
namespace io {
2019-01-17 19:59:13 -08:00
struct Vec3f {
float x;
float y;
float z;
Vec3f();
Vec3f(float x, float y, float z);
2019-04-10 20:47:21 -07:00
Vec3f(const mpud::float_axes_t& axes);
Vec3f operator+(const Vec3f& a) const { return {x + a.x, y + a.y, z + a.z}; }
Vec3f& operator+=(const Vec3f& a) {
x += a.x;
y += a.y;
z += a.z;
return *this;
}
};
struct Mat3f {
float xx, xy, xz;
float yx, yy, yz;
float zx, zy, zz;
Vec3f operator*(const Vec3f& v) const {
2019-04-13 15:41:13 -07:00
return {xx * v.x + xy * v.y + xz * v.z,
2019-04-10 20:47:21 -07:00
yx * v.x + yy * v.y + yz * v.z,
zx * v.x + zy * v.y + zz * v.z};
}
2019-01-17 19:59:13 -08:00
};
2019-01-17 19:44:14 -08:00
struct MpuData {
// G's
2019-01-17 19:59:13 -08:00
Vec3f accel;
2019-01-17 19:44:14 -08:00
// degrees/s
2019-01-17 19:59:13 -08:00
Vec3f gyro_rate;
2019-01-17 19:44:14 -08:00
// flux density uT
2019-01-17 19:59:13 -08:00
Vec3f mag;
2019-01-17 19:44:14 -08:00
};
class MPU {
public:
explicit MPU();
~MPU();
void Init();
2019-01-30 19:50:51 -08:00
void Calibrate();
2019-01-17 19:44:14 -08:00
2019-04-10 20:47:21 -07:00
void GetData(MpuData& data);
2019-01-17 19:44:14 -08:00
private:
2019-04-10 20:47:21 -07:00
mpud::mpu_bus_t* mpu_bus_;
mpud::MPU* mpu_;
2019-01-17 19:44:14 -08:00
mpud::raw_axes_t accel_, gyro_, mag_;
};
} // namespace io
} // namespace ugv