uas-ugv/main/ugv_io_mpu.hh

54 lines
757 B
C++
Raw Normal View History

2019-01-17 19:44:14 -08:00
#pragma once
#include <freertos/FreeRTOS.h>
#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-01-17 22:04:30 -08:00
Vec3f(const mpud::float_axes_t &axes);
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();
void GetData(MpuData &data);
private:
2019-01-17 22:04:30 -08:00
mpud::mpu_bus_t *mpu_bus_;
2019-01-17 19:44:14 -08:00
mpud::MPU * mpu_;
mpud::raw_axes_t accel_, gyro_, mag_;
2019-01-17 19:59:13 -08:00
2019-01-17 22:04:30 -08:00
TaskHandle_t task_;
2019-01-17 19:59:13 -08:00
SemaphoreHandle_t mutex_;
2019-01-17 22:04:30 -08:00
MpuData mpu_data_;
2019-01-17 19:59:13 -08:00
void DoTask();
static void MPU_Task(void *arg);
2019-01-17 19:44:14 -08:00
};
} // namespace io
} // namespace ugv