MPU6050原始数据分析——学习笔记

  • 个人学习笔记
  • MPU6050简介
  • 原始数据分析
  • 加速度计
  • 陀螺仪
  • 代码


个人学习笔记

用于记录自己学习的成果,并且分享给大家一起看看。希望对看到这篇的朋友有所帮助。

MPU6050简介

MPU-6050是一款6轴运动处理组件,将陀螺仪和加速度计合在一起,减少了大量封装空间,还是很不错的。如果连接三轴的磁强计,那就成九轴了。MPU6050用的是IIC通信,想要了解更多的话,直接点击下方链接(省的打字搜索)
link

原始数据分析

加速度计

数据手册描述如下:

Accelerometer Features

The triple-axis MEMS accelerometer in MPU-60X0 includes a wide range of features:

 Digital-output triple-axis accelerometer with a programmable full scale range of ±2g, ±4g, ±8g and ±16g

 Integrated 16-bit ADCs enable simultaneous sampling of accelerometers while requiring no external

multiplexer

 Accelerometer normal operating current: 500µA

 Low power accelerometer mode current: 10µA at 1.25Hz, 20µA at 5Hz, 60µA at 20Hz, 110µA at

40Hz

 Orientation detection and signaling

 Tap detection

 User-programmable interrupts

 High-G interrupt

 User self-test

应用时处理数据我们需要知道 16-bit ADCs(读出的数据应该在-32768~32767),同时设置不同的量程 ±2g, ±4g, ±8g and ±16g

根据需求选取量程,量程选取越小,精度越高,量程较大时精度不如小量程。

设x轴加速度原始数据为ADCx,假设此时量程选取为±4g,则原始数据转换公式为 (4g * ADCx)/32768

下方笔记有兴趣可以看看,比较简略。

MPU6050原始数据分析 mpu6050输出的原始数据是什么_数据


MPU6050原始数据分析 mpu6050输出的原始数据是什么_原始数据_02


MPU6050原始数据分析 mpu6050输出的原始数据是什么_数据_03


MPU6050原始数据分析 mpu6050输出的原始数据是什么_数据_04


MPU6050原始数据分析 mpu6050输出的原始数据是什么_数据分析_05

陀螺仪

数据手册的描述如下:

Gyroscope Features
 The triple-axis MEMS gyroscope in the MPU-60X0 includes a wide range of features:
  Digital-output X-, Y-, and Z-Axis angular rate sensors (gyroscopes) with a user-programmable fullscale range of ±250, ±500, ±1000, and ±2000°/sec
  External sync signal connected to the FSYNC pin supports image, video and GPS synchronization
  Integrated 16-bit ADCs enable simultaneous sampling of gyros
  Enhanced bias and sensitivity temperature stability reduces the need for user calibration
  Improved low-frequency noise performance
  Digitally-programmable low-pass filter
  Gyroscope operating current: 3.6mA
  Standby current: 5µA
  Factory calibrated sensitivity scale factor
  User self-test

应用时处理数据我们需要知道 16-bit ADCs(读出的数据应该在-32768~32767),同时设置不同的量程 ±250, ±500, ±1000, and ±2000°/sec

陀螺仪提供的是三轴角速度

根据需求选取量程,量程选取越小,精度越高,量程较大时精度不如小量程。

设x轴角速度原始数据为ADCx,假设此时量程选取为±2000dps(degree per second),则原始数据转换公式为 (2000 * ADCx)/32768

MPU6050原始数据分析 mpu6050输出的原始数据是什么_数据_06


MPU6050原始数据分析 mpu6050输出的原始数据是什么_原始数据_07


MPU6050原始数据分析 mpu6050输出的原始数据是什么_原始数据_08


MPU6050原始数据分析 mpu6050输出的原始数据是什么_MPU6050原始数据分析_09

代码

下面展示一些 MPU6050原始数据处理代码,没几行,主要是试试这个功能,
代码不完整,变量、子函数什么的自己看着补吧。。。

unsigned char MPU6050_Init(void)
{
    int  res;
    res = MPU_Read_Byte(MPU6050_ADDR,WHO_AM_I);           //读取MPU6050的ID
    if(res == MPU6050_ID)                                 //器件ID正确
    {
    	;
    }
    else
    {
        return 1;
    }

    res = 0;
    res += MPU_Write_Byte(MPU6050_ADDR,MPU_PWR_MGMT1_REG,0X80);//复位MPU6050
    delayms_mpu(100);  //延时100ms
    res += MPU_Write_Byte(MPU6050_ADDR,MPU_PWR_MGMT1_REG,0X00);//唤醒MPU6050
    res += MPU_Set_Gyro_Fsr(3);					        	   //陀螺仪传感器,±2000dps
    res += MPU_Set_Accel_Fsr(1);					       	   //加速度传感器,±4g
    res += MPU_Set_Rate(1000);						       	   //设置采样率1000Hz
    res += MPU_Write_Byte(MPU6050_ADDR,MPU_CFG_REG,0x02);      //设置数字低通滤波器   98hz
    res += MPU_Write_Byte(MPU6050_ADDR,MPU_INT_EN_REG,0X00);   //关闭所有中断
    res += MPU_Write_Byte(MPU6050_ADDR,MPU_USER_CTRL_REG,0X00);//I2C主模式关闭
    res += MPU_Write_Byte(MPU6050_ADDR,MPU_PWR_MGMT1_REG,0X01);//设置CLKSEL,PLL X轴为参考
    res += MPU_Write_Byte(MPU6050_ADDR,MPU_PWR_MGMT2_REG,0X00);//加速度与陀螺仪都工作

    if(res == 0)  //上面寄存器都写入成功
    {
        ;
    }
    else return 1;

    return 0;
}

void MPU6050(void)
{
    MPU_Get_Raw_data(&Accel_x,&Accel_y,&Accel_z,&Gyro_x,&Gyro_y,&Gyro_z);	//得到加速度传感器数据
        ax = (4*9.8*Accel_x)/32768;
        ay = (4*9.8*Accel_y)/32768;
        az = (4*9.8*Accel_z)/32768;
        Gyro_x = (2000*Gyro_x)/32768;
        Gyro_y = (2000*Gyro_y)/32768;
        Gyro_z = (2000*Gyro_z)/32768;

    	//用加速度计算三个轴和水平面坐标系之间的夹角
    	Angle_x_temp=(atan(ay/az))*180/3.14;
    	Angle_y_temp=(atan(ax/az))*180/3.14;

    	Kalman_Filter_X(Angle_x_temp,Gyro_x);  //卡尔曼滤波计算X倾角
    	Kalman_Filter_Y(Angle_y_temp,Gyro_y);  //卡尔曼滤波计算Y倾角
}