-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix IMU not work in some compiled environments
- Loading branch information
1 parent
f77022f
commit f72d90d
Showing
12 changed files
with
208 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#include "IMU.h" | ||
|
||
#include <Arduino.h> | ||
#include <math.h> | ||
|
||
#include "M5Stack.h" | ||
#undef IMU | ||
|
||
IMU::IMU() { | ||
} | ||
|
||
int IMU::Init(void) { | ||
int imu_flag = M5.Sh200Q.Init(); | ||
Serial.printf("imu_flag:%d", imu_flag); | ||
if (imu_flag != 0) { | ||
imu_flag = M5.Mpu6886.Init(); | ||
if (imu_flag == 0) { | ||
imuType = IMU_MPU6886; | ||
Serial.printf("IMU_MPU6886"); | ||
} else { | ||
imuType = IMU_UNKNOWN; | ||
Serial.printf("IMU_UNKNOWN"); | ||
return -1; | ||
} | ||
} else { | ||
imuType = IMU_SH200Q; | ||
} | ||
return 0; | ||
} | ||
|
||
void IMU::getGres() { | ||
if (imuType == IMU_SH200Q) { | ||
gRes = M5.Sh200Q.gRes; | ||
} else if (imuType == IMU_MPU6886) { | ||
gRes = M5.Mpu6886.gRes; | ||
} | ||
} | ||
|
||
void IMU::getAres() { | ||
if (imuType == IMU_SH200Q) { | ||
aRes = M5.Sh200Q.aRes; | ||
} else if (imuType == IMU_MPU6886) { | ||
aRes = M5.Mpu6886.aRes; | ||
} | ||
} | ||
|
||
void IMU::getAccelAdc(int16_t *ax, int16_t *ay, int16_t *az) { | ||
if (imuType == IMU_SH200Q) { | ||
M5.Sh200Q.getAccelAdc(ax, ay, az); | ||
} else if (imuType == IMU_MPU6886) { | ||
M5.Mpu6886.getAccelAdc(ax, ay, az); | ||
} | ||
} | ||
|
||
void IMU::getAccelData(float *ax, float *ay, float *az) { | ||
if (imuType == IMU_SH200Q) { | ||
M5.Sh200Q.getAccelData(ax, ay, az); | ||
} else if (imuType == IMU_MPU6886) { | ||
M5.Mpu6886.getAccelData(ax, ay, az); | ||
} | ||
} | ||
|
||
void IMU::getGyroAdc(int16_t *gx, int16_t *gy, int16_t *gz) { | ||
if (imuType == IMU_SH200Q) { | ||
M5.Sh200Q.getGyroAdc(gx, gy, gz); | ||
} else if (imuType == IMU_MPU6886) { | ||
M5.Mpu6886.getGyroAdc(gx, gy, gz); | ||
} | ||
} | ||
|
||
void IMU::getGyroData(float *gx, float *gy, float *gz) { | ||
if (imuType == IMU_SH200Q) { | ||
M5.Sh200Q.getGyroData(gx, gy, gz); | ||
} else if (imuType == IMU_MPU6886) { | ||
M5.Mpu6886.getGyroData(gx, gy, gz); | ||
} | ||
} | ||
|
||
void IMU::getTempAdc(int16_t *t) { | ||
if (imuType == IMU_SH200Q) { | ||
M5.Sh200Q.getTempAdc(t); | ||
} else if (imuType == IMU_MPU6886) { | ||
M5.Mpu6886.getTempAdc(t); | ||
} | ||
} | ||
|
||
void IMU::getTempData(float *t) { | ||
if (imuType == IMU_SH200Q) { | ||
M5.Sh200Q.getTempData(t); | ||
} else if (imuType == IMU_MPU6886) { | ||
M5.Mpu6886.getTempData(t); | ||
} | ||
} | ||
|
||
void IMU::getAhrsData(float *pitch, float *roll, float *yaw) { | ||
float accX = 0; | ||
float accY = 0; | ||
float accZ = 0; | ||
|
||
float gyroX = 0; | ||
float gyroY = 0; | ||
float gyroZ = 0; | ||
|
||
getGyroData(&gyroX, &gyroY, &gyroZ); | ||
getAccelData(&accX, &accY, &accZ); | ||
|
||
MahonyAHRSupdateIMU(gyroX * DEG_TO_RAD, gyroY * DEG_TO_RAD, | ||
gyroZ * DEG_TO_RAD, accX, accY, accZ, pitch, roll, yaw); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef __IMU_H__ | ||
#define __IMU_H__ | ||
|
||
#include <Arduino.h> | ||
#include <Wire.h> | ||
|
||
#include "utility/MahonyAHRS.h" | ||
|
||
class IMU { | ||
public: | ||
enum ImuType { IMU_UNKNOWN = 0, IMU_SH200Q, IMU_MPU6886 }; | ||
|
||
IMU(); | ||
|
||
int Init(void); | ||
|
||
void getGres(); | ||
void getAres(); | ||
|
||
void getAccelAdc(int16_t *ax, int16_t *ay, int16_t *az); | ||
void getGyroAdc(int16_t *gx, int16_t *gy, int16_t *gz); | ||
void getTempAdc(int16_t *t); | ||
|
||
void getAccelData(float *ax, float *ay, float *az); | ||
void getGyroData(float *gx, float *gy, float *gz); | ||
void getTempData(float *t); | ||
|
||
void getAhrsData(float *pitch, float *roll, float *yaw); | ||
|
||
ImuType imuType; | ||
float aRes, gRes; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters