0

I tried using AHRS library call uNavAHRS, and have been test example sketch from github, and change little code like below:

https://github.com/bolderflight/uNavAHRS/blob/master/examples/uNavAHRS-with-MPU9250/uNavAHRS_MPU9250/uNavAHRS_MPU9250.ino

/*
uNavAHRS_MPU9250.ino
Brian R Taylor
brian.taylor@bolderflight.com

Copyright (c) 2017 Bolder Flight Systems

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 "uNavAHRS.h"
#include "MPU9250.h"

// an MPU-9250 object on SPI bus 0 with chip select 10
MPU9250 Imu(Wire,0x68);
int status;
// a uNavAHRS object
uNavAHRS Filter;
void setup() {
  // serial to display data
  Serial.begin(115200);
  while(!Serial) {}

  // start communication with IMU 
  status = Imu.begin();
  if (status < 0) {
    Serial.println("IMU initialization unsuccessful");
    Serial.println("Check IMU wiring or try cycling power");
    Serial.print("Status: ");
    Serial.println(status);
    while(1) {}
  }
     Filter.setInitializationDuration(10000000);
    // setting a 41 Hz DLPF bandwidth
  Imu.setDlpfBandwidth(MPU9250::DLPF_BANDWIDTH_41HZ);
  // setting SRD to 9 for a 100 Hz update rate
  Imu.setSrd(9);
  // enabling the data ready interrupt
}

void loop() {
    Imu.readSensor();
    // update the filter
    if (Filter.update(Imu.getGyroX_rads(),Imu.getGyroY_rads(),Imu.getGyroZ_rads(),Imu.getAccelX_mss(),Imu.getAccelY_mss(),Imu.getAccelZ_mss(),Imu.getMagX_uT(),Imu.getMagY_uT(),Imu.getMagZ_uT())) {
      Serial.print(Filter.getPitch_rad()*180.0f/PI);
      Serial.println();

  }
}

But when i uploaded sketch and wait for initialize then initialize complete i get pitch value from serial port that value just fine but wait a some time value become nan error like this

0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.03 0.03 0.01 0.01 0.01 nan nan nan nan nan nan nan nan nan

I don't know what happen in this process can anyone give me some advice to solve that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.