Reefwing-Software / Reefwing-AHRS

Attitude and Heading Reference System (AHRS)
Other
43 stars 8 forks source link

Kalman and pitch #7

Closed salviador closed 11 months ago

salviador commented 11 months ago

Hi, I use Nano 33 BLE rev 2 setting in KALMAN mode, but when I write roll , pitch in serial I only get roll, pitch in nan


void setup() {
  ahrs.begin();

  ahrs.setFusionAlgorithm(SensorFusion::KALMAN  );
  ahrs.setDeclination(12.717);                     //  Sydney, Australia
}

void loop() {
  if (IMU.gyroscopeAvailable()) {  IMU.readGyroscope(data.gx, data.gy, data.gz);  }
  if (IMU.accelerationAvailable()) {  IMU.readAcceleration(data.ax, data.ay, data.az);  }
  if (IMU.magneticFieldAvailable()) {  IMU.readMagneticField(data.mx, data.my, data.mz);  }

  ahrs.setData(data);
  ahrs.update();

  Serial.print(ahrs.angles.roll , 2);
  Serial.print(",");
  Serial.print(ahrs.angles.pitch, 2);
  Serial.println();
}
reefwing commented 11 months ago

There are a few points to consider that might lead to NaN (Not a Number) results under certain conditions in the Kalman filter:

Initial Conditions and Parameters:

Division by Zero in Kalman Gain Calculation: