|
|
|
@ -20,6 +20,12 @@ static constexpr mpud::accel_fs_t MPU_ACCEL_FS = mpud::ACCEL_FS_2G;
@@ -20,6 +20,12 @@ static constexpr mpud::accel_fs_t MPU_ACCEL_FS = mpud::ACCEL_FS_2G;
|
|
|
|
|
static constexpr mpud::gyro_fs_t MPU_GYRO_FS = mpud::GYRO_FS_500DPS; |
|
|
|
|
static constexpr float MPU_MAG_TO_FLUX = (4912.f) / (32760.f); |
|
|
|
|
|
|
|
|
|
static const Vec3f ACCEL_OFFSET = {0., 0., 0.}; |
|
|
|
|
static const Mat3f ACCEL_MAT = {1., 0., 0., 0., 1., 0., 0., 0., 1.}; |
|
|
|
|
static const Vec3f MAG_OFFSET = {0., 0., 0.}; |
|
|
|
|
static const Mat3f MAG_MAT = {1., 0., 0., 0., 1., 0., 0., 0., 1.}; |
|
|
|
|
static const Vec3f GYRO_OFFSET = {0., 0., 0.}; |
|
|
|
|
|
|
|
|
|
static const char *TAG = "ugv_io_mpu"; |
|
|
|
|
|
|
|
|
|
Vec3f::Vec3f() : x(0), y(0), z(0) {} |
|
|
|
@ -35,7 +41,7 @@ void MPU::Init() {
@@ -35,7 +41,7 @@ void MPU::Init() {
|
|
|
|
|
xSemaphoreTake(i2c_mutex, portMAX_DELAY); |
|
|
|
|
mpu_bus_ = &i2c0; |
|
|
|
|
// This is shared with the oled, so just use those pins
|
|
|
|
|
// mpu_bus_->begin(MPU_SDA, MPU_SCL);
|
|
|
|
|
mpu_bus_->begin(MPU_SDA, MPU_SCL, 100000); |
|
|
|
|
mpu_ = new mpud::MPU(*mpu_bus_); |
|
|
|
|
|
|
|
|
|
esp_err_t ret; |
|
|
|
@ -55,7 +61,7 @@ void MPU::Init() {
@@ -55,7 +61,7 @@ void MPU::Init() {
|
|
|
|
|
ESP_LOGE(TAG, "MPU initialization error"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
Calibrate(); |
|
|
|
|
// Calibrate();
|
|
|
|
|
mpu_->setAccelFullScale(MPU_ACCEL_FS); |
|
|
|
|
mpu_->setGyroFullScale(MPU_GYRO_FS); |
|
|
|
|
// force magnetometer into continuous mode
|
|
|
|
@ -109,10 +115,13 @@ void MPU::GetData(MpuData &data) {
@@ -109,10 +115,13 @@ void MPU::GetData(MpuData &data) {
|
|
|
|
|
static_cast<int16_t>(compass_data[4]); |
|
|
|
|
// ESP_LOGV(TAG, "compass: %d, %d, %d", mx, my, mz);
|
|
|
|
|
data.accel = mpud::accelGravity(accel_, MPU_ACCEL_FS); |
|
|
|
|
data.accel = ACCEL_MAT * (data.accel + ACCEL_OFFSET); |
|
|
|
|
data.gyro_rate = mpud::gyroDegPerSec(gyro_, MPU_GYRO_FS); |
|
|
|
|
data.mag.x = ((float)mx) * MPU_MAG_TO_FLUX; |
|
|
|
|
data.mag.y = ((float)my) * MPU_MAG_TO_FLUX; |
|
|
|
|
data.mag.z = ((float)mz) * MPU_MAG_TO_FLUX; |
|
|
|
|
data.gyro_rate += GYRO_OFFSET; |
|
|
|
|
data.mag.x = ((float)mx) * MPU_MAG_TO_FLUX; |
|
|
|
|
data.mag.y = ((float)my) * MPU_MAG_TO_FLUX; |
|
|
|
|
data.mag.z = ((float)mz) * MPU_MAG_TO_FLUX; |
|
|
|
|
data.mag = MAG_MAT * (data.mag + MAG_OFFSET); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; // namespace io
|
|
|
|
|