weixin_39389143 2019-10-31 09:02 采纳率: 50%
浏览 569
已采纳

MPU-9150九轴传感器,Failed to init IMU: -1 No valid compass calibration data?

1、用MPU9150九轴传感器采集人体姿态数据时,之前一直都能将九个数据点输出到串口监视器中,但突然有一天总是报错,传感器无法读取数据

2、烧录的代码如下:
#include

#include

////////////////////////////////////////////////////////////////////////////
//
// This file is part of RTIMULib-Arduino
//
// Copyright (c) 2014-2015, richards-tech
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
// Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include
#include "I2Cdev.h"
#include "RTIMUSettings.h"
#include "RTIMU.h"
#include "RTFusionRTQF.h"
#include "CalLib.h"
#include

RTIMU *imu; // the IMU object
RTFusionRTQF fusion; // the fusion object
RTIMUSettings settings; // the settings object

// DISPLAY_INTERVAL sets the rate at which results are displayed

#define DISPLAY_INTERVAL 0 // interval between pose displays

// SERIAL_PORT_SPEED defines the speed to use for the debug serial port

#define SERIAL_PORT_SPEED 115200

unsigned long lastDisplay;
unsigned long lastRate;
int sampleCount;
RTQuaternion gravity;

void setup()
{
int errcode;

Serial.begin(SERIAL_PORT_SPEED);
Wire.begin();
imu = RTIMU::createIMU(&settings); // create the imu object

Serial.print("ArduinoIMU starting using device "); Serial.println(imu->IMUName());
if ((errcode = imu->IMUInit()) < 0) {
Serial.print("Failed to init IMU: "); Serial.println(errcode);
}

if (imu->getCalibrationValid())
Serial.println("Using compass calibration");
else
Serial.println("No valid compass calibration data");

lastDisplay = lastRate = millis();
sampleCount = 0;

gravity.setScalar(0);
gravity.setX(0);
gravity.setY(0);
gravity.setZ(1);
}

void loop()
{

unsigned long now = millis();
unsigned long timeTemp = millis();
unsigned long delta;
RTVector3 realAccel;
RTVector3 realGyro;
RTVector3 realCompass;
RTQuaternion rotatedGravity;
RTQuaternion fusedConjugate;
RTQuaternion qTemp;
int loopCount = 0;

while (imu->IMURead()) { // get the latest data if ready yet
// this flushes remaining data in case we are falling behind
if (++loopCount >= 10)
continue;
fusion.newIMUData(imu->getGyro(), imu->getAccel(), imu->getCompass(), imu->getTimestamp());

//  do gravity rotation and subtraction

// create the conjugate of the pose

fusedConjugate = fusion.getFusionQPose().conjugate();

// now do the rotation - takes two steps with qTemp as the intermediate variable

qTemp = gravity * fusion.getFusionQPose();
rotatedGravity = fusedConjugate * qTemp;

// now adjust the measured accel and change the signs to make sense

realAccel.setX(-(imu->getAccel().x() - rotatedGravity.x()));
realAccel.setY(-(imu->getAccel().y() - rotatedGravity.y()));
realAccel.setZ(-(imu->getAccel().z() - rotatedGravity.z()));

realGyro.setX(-(imu->getGyro().x()));
realGyro.setY(-(imu->getGyro().y()));
realGyro.setZ(-(imu->getGyro().z()));


realCompass.setX(-(imu->getCompass().x()));
realCompass.setY(-(imu->getCompass().y()));
realCompass.setZ(-(imu->getCompass().z()));

sampleCount++;
if ((delta = now - lastRate) >= 1000) {
  Serial.print("Sample rate: "); Serial.print(sampleCount);
  if (!imu->IMUGyroBiasValid())
    Serial.println(", calculating gyro bias");
  else
    Serial.println();

  sampleCount = 0;
  lastRate = now;
}

/* if ((now - lastDisplay) >= DISPLAY_INTERVAL) {
lastDisplay = now;

  RTMath::display("Accel:", realAccel);
  RTMath::display("Gyro:", realGyro);
  RTMath::display("Compass:", realCompass);
  Serial.println();
}*/
/*////////////////////正常输出//////////////*/
  /*RTMath::display("Accel:", realAccel);
  RTMath::display("Gyro:", realGyro);
  RTMath::display("Compass:", realCompass);
  Serial.println();*/
  /******************串口输出************/
  RTMath::display( "",realAccel);
  RTMath::display("", realGyro);
  RTMath::display("",realCompass);
  Serial.println();
  delay(25);

}
}

3、编译没有报错,但是打开串口监视器的时候出现:
ArduinoIMU starting using device MPU-9250
Failed to init IMU: -1
No valid compass calibration data

4、尝试过的解决方法:
a、更换连接线
b、更换库文件

  • 写回答

1条回答 默认 最新

  • zqbnqsdsmd 2019-10-31 10:55
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)