MPU6050(MPU6050)

Macro definition

Macro definitionvalueAnnotation
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
q301073741824.0fLabel factor for the number of four yuan and acceleration/gyroscope data

Global variable

Global variabletypeAnnotation
gyroshort[3]The gyroscope data array, including X, Y, Z -axis data
accelshort[3]Acceleration data array, including X, Y, Z -axis data
sensorsshortSensor status logo
RollfloatRoller
PitchfloatPitch angle
YawfloatPolar angle
q0floatQuaternion q0 part
q1floatQuaternion q1 part
q2floatQuaternion q2 part
q3floatQuaternion q3 part
bufferuint8_t[14]The buffer area is used to store data
MPU6050_FIFOint16_t[6][11]Data cache array for filtering
Gx_offsetint16_tRolling axis offset
Gy_offsetint16_tPental axis offset
Gz_offsetint16_tPoor navigation shaft offset

Static variable

Static variabletypeAnnotation
gyro_orientationsigned char[9]Trooria direction matrix

method

MPU6050_Init()

Initialize MPU6050 to enter the available state

Return valuetype
nonevoid

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)

parametertypeAnnotation
wayintAlgorithm of reading posture information: 1.DMP 2. Carman Filter 3. complementary filtering
Return valuetype
Gesture informationfloat*
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 valuetype
Gesture informationfloat*
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 valuetype
Celsius temperatureint
Other functionsReturn valueFunction
static unsigned short inv_row_2_scale(const signed char *row)unsigned shortRing vector label conversion function
static unsigned short inv_orientation_matrix_to_scalar(const signed char *mtx)unsigned shortDirection matrix marker conversion function
static void run_self_test(void)voidRun 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)voidUpdate the FIFO array and perform filtering
void MPU6050_setClockSource(uint8_t source)voidSet MPU6050 clock source
void MPU6050_setFullScaleGyroRange(uint8_t range)voidSet the range range of the gyroscope
void MPU6050_setFullScaleAccelRange(uint8_t range)voidSet the maximum range of the acceleration meter
void MPU6050_setSleepEnabled(uint8_t enabled)voidSet whether the MPU6050 enters the sleep mode
uint8_t MPU6050_getDeviceID(void)uint8_tRead MPU6050 WHO_AM_I identification
uint8_t MPU6050_testConnection(void)uint8_tDetect whether the MPU6050 has been connected
void MPU6050_setI2CMasterModeEnabled(uint8_t enabled)voidSet the host of the MPU6050 as the AUX I2C line
void MPU6050_setI2CBypassEnabled(uint8_t enabled)voidSet the host of the MPU6050 as the AUX I2C line
void MPU6050_initialize(void)voidInitialize MPU6050 to enter the available state
DMP_Init(void)voidInitialization 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)intRead the MPU6050 built-in temperature sensor data
void MPU6050_EXTI_Init(void)voidInitialization 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);
    }
}