uNav INS

It looks like your z-axis accel is positive up instead of positive down. Your z-axis gyro and mag are also probably not correct. Looking at the data sheet, it looks like by default x is positive forward, y is positive left, and z is positive up. You should test all of your sensor data. You test the accel by rotating each axis in line with the gravity vector and checking the sign of the corresponding accel channel. You can check each gyro axis by inputting a right hand rotation on each axis and checking the sign of the corresponding gyro output.

Would also help to post your application code and the BNO055 library that you're using. I don't have one of those, but it sounds like Mike does.
 
Thank you for the answer.
According to my system I have already tested that the vertical (z) axis is pointing down, so 9.71m/s2 positive works according the ref.
I’ve already tested all the axis possibilities and I’m getting those random reading for roll pitch and yaw.
The BNO055 data sheet has a diferente reference frames so that’s why I needed to change the orientation to match the most common axis distribution: front positive, right positive and down positive.
It looks like your z-axis accel is positive up instead of positive down. Your z-axis gyro and mag are also probably not correct. Looking at the data sheet, it looks like by default x is positive forward, y is positive left, and z is positive up. You should test all of your sensor data. You test the accel by rotating each axis in line with the gravity vector and checking the sign of the corresponding accel channel. You can check each gyro axis by inputting a right hand rotation on each axis and checking the sign of the corresponding gyro output.

Would also help to post your application code and the BNO055 library that you're using. I don't have one of those, but it sounds like Mike does.
 
View attachment 27589View attachment 27590
The master version compiles perfect but i have the graphic i uploaded earlier. The ver6 doesn't compiles to my teensy 4.

I just tried to compile the example sketch in the zip file you attached and yes there are errors when you compile for the T4 but for me they were all related to getting the correct libraries and updating the sketch accordingly.

The libraries I updated were all from Bolderflight's repository:
https://github.com/bolderflight/UBLOX - this cause most of the errors and had to rewrite portions of it to match the new interface
https://github.com/bolderflight/units
https://github.com/bolderflight/eigen

This is what the updated example should look like I think.
Code:
/*
uNavINS_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 "uNavINS.h"
#include "MPU9250.h"
#include "ubx.h"

// an MPU-9250 object on SPI bus 0 with chip select 24
MPU9250 Imu(SPI,24);
int status;
// a flag for when the MPU-9250 has new data
volatile int newData;
// a uNavINS object
uNavINS Filter;
bfs::Ubx gps(&Serial4);
bool newGpsData;
unsigned long prevTOW;

// timers to measure performance
unsigned long tstart, tstop;

void setup() {
  // serial to display data
  Serial.begin(115200);
  while(!Serial) {}

  if (!gps.AutoBegin()) {
    Serial.println("Unable to establish communication and configure GNSS RX");
    while (1) {}
  }

  // 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) {}
  }
  // setting SRD to 9 for a 100 Hz update rate
  Imu.setSrd(9);
  // enabling the data ready interrupt
  Imu.enableDataReadyInterrupt();
  // attaching the interrupt to microcontroller pin 1
  pinMode(27,INPUT);
  attachInterrupt(27,runFilter,RISING);
  Serial.println("Starting...");
}

void loop() {
  gps.Read();
  if (gps.num_sv() > 5) {
    if (newData == 1) {
      newData = 0;
      tstart = micros();
      // read the sensor
      Imu.readSensor();
      // update the filter
      Filter.update(gps.gps_tow_s(),gps.north_vel_mps(),gps.east_vel_mps(),gps.down_vel_mps(),gps.lat_rad(),gps.lon_rad(),gps.alt_msl_m(),Imu.getGyroY_rads(),-1*Imu.getGyroX_rads(),Imu.getGyroZ_rads(),Imu.getAccelY_mss(),-1*Imu.getAccelX_mss(),Imu.getAccelZ_mss(),Imu.getMagX_uT(),Imu.getMagY_uT(),Imu.getMagZ_uT());
      Serial.print(Filter.getPitch_rad()*180.0f/PI);
      Serial.print("\t");
      Serial.print(Filter.getRoll_rad()*180.0f/PI);
      Serial.print("\t");
      Serial.print(Filter.getYaw_rad()*180.0f/PI);
      Serial.print("\n");
      tstop = micros();
    }
  }
}

void runFilter() {
  newData = 1;
}
Please note the portion I have not tried is the new UBLOX library which @brtaylor updated from the version I have been using .

As for the BNO055 yes I have a BNO055 that I can test with but as
brtaylor said:
It looks like your z-axis accel is positive up instead of positive down. Your z-axis gyro and mag are also probably not correct. Looking at the data sheet, it looks like by default x is positive forward, y is positive left, and z is positive up. You should test all of your sensor data. You test the accel by rotating each axis in line with the gravity vector and checking the sign of the corresponding accel channel. You can check each gyro axis by inputting a right hand rotation on each axis and checking the sign of the corresponding gyro output.

Would also help to post your application code and the BNO055 library that you're using. I don't have one of those, but it sounds like Mike does.

EDIT: Note what I had to update is pretty much in the readme in the zip or the library readmes that you need to download
## Installation
This library requires [Eigen](https://github.com/bolderflight/Eigen) to compile. First download or clone [Eigen](https://github.com/bolderflight/Eigen) into your Arduino/libraries folder, then download or clone this library into your Arduino/libraries folder. Additionally, this library requires IMU measurements and GPS measurements. For the included examples, an [MPU-9250 IMU](https://github.com/bolderflight/MPU9250) is used with a [uBlox GPS](https://github.com/bolderflight/UBLOX), and their libraries will need to be installed as well.

You might want to see this link on guidance on posting issues:
https://forum.pjrc.com/threads/1513...n-Your-Question!?p=17615&viewfull=1#post17615
 
I’ll try again the last version of uNav again reinstalling all the libraries from zero.
Iva exactly the same sketch with the difference that I’m getting the same input values from another IMU.
Another fact is that I don’t have a source to download the “official” uNav release because the repository is unavailable.

I just tried to compile the example sketch in the zip file you attached and yes there are errors when you compile for the T4 but for me they were all related to getting the correct libraries and updating the sketch accordingly.

The libraries I updated were all from Bolderflight's repository:
https://github.com/bolderflight/UBLOX - this cause most of the errors and had to rewrite portions of it to match the new interface
https://github.com/bolderflight/units
https://github.com/bolderflight/eigen

This is what the updated example should look like I think.
Code:
/*
uNavINS_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 "uNavINS.h"
#include "MPU9250.h"
#include "ubx.h"

// an MPU-9250 object on SPI bus 0 with chip select 24
MPU9250 Imu(SPI,24);
int status;
// a flag for when the MPU-9250 has new data
volatile int newData;
// a uNavINS object
uNavINS Filter;
bfs::Ubx gps(&Serial4);
bool newGpsData;
unsigned long prevTOW;

// timers to measure performance
unsigned long tstart, tstop;

void setup() {
  // serial to display data
  Serial.begin(115200);
  while(!Serial) {}

  if (!gps.AutoBegin()) {
    Serial.println("Unable to establish communication and configure GNSS RX");
    while (1) {}
  }

  // 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) {}
  }
  // setting SRD to 9 for a 100 Hz update rate
  Imu.setSrd(9);
  // enabling the data ready interrupt
  Imu.enableDataReadyInterrupt();
  // attaching the interrupt to microcontroller pin 1
  pinMode(27,INPUT);
  attachInterrupt(27,runFilter,RISING);
  Serial.println("Starting...");
}

void loop() {
  gps.Read();
  if (gps.num_sv() > 5) {
    if (newData == 1) {
      newData = 0;
      tstart = micros();
      // read the sensor
      Imu.readSensor();
      // update the filter
      Filter.update(gps.gps_tow_s(),gps.north_vel_mps(),gps.east_vel_mps(),gps.down_vel_mps(),gps.lat_rad(),gps.lon_rad(),gps.alt_msl_m(),Imu.getGyroY_rads(),-1*Imu.getGyroX_rads(),Imu.getGyroZ_rads(),Imu.getAccelY_mss(),-1*Imu.getAccelX_mss(),Imu.getAccelZ_mss(),Imu.getMagX_uT(),Imu.getMagY_uT(),Imu.getMagZ_uT());
      Serial.print(Filter.getPitch_rad()*180.0f/PI);
      Serial.print("\t");
      Serial.print(Filter.getRoll_rad()*180.0f/PI);
      Serial.print("\t");
      Serial.print(Filter.getYaw_rad()*180.0f/PI);
      Serial.print("\n");
      tstop = micros();
    }
  }
}

void runFilter() {
  newData = 1;
}
Please note the portion I have not tried is the new UBLOX library which @brtaylor updated from the version I have been using .

As for the BNO055 yes I have a BNO055 that I can test with but as


EDIT: Note what I had to update is pretty much in the readme in the zip or the library readmes that you need to download


You might want to see this link on guidance on posting issues:
https://forum.pjrc.com/threads/1513...n-Your-Question!?p=17615&viewfull=1#post17615
 
I’ll try again the last version of uNav again reinstalling all the libraries from zero.
Iva exactly the same sketch with the difference that I’m getting the same input values from another IMU.
Another fact is that I don’t have a source to download the “official” uNav release because the repository is unavailable.

For some reason you keep ignoring the BNO055 code that we keep asking Brian and I keep asking you about.
brtaylor said:
...post your application code and the BNO055 library that you're using

Wont be able to help you much more. Would be nice if you could attach the actual code you are running with the bno055 -- otherwise its just guess work on our part.
 
Code:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include <EEPROM.h>
#include <uNavINS.h>
#include <ubx.h>

uint16_t BNO055_SAMPLERATE_DELAY_MS = 0;
Adafruit_BNO055 bno = Adafruit_BNO055(3, 0x29); //3 lugar en EEPROM de la calibracion.
volatile int newData;
// a uNavINS object
uNavINS Filter;
bfs::Ubx gps(&Serial4);
bool newGpsData;
unsigned long prevTOW;

// timers to measure performance
unsigned long tstart, tstop;

void setup() {
  Serial.begin(57600);//Inicio puerto serial PC.
  if (!bno.begin())
  {
    /* There was a problem detecting the BNO055 ... check your connections */
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
    while (1);
  }
  int eeAddress = 0;
  long bnoID;
  bool foundCalib = false;

  adafruit_bno055_offsets_t calibrationData;
  sensor_t sensor;

  bno.getSensor(&sensor);
    if (bnoID != sensor.sensor_id)
    {
        Serial.println("\nNo Calibration Data for this sensor exists in EEPROM");
        delay(500);
    }
    else
    {
        Serial.println("\nFound Calibration for this sensor in EEPROM.");
        eeAddress += sizeof(long);
        EEPROM.get(eeAddress, calibrationData);

        //displaySensorOffsets(calibrationData);

        Serial.println("\n\nRestoring Calibration data to the BNO055...");
        bno.setSensorOffsets(calibrationData);

        Serial.println("\n\nCalibration data loaded into BNO055");
        foundCalib = true;
    }
}

void loop() {

  sensors_event_t orientationData , angVelocityData , linearAccelData, magnetometerData, accelerometerData, gravityData;
  // - VECTOR_ACCELEROMETER - m/s^2
  // - VECTOR_MAGNETOMETER  - uT
  // - VECTOR_GYROSCOPE     - deg/s
  // - VECTOR_EULER         - degrees
  // - VECTOR_LINEARACCEL   - m/s^2
  // - VECTOR_GRAVITY       - m/s^2
  imu::Vector<3> euler = bno.getVector(Adafruit_BNO055::VECTOR_EULER);
  imu::Vector<3> gyros = bno.getVector(Adafruit_BNO055::VECTOR_GYROSCOPE);//la da en DEG/S
  imu::Vector<3> acc = bno.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);
  imu::Vector<3> linearacc = bno.getVector(Adafruit_BNO055::VECTOR_LINEARACCEL);
  imu::Vector<3> mags = bno.getVector(Adafruit_BNO055::VECTOR_MAGNETOMETER);
  imu::Vector<3> gravity = bno.getVector(Adafruit_BNO055::VECTOR_GRAVITY);

  float acc_x = -acc.x();//front positive for all sensors. m/s2
  float acc_y = acc.y();//right positive
  float acc_z = acc.z();//down positive
  float gyro_x = gyros.x();// DEG/S
  float gyro_y = -gyros.y();
  float gyro_z = -gyros.z();
  float mag_x = -mags.x();//uT
  float mag_y = mags.y();
  float mag_z = mags.z();

  Filter.update(gps.gps_tow_s(),gps.north_vel_mps(),gps.east_vel_mps(),
                gps.down_vel_mps(),gps.lat_rad(),gps.lon_rad(),
                gps.alt_msl_m(),gyro_y*PI/180,gyro_x*PI/180,gyro_z*PI/180,
                acc_y,acc_x,acc_z,
                mag_x,mag_y,mag_z);
                
  float PITCH_EKF = Filter.getPitch_rad()*180.0f/PI;
  float ROLL_EKF = Filter.getRoll_rad()*180.0f/PI;
  float YAW_EKF =Filter.getYaw_rad()*180.0f/PI;

  Serial.print("PITCH     |   ");Serial.println(PITCH_EKF);
  Serial.print("ROLL      |   ");Serial.println(ROLL_EKF);
  Serial.print("YAW       |   ");Serial.println(YAW_EKF);
  

}
For some reason you keep ignoring the BNO055 code that we keep asking Brian and I keep asking you about.


Wont be able to help you much more. Would be nice if you could attach the actual code you are running with the bno055 -- otherwise its just guess work on our part.
 
Just looking at your BNO055 code it looks like by just using
Code:
bno.begin()

the BNO055 is in ndof mode which puts in fusion mode with 9 degrees of freedom where the fused absolute orientation data is calculated from accelerometer, gyroscope and the magnetometer and the default axis orientation is:
Capture.PNG

Which shows the axes are not aligned according to what @brtaylor mentioned. In addition when you are in fusion mode you will only get data from the sensor when it is moving, If its stationary no data will be generated. Try the examples to see what I mean.

Also you probably should set your accel, gyro ranges.
 
No, I’m not using that acceleration, I’m using the mode that I’m getting the total accelerations even when the system is stationary, you can see it in the image I posted yesterday. I’m receiving the gravity acceleration plus any other external accelerations due motion.
In the variable declaration I had to change the axes and signs of the BNO variables because they doesn’t match with the required here initially.
In fact I receiving every variable from the sensor, the fused and not fused, I’m only using the not fused because We don’t need the absolute orientation from the sensor.
I’ve double checked the axis and they match for sure. If they were wrong, the other filters I used before didn’t work because they use the same axis distribution as here.


Just looking at your BNO055 code it looks like by just using
Code:
bno.begin()

the BNO055 is in ndof mode which puts in fusion mode with 9 degrees of freedom where the fused absolute orientation data is calculated from accelerometer, gyroscope and the magnetometer and the default axis orientation is:
View attachment 27592

Which shows the axes are not aligned according to what @brtaylor mentioned. In addition when you are in fusion mode you will only get data from the sensor when it is moving, If its stationary no data will be generated. Try the examples to see what I mean.

Also you probably should set your accel, gyro ranges.
 
The sensor tilted right about 14 degrees:
GYROX: 0
GYROY: 0
GYROZ: 0
ACCX: 0.01 m/s2
ACCY: 2.52 m/s2
ACCZ: 9.47 m/s2
As you can see, Z pointing down is positive and the gravity component to the right (Y) is positive.
If I’m accelerating inside a car with pitch 0, I got the inertial force like this:
ACCX: -1.78 m/s2
ACCY: 0
ACCZ: 9.82 m/s2
 
The sensor tilted right about 14 degrees:
GYROX: 0
GYROY: 0
GYROZ: 0
ACCX: 0.01 m/s2
ACCY: 2.52 m/s2
ACCZ: 9.47 m/s2
As you can see, Z pointing down is positive and the gravity component to the right (Y) is positive.
If I’m accelerating inside a car with pitch 0, I got the inertial force like this:
ACCX: -1.78 m/s2
ACCY: 0
ACCZ: 9.82 m/s2

No, that's not correct. An object just sitting on a table will see an apparent upward acceleration of 9.80665 m/s/s from the force of the table supporting the accelerometer. This means that with the z-axis positive down, you should see -9.80665 m/s/s on the z-axis accelerometer value. With the sensor tilted to the right, you should see some negative value for the y-axis accelerometer value up to a full -9.80665 m/s/s when the sensor is placed 90 degrees to the right. When you accelerated in your car, you should have seen a +x accelerometer value if you were speeding up and a negative accelerometer value when you are slowing down. Going back to the table analogy, when you place the sensor 90 degrees pitch down, you should see -9.80665 m/s/s.

For the gyro, with the sensor at 0 pitch and 0 roll, rotating the sensor clockwise should produce positive z-axis rotation rate. Similarly, rotating in a pitch up motion should produce positive y-axis rate and rotating in a right roll should produce positive x-axis rate.
 
Now I've adjusted the axis according to your instruction and i have:
GYRO's positive when pitching up, rolling right and rotating right.
Accelerometer negative when tilted right and front. Negative 9.80m/s/s when stationary.
Results: Same random angles values.

No, that's not correct. An object just sitting on a table will see an apparent upward acceleration of 9.80665 m/s/s from the force of the table supporting the accelerometer. This means that with the z-axis positive down, you should see -9.80665 m/s/s on the z-axis accelerometer value. With the sensor tilted to the right, you should see some negative value for the y-axis accelerometer value up to a full -9.80665 m/s/s when the sensor is placed 90 degrees to the right. When you accelerated in your car, you should have seen a +x accelerometer value if you were speeding up and a negative accelerometer value when you are slowing down. Going back to the table analogy, when you place the sensor 90 degrees pitch down, you should see -9.80665 m/s/s.

For the gyro, with the sensor at 0 pitch and 0 roll, rotating the sensor clockwise should produce positive z-axis rotation rate. Similarly, rotating in a pitch up motion should produce positive y-axis rate and rotating in a right roll should produce positive x-axis rate.
 
@brtaylor

Just finished my version of the sketch, now its been quite a while since I worked this but so accel is in m/s/s, mag is in uT and gryo is in rads/s

Getting the following then goes to nan's - I know we have seen this before at some point in time;
Code:
Num Satellites: 6
Gyro:-0.0011	-0.0033	0.0022
Mag:-125.1250	-31.5000	35.8125
Accl:0.5400	-1.7500	-9.9000
32.12	120.26	56.91
Num Satellites: 6
Gyro:-0.0033	-0.0022	0.0000
Mag:-123.6250	-29.3125	35.0000
Accl:0.5500	-1.7300	-9.9000
-63.08	129.25	-125.86
Num Satellites: 6
Gyro:-0.0011	-0.0044	0.0011
Mag:-125.1250	-32.2500	35.4375
Accl:0.5500	-1.7600	-9.8700
-41.69	67.60	106.09
Num Satellites: 6
Gyro:-0.0022	-0.0022	0.0000
Mag:-122.1875	-31.5000	36.6250
Accl:0.5600	-1.7500	-9.8100
18.21	132.15	-90.15
Num Satellites: 6
Gyro:0.0022	0.0000	0.0000
Mag:-125.1250	-31.5000	36.5625
Accl:0.5700	-1.7300	-9.8200
-44.33	-25.40	-161.41
Num Satellites: 6
Gyro:-0.0011	-0.0033	0.0022
Mag:-124.7500	-30.7500	36.1875
Accl:0.5700	-1.7500	-9.8500
-44.33	153.61	-161.41
Num Satellites: 6
Gyro:-0.0044	-0.0011	0.0011
Mag:-124.0000	-31.8750	35.0000
Accl:0.5400	-1.7300	-9.8500
16.42	102.16	34.61
Num Satellites: 6
Gyro:-0.0011	-0.0022	0.0011
Mag:-124.0000	-31.1250	35.8125
Accl:0.5600	-1.7700	-9.8700
nan	nan	nan
 
Yes, i think that's exactly what is happening to me.
Theres something else that is interfering with the filter.

@brtaylor

Just finished my version of the sketch, now its been quite a while since I worked this but so accel is in m/s/s, mag is in uT and gryo is in rads/s

Getting the following then goes to nan's - I know we have seen this before at some point in time;
Code:
Num Satellites: 6
Gyro:-0.0011	-0.0033	0.0022
Mag:-125.1250	-31.5000	35.8125
Accl:0.5400	-1.7500	-9.9000
32.12	120.26	56.91
Num Satellites: 6
Gyro:-0.0033	-0.0022	0.0000
Mag:-123.6250	-29.3125	35.0000
Accl:0.5500	-1.7300	-9.9000
-63.08	129.25	-125.86
Num Satellites: 6
Gyro:-0.0011	-0.0044	0.0011
Mag:-125.1250	-32.2500	35.4375
Accl:0.5500	-1.7600	-9.8700
-41.69	67.60	106.09
Num Satellites: 6
Gyro:-0.0022	-0.0022	0.0000
Mag:-122.1875	-31.5000	36.6250
Accl:0.5600	-1.7500	-9.8100
18.21	132.15	-90.15
Num Satellites: 6
Gyro:0.0022	0.0000	0.0000
Mag:-125.1250	-31.5000	36.5625
Accl:0.5700	-1.7300	-9.8200
-44.33	-25.40	-161.41
Num Satellites: 6
Gyro:-0.0011	-0.0033	0.0022
Mag:-124.7500	-30.7500	36.1875
Accl:0.5700	-1.7500	-9.8500
-44.33	153.61	-161.41
Num Satellites: 6
Gyro:-0.0044	-0.0011	0.0011
Mag:-124.0000	-31.8750	35.0000
Accl:0.5400	-1.7300	-9.8500
16.42	102.16	34.61
Num Satellites: 6
Gyro:-0.0011	-0.0022	0.0011
Mag:-124.0000	-31.1250	35.8125
Accl:0.5600	-1.7700	-9.8700
nan	nan	nan
 
All
Finally remembered what was causing the nan;s. dt in the cpp file is in micros needs to be in seconds.
Code:
    // get the change in time
    _dt = (float)_t/1e6;
This change is at about line 111
Now the data looks like
Code:
Gyro:0.0022	0.0000	0.0011
Mag:-36.0000	-131.8750	35.5625
Accl:-1.1500	0.2900	-9.9800
-2.91	-6.20	-136.28
Gyro:-0.0011	0.0022	-0.0011
Mag:-36.3750	-133.0000	35.5625
Accl:-1.1400	0.2700	-9.9600
-3.02	-6.24	-136.27
Gyro:0.0000	0.0011	-0.0011
Mag:-36.3750	-131.8750	34.7500
Accl:-1.1500	0.2800	-9.9900
-3.00	-6.24	-136.23
Gyro:-0.0022	0.0000	-0.0033
Mag:-36.0000	-131.8750	34.7500
Accl:-1.1500	0.2800	-9.9500
-2.99	-6.24	-136.19
 
Thank you!
Yes, that was exactly the solution we needed, i changed that variable declaration and now the system is working like a charm.
Thank you both for helping me solving this problem and answering me all my questions.

All
Finally remembered what was causing the nan;s. dt in the cpp file is in micros needs to be in seconds.
Code:
    // get the change in time
    _dt = (float)_t/1e6;
This change is at about line 111
Now the data looks like
Code:
Gyro:0.0022	0.0000	0.0011
Mag:-36.0000	-131.8750	35.5625
Accl:-1.1500	0.2900	-9.9800
-2.91	-6.20	-136.28
Gyro:-0.0011	0.0022	-0.0011
Mag:-36.3750	-133.0000	35.5625
Accl:-1.1400	0.2700	-9.9600
-3.02	-6.24	-136.27
Gyro:0.0000	0.0011	-0.0011
Mag:-36.3750	-131.8750	34.7500
Accl:-1.1500	0.2800	-9.9900
-3.00	-6.24	-136.23
Gyro:-0.0022	0.0000	-0.0033
Mag:-36.0000	-131.8750	34.7500
Accl:-1.1500	0.2800	-9.9500
-2.99	-6.24	-136.19
 
Hello! Its me again.

Im trying the system with the GPS connected and im getting nan's again.
The code without GPS works fine.
Any advise?

Not sure what your sketch looks like but would make sure you have a GPS fix before starting the fusion algorithm. See the sketch in post #728
 
The problem is exactly the same you had when it starts to show random numbers until it shows nan's numbers.

Maybe you can share your sketch to let me try it? Maybe i have something different in the main code.



Not sure what your sketch looks like but would make sure you have a GPS fix before starting the fusion algorithm. See the sketch in post #728
 
The NaNs are probably due to not getting a good fix from the GPS - as long as you made the time change the algorithm should work:

This is the sketch I am using - its a bit different than the one you posted. But isn't this for your thesis or something like that:
Code:
/*
 *
      Note that by default the axis orientation of the BNO chip looks like
      the following (taken from section 3.4, page 24 of the datasheet).  Notice
      the dot in the corner that corresponds to the dot on the BNO chip:
                         | Z axis
                         |
                         |   / X axis
                     ____|__/____
        Y axis     / *   | /    /|
        _________ /______|/    //
                 /___________ //
                |____________|/
 */
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include <EEPROM.h>
#include <uNavINS.h>
#include <ubx.h>

Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28); //3 lugar en EEPROM de la calibracion.

// a uNavINS object
uNavINS Filter;
bfs::Ubx gnss(&Serial1);
bool newGpsData;
unsigned long prevTOW;

// timers to measure performance
unsigned long tstart, tstop;
float acc_x, acc_y, acc_z;
float gyro_x, gyro_z, gyro_y;
float mag_x, mag_y, mag_z;

void setup() {
  Serial.begin(57600);
  if (!gnss.AutoBegin()) {
    Serial.println("Unable to establish communication and configure GNSS RX");
    while (1) {}
  }

  if (!bno.begin(bno.OPERATION_MODE_AMG))
  {
    /* There was a problem detecting the BNO055 ... check your connections */
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
    while (1);
  }
  //Set to axis remap p5
  //bno.setAxisRemap(bno.REMAP_CONFIG_P5);
  bno.setAxisSign(bno.REMAP_SIGN_P5);
  int eeAddress = 0;
  long bnoID;
  bool foundCalib = false;

  EEPROM.get(eeAddress, bnoID);

  adafruit_bno055_offsets_t calibrationData;
  sensor_t sensor;

  bno.getSensor(&sensor);
    if (bnoID != sensor.sensor_id)
    {
        Serial.println("\nNo Calibration Data for this sensor exists in EEPROM");
        delay(500);
    }
    else
    {
        Serial.println("\nFound Calibration for this sensor in EEPROM.");
        eeAddress += sizeof(long);
        EEPROM.get(eeAddress, calibrationData);

        //displaySensorOffsets(calibrationData);

        Serial.println("\n\nRestoring Calibration data to the BNO055...");
        bno.setSensorOffsets(calibrationData);

        Serial.println("\n\nCalibration data loaded into BNO055");
        foundCalib = true;
    }
}

void loop() {
  /* Get a new sensor event */
  sensors_event_t angVelocityData , magnetometerData, accelerometerData;

 if (gnss.Read() && gnss.num_sv() >= 3) {
    bno.getEvent(&angVelocityData, Adafruit_BNO055::VECTOR_GYROSCOPE);
    bno.getEvent(&magnetometerData, Adafruit_BNO055::VECTOR_MAGNETOMETER);
    bno.getEvent(&accelerometerData, Adafruit_BNO055::VECTOR_ACCELEROMETER);
  
    getIMU(&angVelocityData);
    getIMU(&magnetometerData);
    getIMU(&accelerometerData);

    tstart = micros();
  
    // update the filter
    Filter.update(gnss.gps_tow_s(),gnss.north_vel_mps(),gnss.east_vel_mps(),gnss.down_vel_mps(),gnss.lat_rad(),gnss.lon_rad(),gnss.alt_msl_m(), gyro_x,gyro_y,gyro_z,acc_x,acc_y,acc_z,mag_x,mag_y,mag_z);
    Serial.print(Filter.getPitch_rad()*180.0f/PI);
    Serial.print(",");
    Serial.print(Filter.getRoll_rad()*180.0f/PI);
    Serial.print(",");
    Serial.println(Filter.getYaw_rad()*180.0f/PI);

    tstop = micros();

 }

}

void getIMU(sensors_event_t* event) {
      if (event->type == SENSOR_TYPE_ACCELEROMETER) {
        //Serial.print("Accl:");
        acc_x = event->acceleration.x;
        acc_y = event->acceleration.y;
        acc_z = event->acceleration.z;
        //Serial.print(acc_x, 4); Serial.print("\t");
        //Serial.print(acc_y, 4); Serial.print("\t");
        //Serial.println(acc_z, 4);
      } 
      else if (event->type == SENSOR_TYPE_MAGNETIC_FIELD) {
        //Serial.print("Mag:");
        mag_x = event->magnetic.x;
        mag_y = event->magnetic.y;
        mag_z = event->magnetic.z;
        //Serial.print(mag_x, 4); Serial.print("\t");
        //Serial.print(mag_y, 4); Serial.print("\t");
        //Serial.println(mag_z, 4);
      }
      else if (event->type == SENSOR_TYPE_GYROSCOPE) {
        //Serial.print("Gyro:");
        gyro_x = event->gyro.x;
        gyro_y = event->gyro.y;
        gyro_z = event->gyro.z;
        //Serial.print(gyro_x, 4); Serial.print("\t");
        //Serial.print(gyro_y, 4); Serial.print("\t");
        //Serial.println(gyro_z, 4);
      }
}
 
What GPS module are you using?
The NaNs are probably due to not getting a good fix from the GPS - as long as you made the time change the algorithm should work:

This is the sketch I am using - its a bit different than the one you posted. But isn't this for your thesis or something like that:
Code:
/*
 *
      Note that by default the axis orientation of the BNO chip looks like
      the following (taken from section 3.4, page 24 of the datasheet).  Notice
      the dot in the corner that corresponds to the dot on the BNO chip:
                         | Z axis
                         |
                         |   / X axis
                     ____|__/____
        Y axis     / *   | /    /|
        _________ /______|/    //
                 /___________ //
                |____________|/
 */
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include <EEPROM.h>
#include <uNavINS.h>
#include <ubx.h>

Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28); //3 lugar en EEPROM de la calibracion.

// a uNavINS object
uNavINS Filter;
bfs::Ubx gnss(&Serial1);
bool newGpsData;
unsigned long prevTOW;

// timers to measure performance
unsigned long tstart, tstop;
float acc_x, acc_y, acc_z;
float gyro_x, gyro_z, gyro_y;
float mag_x, mag_y, mag_z;

void setup() {
  Serial.begin(57600);
  if (!gnss.AutoBegin()) {
    Serial.println("Unable to establish communication and configure GNSS RX");
    while (1) {}
  }

  if (!bno.begin(bno.OPERATION_MODE_AMG))
  {
    /* There was a problem detecting the BNO055 ... check your connections */
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
    while (1);
  }
  //Set to axis remap p5
  //bno.setAxisRemap(bno.REMAP_CONFIG_P5);
  bno.setAxisSign(bno.REMAP_SIGN_P5);
  int eeAddress = 0;
  long bnoID;
  bool foundCalib = false;

  EEPROM.get(eeAddress, bnoID);

  adafruit_bno055_offsets_t calibrationData;
  sensor_t sensor;

  bno.getSensor(&sensor);
    if (bnoID != sensor.sensor_id)
    {
        Serial.println("\nNo Calibration Data for this sensor exists in EEPROM");
        delay(500);
    }
    else
    {
        Serial.println("\nFound Calibration for this sensor in EEPROM.");
        eeAddress += sizeof(long);
        EEPROM.get(eeAddress, calibrationData);

        //displaySensorOffsets(calibrationData);

        Serial.println("\n\nRestoring Calibration data to the BNO055...");
        bno.setSensorOffsets(calibrationData);

        Serial.println("\n\nCalibration data loaded into BNO055");
        foundCalib = true;
    }
}

void loop() {
  /* Get a new sensor event */
  sensors_event_t angVelocityData , magnetometerData, accelerometerData;

 if (gnss.Read() && gnss.num_sv() >= 3) {
    bno.getEvent(&angVelocityData, Adafruit_BNO055::VECTOR_GYROSCOPE);
    bno.getEvent(&magnetometerData, Adafruit_BNO055::VECTOR_MAGNETOMETER);
    bno.getEvent(&accelerometerData, Adafruit_BNO055::VECTOR_ACCELEROMETER);
  
    getIMU(&angVelocityData);
    getIMU(&magnetometerData);
    getIMU(&accelerometerData);

    tstart = micros();
  
    // update the filter
    Filter.update(gnss.gps_tow_s(),gnss.north_vel_mps(),gnss.east_vel_mps(),gnss.down_vel_mps(),gnss.lat_rad(),gnss.lon_rad(),gnss.alt_msl_m(), gyro_x,gyro_y,gyro_z,acc_x,acc_y,acc_z,mag_x,mag_y,mag_z);
    Serial.print(Filter.getPitch_rad()*180.0f/PI);
    Serial.print(",");
    Serial.print(Filter.getRoll_rad()*180.0f/PI);
    Serial.print(",");
    Serial.println(Filter.getYaw_rad()*180.0f/PI);

    tstop = micros();

 }

}

void getIMU(sensors_event_t* event) {
      if (event->type == SENSOR_TYPE_ACCELEROMETER) {
        //Serial.print("Accl:");
        acc_x = event->acceleration.x;
        acc_y = event->acceleration.y;
        acc_z = event->acceleration.z;
        //Serial.print(acc_x, 4); Serial.print("\t");
        //Serial.print(acc_y, 4); Serial.print("\t");
        //Serial.println(acc_z, 4);
      } 
      else if (event->type == SENSOR_TYPE_MAGNETIC_FIELD) {
        //Serial.print("Mag:");
        mag_x = event->magnetic.x;
        mag_y = event->magnetic.y;
        mag_z = event->magnetic.z;
        //Serial.print(mag_x, 4); Serial.print("\t");
        //Serial.print(mag_y, 4); Serial.print("\t");
        //Serial.println(mag_z, 4);
      }
      else if (event->type == SENSOR_TYPE_GYROSCOPE) {
        //Serial.print("Gyro:");
        gyro_x = event->gyro.x;
        gyro_y = event->gyro.y;
        gyro_z = event->gyro.z;
        //Serial.print(gyro_x, 4); Serial.print("\t");
        //Serial.print(gyro_y, 4); Serial.print("\t");
        //Serial.println(gyro_z, 4);
      }
}
 
Back
Top