MPU6050(MPU6050)
Macro definition
| Macro definition | value | Annotation |
|---|---|---|
| PRINT_ACCEL | (0x01) | Print acceleration data |
| PRINT_GYRO | (0x02) | Print gyroscope data |
| PRINT_QUAT | (0x04) | Print four yuan data data |
| ACCEL_ON | (0x01) | Acceleration sensor enable |
| GYRO_ON | (0x02) | Gyroscope sensor enable |
| MOTION | (0) | Movement status (0 means no exercise) |
| NO_MOTION | (1) | Non -sports state (1 means exercise) |
| DEFAULT_MPU_HZ | (200) | The default sampling frequency, the unit is Hz |
| FLASH_SIZE | (512) | Flash memory, the unit is byte |
| FLASH_MEM_START | ((void*)0x1800) | Start address of flash memory |
| q30 | 1073741824.0f | Label factor for the number of four yuan and acceleration/gyroscope data |
Global variable
| Global variable | type | Annotation |
|---|---|---|
| gyro | short[3] | The gyroscope data array, including X, Y, Z -axis data |
| accel | short[3] | Acceleration data array, including X, Y, Z -axis data |
| sensors | short | Sensor status logo |
| Roll | float | Roller |
| Pitch | float | Pitch angle |
| Yaw | float | Polar angle |
| q0 | float | Quaternion q0 part |
| q1 | float | Quaternion q1 part |
| q2 | float | Quaternion q2 part |
| q3 | float | Quaternion q3 part |
| buffer | uint8_t[14] | The buffer area is used to store data |
| MPU6050_FIFO | int16_t[6][11] | Data cache array for filtering |
| Gx_offset | int16_t | Rolling axis offset |
| Gy_offset | int16_t | Pental axis offset |
| Gz_offset | int16_t | Poor navigation shaft offset |
Static variable
| Static variable | type | Annotation |
|---|---|---|
| gyro_orientation | signed char[9] | Trooria direction matrix |
method
MPU6050_Init()
Initialize MPU6050 to enter the available state
| Return value | type |
|---|---|
| none | void |
MPU6050_getDate(int way)
2024-11-25 renew
Integrate the algorithm of obtaining gesture
Read MPU6050 posture information
way: 1.DMP 2.Carman Filter 3.Complementary filtering
When using Carman filtering and complementary filtering to obtain posture information, the YAW value read is invalid data (that is, the value of the return value is invalid)
| parameter | type | Annotation |
|---|---|---|
| way | int | Algorithm of reading posture information: 1.DMP 2. Carman Filter 3. complementary filtering |
| Return value | type |
|---|---|
| Gesture information | float* |
| Back value order: Roll, Pitch, Yaw, gyro(X -axis), gyro(Y -axis),gyro(Z -axis), accel(X -axis),accel(Y -axis),accel(Z -axis) | |
Read_DMP(void)
Read the attitude information of the MPU6050 built -in DMP
2024-11-18 renew
1. Return value adds original data GYRO and Accel
2024-11-22 renew
1. Fix the error problem of the return value order
| Return value | type |
|---|---|
| Gesture information | float* |
| Back value order: Roll, Pitch, Yaw, gyro(X -axis), gyro(Y -axis),gyro(Z -axis), accel(X -axis),accel(Y -axis),accel(Z -axis) | |
Read_Temperature(void)
Read MPU6050 built -in temperature sensor data
| Return value | type |
|---|---|
| Celsius temperature | int |
| Other functions | Return value | Function |
|---|---|---|
| static unsigned short inv_row_2_scale(const signed char *row) | unsigned short | Ring vector label conversion function |
| static unsigned short inv_orientation_matrix_to_scalar(const signed char *mtx) | unsigned short | Direction matrix marker conversion function |
| static void run_self_test(void) | void | Run self -inspection and set bias |
| void MPU6050_newValues(int16_t ax,int16_t ay,int16_t az,int16_t gx,int16_t gy,int16_t gz) | void | Update the FIFO array and perform filtering |
| void MPU6050_setClockSource(uint8_t source) | void | Set MPU6050 clock source |
| void MPU6050_setFullScaleGyroRange(uint8_t range) | void | Set the range range of the gyroscope |
| void MPU6050_setFullScaleAccelRange(uint8_t range) | void | Set the maximum range of the acceleration meter |
| void MPU6050_setSleepEnabled(uint8_t enabled) | void | Set whether the MPU6050 enters the sleep mode |
| uint8_t MPU6050_getDeviceID(void) | uint8_t | Read MPU6050 WHO_AM_I identification |
| uint8_t MPU6050_testConnection(void) | uint8_t | Detect whether the MPU6050 has been connected |
| void MPU6050_setI2CMasterModeEnabled(uint8_t enabled) | void | Set the host of the MPU6050 as the AUX I2C line |
| void MPU6050_setI2CBypassEnabled(uint8_t enabled) | void | Set the host of the MPU6050 as the AUX I2C line |
| void MPU6050_initialize(void) | void | Initialize MPU6050 to enter the available state |
| DMP_Init(void) | void | Initialization of MPU6050 built-in DMP |
| float* Read_DMP(void) | float* | Read the attitude information of the built-in DMP of MPU6050 |
| int Read_Temperature(void) | int | Read the MPU6050 built-in temperature sensor data |
| void MPU6050_EXTI_Init(void) | void | Initialization interrupt |
Usage Examples
MPU6050 relies on the Delay module as a preamplifier
//The new version only needs to import these two header files
#include "delay.h"
#include "MPU6050.h"
//The old version also needs to import these header files
#include "IOI2C.h"
#include "dmpKey.h"
#include "dmpmap.h"
#include "inv_mpu.h"
#include "inv_mpu_dmp_motion_driver.h"
int main() {
MPU6050_Init();
while(1);
return 0;
}
void EXTI15_10_IRQHandler() {
if(MPU6050_INT==0)
{
EXTI->PR=1<<12;
// The new version recommends using MPU6050_getDate(1)
// Older versions use Read_DMP();
MPU6050_getDate(1);
}
}