|
|
@ -3,6 +3,7 @@ |
|
|
|
#include <driver/uart.h> |
|
|
|
#include <driver/uart.h> |
|
|
|
#include <esp_log.h> |
|
|
|
#include <esp_log.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "i2c_mutex.h" |
|
|
|
#include "MPU.hpp" |
|
|
|
#include "MPU.hpp" |
|
|
|
#include "mpu/math.hpp" |
|
|
|
#include "mpu/math.hpp" |
|
|
|
|
|
|
|
|
|
|
@ -32,6 +33,7 @@ void MPU::Init() { |
|
|
|
|
|
|
|
|
|
|
|
mpu_bus_ = &i2c0; |
|
|
|
mpu_bus_ = &i2c0; |
|
|
|
// This is shared with the oled, so just use those pins
|
|
|
|
// This is shared with the oled, so just use those pins
|
|
|
|
|
|
|
|
xSemaphoreTake(i2c_mutex, portMAX_DELAY); |
|
|
|
mpu_bus_->begin(MPU_SDA, MPU_SCL); |
|
|
|
mpu_bus_->begin(MPU_SDA, MPU_SCL); |
|
|
|
mpu_ = new mpud::MPU(*mpu_bus_); |
|
|
|
mpu_ = new mpud::MPU(*mpu_bus_); |
|
|
|
|
|
|
|
|
|
|
@ -54,6 +56,7 @@ void MPU::Init() { |
|
|
|
} |
|
|
|
} |
|
|
|
mpu_->setAccelFullScale(MPU_ACCEL_FS); |
|
|
|
mpu_->setAccelFullScale(MPU_ACCEL_FS); |
|
|
|
mpu_->setGyroFullScale(MPU_GYRO_FS); |
|
|
|
mpu_->setGyroFullScale(MPU_GYRO_FS); |
|
|
|
|
|
|
|
xSemaphoreGive(i2c_mutex); |
|
|
|
|
|
|
|
|
|
|
|
BaseType_t xRet = |
|
|
|
BaseType_t xRet = |
|
|
|
xTaskCreate(MPU::MPU_Task, "ugv_io_mpu", 2 * 1024, this, 3, &this->task_); |
|
|
|
xTaskCreate(MPU::MPU_Task, "ugv_io_mpu", 2 * 1024, this, 3, &this->task_); |
|
|
@ -74,7 +77,9 @@ void MPU::DoTask() { |
|
|
|
esp_err_t ret; |
|
|
|
esp_err_t ret; |
|
|
|
while (true) { |
|
|
|
while (true) { |
|
|
|
vTaskDelay(pdMS_TO_TICKS(50)); |
|
|
|
vTaskDelay(pdMS_TO_TICKS(50)); |
|
|
|
|
|
|
|
xSemaphoreTake(i2c_mutex, portMAX_DELAY); |
|
|
|
ret = mpu_->motion(&accel_, &gyro_, &mag_); |
|
|
|
ret = mpu_->motion(&accel_, &gyro_, &mag_); |
|
|
|
|
|
|
|
xSemaphoreGive(i2c_mutex); |
|
|
|
if (ret != ESP_OK) { |
|
|
|
if (ret != ESP_OK) { |
|
|
|
ESP_LOGE(TAG, "error reading MPU"); |
|
|
|
ESP_LOGE(TAG, "error reading MPU"); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|