MPU-6000(MPU-6050)移植读取数据时出现FIFO溢出问题解析

文章图片

MPU-6000MPU-6050)为全球首例整合性6轴运动处理组件,相较于多组件方案,免除了组合陀螺仪与加速器时间轴之差的问题,减少了大量的封装空间。

  MPU-6000MPU-6050)的角速度全格感测范围为±250、±500、±1000与±2000°/sec (dps),可准确追踪快速与慢速动作,并且,用户可程式控制的加速器全格感测范围为±2g、±4g±8g与±16g。产品传输可透过最高至400kHz的IIC或最高达20MHz的SPI(MPU-6050没有SPI)。MPU-6000可在不同电压下工作,VDD供电电压介为2.5V±5%、3.0V±5%或3.3V±5%,逻辑接口VDDIO供电为1.8V± 5%(MPU6000仅用VDD)。MPU-6000的包装尺寸4x4x0.9mm(QFN),在业界是革命性的尺寸。其他的特征包含内建的温度感测器、包含在运作环境中仅有±1%变动的振荡器。 

对问题做个简单的分析:为什么FIFO数据会溢出?MPU6050的DMP在工作的时候,其实大概的工作过程是mpu6050对陀螺仪和加速度计按照一定的采样速率进行采样,对采样得到的陀螺仪和加速度计数据通过DMP处理后得到姿态角(pitch,roll,yaw),然后存入FIFO中,这个过程在你初始化完DMP后就会不受人为控制的持续进行,那么如果你不及时读取FIFO的数据,FIFO数据很快就会溢出,那么就会出现以上的问题啦!

  好了,说了那么一大堆,问题该如何解决呢? 其实很简答啦,只要一个简单循环其实就解决了!看如下的程序:

  while(mpu_dmp_get_data(&pitch,&roll,&yaw)!=0){}

  就是上面这么一句话,如果读取失败,马上进行第二次读取,这时候FIFO一般没有溢出,搞定!(因为检测到FIFO溢出后会马上reset一下FIFO)。

  最后上一发图: 
  

int dmp_read_fifo(short *gyro, short *accel, long *quat,

  unsigned long *TImestamp, short *sensors, unsigned char *more)

  {

  unsigned char fifo_data[MAX_PACKET_LENGTH];

  unsigned char ii = 0;

  /* TODO: sensors[0] only changes when dmp_enable_feature is called. We can

  * cache this value and save some cycles.

  */

  sensors[0] = 0;

  /* Get a packet. */

  if (mpu_read_fifo_stream(dmp.packet_length, fifo_data, more))

  return -1;

  /* Parse DMP packet. */

  if (dmp.feature_mask & (DMP_FEATURE_LP_QUAT | DMP_FEATURE_6X_LP_QUAT)) {

  #ifdef FIFO_CORRUPTION_CHECK

  long quat_q14[4], quat_mag_sq;

  #endif

  quat[0] = ((long)fifo_data[0] 《《 24) | ((long)fifo_data[1] 《《 16) |

  ((long)fifo_data[2] 《《 8) | fifo_data[3];

  quat[1] = ((long)fifo_data[4] 《《 24) | ((long)fifo_data[5] 《《 16) |

  ((long)fifo_data[6] 《《 8) | fifo_data[7];

  quat[2] = ((long)fifo_data[8] 《《 24) | ((long)fifo_data[9] 《《 16) |

  ((long)fifo_data[10] 《《 8) | fifo_data[11];

  quat[3] = ((long)fifo_data[12] 《《 24) | ((long)fifo_data[13] 《《 16) |

  ((long)fifo_data[14] 《《 8) | fifo_data[15];

  ii += 16;

  #ifdef FIFO_CORRUPTION_CHECK

  /* We can detect a corrupted FIFO by monitoring the quaternion data and

  * ensuring that the magnitude is always normalized to one. This

  * shouldn‘t happen in normal operaTIon, but if an I2C error occurs,

  * the FIFO reads might become misaligned.

  *

  * Let’s start by scaling down the quaternion data to avoid long long

  * math.

  */

  quat_q14[0] = quat[0] 》》 16;

  quat_q14[1] = quat[1] 》》 16;

  quat_q14[2] = quat[2] 》》 16;

  quat_q14[3] = quat[3] 》》 16;

  quat_mag_sq = quat_q14[0] * quat_q14[0] + quat_q14[1] * quat_q14[1] +

  quat_q14[2] * quat_q14[2] + quat_q14[3] * quat_q14[3];

  if ((quat_mag_sq 《 QUAT_MAG_SQ_MIN) ||

  (quat_mag_sq 》 QUAT_MAG_SQ_MAX)) {

  /* Quaternion is outside of the acceptable threshold. */

  mpu_reset_fifo();

  sensors[0] = 0;

  return -1;

  }

  sensors[0] |= INV_WXYZ_QUAT;

  #endif

  }

  if (dmp.feature_mask & DMP_FEATURE_SEND_RAW_ACCEL) {

  accel[0] = ((short)fifo_data[ii+0] 《《 8) | fifo_data[ii+1];

  accel[1] = ((short)fifo_data[ii+2] 《《 8) | fifo_data[ii+3];

  accel[2] = ((short)fifo_data[ii+4] 《《 8) | fifo_data[ii+5];

  ii += 6;

  sensors[0] |= INV_XYZ_ACCEL;

  }

  if (dmp.feature_mask & DMP_FEATURE_SEND_ANY_GYRO) {

  gyro[0] = ((short)fifo_data[ii+0] 《《 8) | fifo_data[ii+1];

  gyro[1] = ((short)fifo_data[ii+2] 《《 8) | fifo_data[ii+3];

  gyro[2] = ((short)fifo_data[ii+4] 《《 8) | fifo_data[ii+5];

  ii += 6;

  sensors[0] |= INV_XYZ_GYRO;

  }

  /* Gesture data is at the end of the DMP packet. Parse it and call

  * the gesture callbacks (if registered)。

  */

  if (dmp.feature_mask & (DMP_FEATURE_TAP | DMP_FEATURE_ANDROID_ORIENT))

  decode_gesture(fifo_data + ii);

  get_ms(timestamp);

  return 0;

  }

成品展示:
型号 品牌 供应商 库存量/起订量 售价(含13%税)
SRF0703-151M Bourns 1/25 暂无价格 询价
SN74LVC1T45DBVT TI 10000/25 ¥2.452801
价格梯度 售价(含13%税)
25 ¥3.773540
50 ¥3.396186
100 ¥2.641478
500 ¥2.452801
加入购物车
MKA14103(干簧管14103) MKA 95900/1 ¥0.7684
价格梯度 售价(含13%税)
1 ¥0.904
1000 ¥0.8475
1500 ¥0.7684
加入购物车
STM8L101F3U6TR STMicroelectronics 1/10 暂无价格 询价
DRQ127-330-R Eaton 1/20 暂无价格 询价
W7100 WIZnet 10000/10 ¥31.64
价格梯度 售价(含13%税)
10 ¥33.90
100 ¥33.335
1000 ¥32.77
10000 ¥32.205
100000 ¥31.64
加入购物车
DEI1016-QMS DEI 412/1 ¥301.71
价格梯度 售价(含13%税)
1 ¥356.017800
10 ¥346.966500
25 ¥337.915200
50 ¥331.881000
100 ¥325.846800
300 ¥322.829700
500 ¥319.812600
1000 ¥301.710000
加入购物车
AP8022 Chipown 9999999/100 ¥1.017
价格梯度 售价(含13%税)
100 ¥1.0509
1000 ¥1.0396
10000 ¥1.0283
50000 ¥1.017
加入购物车
220uF/50V RB3.5/8 chengxing 14500/50 ¥0.1695
价格梯度 售价(含13%税)
50 ¥0.339000
100 ¥0.305100
500 ¥0.262725
1000 ¥0.245775
3000 ¥0.211875
5000 ¥0.203400
10000 ¥0.169500
加入购物车
DRQ127-220-R Eaton 1/20 暂无价格 询价
CTX250-4-R Eaton 1/10 暂无价格 询价
SDQ25-101-R Eaton 1/20 暂无价格 询价
DRQ74-100-R Eaton 1/20 暂无价格 询价
DRQ125-100-R Eaton 1/20 暂无价格 询价
P0595NLT Pulse Electronics 1/10 暂无价格 询价
SRF1260-221M Bourns 1/25 暂无价格 询价
SRF0703-470M Bourns 1/25 暂无价格 询价
DRQ125-220-R Eaton 1/20 暂无价格 询价
DEI1016A DEI 750/1 ¥242.95
价格梯度 售价(含13%税)
1 ¥286.681000
10 ¥279.392500
25 ¥272.104000
50 ¥267.245000
100 ¥262.386000
300 ¥259.956500
500 ¥257.527000
1000 ¥242.950000
加入购物车
CTX20-4P-R Eaton 1/20 暂无价格 询价
DRQ74-150-R Eaton 1/25 暂无价格 询价
DRQ73-470-R Eaton 1/20 暂无价格 询价
VPH2-1600-R Eaton 1/20 暂无价格 询价
DRQ73-3R3-R Eaton 1/25 暂无价格 询价
DRQ127-102-R Eaton 1/20 暂无价格 询价
DRAQ127-100-R Eaton 1/25 暂无价格 询价
VP1-0102-R Eaton 1/20 暂无价格 询价
PF0553.103NLT Pulse Electronics 1/20 暂无价格 询价
SRF0703-820M Bourns 1/25 暂无价格 询价
CTX5-4-R Eaton 1/20 暂无价格 询价
CTX10-4A-R Eaton 1/20 暂无价格 询价
DRQ73-101-R Eaton 1/25 暂无价格 询价
DRQ74-100-R Eaton 1/20 暂无价格 询价
CTX20-4-R Eaton 1/10 暂无价格 询价
DRQ127-100-R Eaton 1/20 暂无价格 询价
CTX250-4-R Eaton 1/20 暂无价格 询价
SRF1280-102M Bourns 1/25 暂无价格 询价
PM3604-50-RC Bourns 1/25 暂无价格 询价
CTX5-4-R Eaton 1/10 暂无价格 询价
CTX20-4P-R Eaton 1/20 暂无价格 询价
DEI1016 DEI 750/1 ¥412.45
价格梯度 售价(含13%税)
1 ¥486.691000
10 ¥474.317500
25 ¥461.944000
50 ¥453.695000
100 ¥445.446000
300 ¥441.321500
500 ¥437.197000
1000 ¥412.450000
加入购物车
DRQ73-150-R Eaton 1/25 暂无价格 询价
SDQ25-150-R Eaton 1/20 暂无价格 询价
DRQ125-100-R Eaton 1/20 暂无价格 询价
CTX50-4-R Eaton 1/10 暂无价格 询价

发表评论

评论

    暂无评论

©Copyright 2013-2025 亿配芯城(深圳)电子科技有限公司 粤ICP备17008354号

Scroll