PX4 EKF2 Heading Instability Issue

Hello,

I am currently developing an outdoor multirotor platform based on PX4 Autopilot running on a Raspberry Pi (PilotPi), and I would like to share a detailed summary of the troubleshooting steps I have taken so far regarding a persistent EKF2 “Heading estimate not stable” preflight failure.

System Overview

  • Autopilot: PX4 (EKF2)

  • Companion / Host: Raspberry Pi (Ubuntu)

  • IMU: ICM42605 (SPI)

  • Barometer: MS5611 (I2C, Internal)

  • Magnetometers:

    • MAG0: IST8310 (I2C, Internal)

    • MAG1: QMC5883 (I2C, external, integrated in GPS module)

  • GPS: BZ-251 (u-blox M10, UBX protocol, 10 Hz)


GPS Verification

  • GPS was tested independently on the Raspberry Pi using /dev/ttySC0 @ 115200.

  • Confirmed valid NMEA output.

  • PX4 GPS driver was tested with both protocols:

    • gps start -p nmea → no valid data

    • gps start -p ubxsuccessful

  • PX4 reports:

    • Fix type: 3

    • Satellites used: 21

    • Position, velocity, and timing data valid

  • Conclusion: GPS is working correctly and publishing valid data


EKF2 and Performance Validation

  • EKF2 status shows stable timing:

    • EKF rate: 200 Hz

    • Average execution time: ~10 µs

  • Work queue monitoring confirms no scheduling overruns.

  • Conclusion: CPU performance and scheduling are not the cause of the issue


Magnetometer Investigation

IST8310 (MAG0)

  • Detected correctly by PX4

  • Calibration repeatedly fails due to severe noise

  • EKF2 consistently rejects magnetometer data

  • Known issue with IST8310 noise characteristics confirmed during testing

QMC5883 (MAG1)

  • Detected on I2C bus and visible via listener sensor_mag

  • Priority and calibration parameters verified

  • Despite this, EKF2 does not accept it as a valid yaw source

  • Heading remains unavailable (heading = NaN)

  • PX4 continues to report:

    • Preflight Fail: heading estimate not stable

    • Found 0 compass (required: 1)


Configuration Attempts

  • Verified magnetometer priority parameters

  • Attempted to force EKF2 magnetometer usage

  • Confirmed that EKF2 is running with valid local and global position estimates

  • Tested indoor and outdoor environments

  • Verified that the issue persists even with a valid GPS fix


Current Conclusion

  • EKF2 requires a reliable yaw observation source for arming

  • In the current configuration:

    • IST8310 is rejected due to noise

    • QMC5883 is not accepted as a valid EKF2 yaw source

    • No dual-GPS yaw is available

  • As a result, PX4 cannot produce a stable heading estimate and blocks arming


Please let me know if you need any additional logs, parameters, or test results.

Hi there!

Is this an internal mag? If so, I would advise against using it as a navigation source, as they can be very noisy.



This seems very strange. Are you sure that you are not seeing the other mag? Could you paste the output here?
If it has no heading, it will not be accepted by EKF2.


In general, this problem is well known and mostly caused by the way the hardware is built. Generally, try to increase the distance of the mag from any power lines, metal, or radio stuff.
Or, to get around it, try moving the drone around a bit and the error will most likely go away.

1 Like

I don’t use Internal MAG because of noise. I changed extern MAG from QMC5883 to IST8310.

System Information

  • Flight Controller:
  • Firmware: PX4 (version TBD)
  • GPS Module: Pixhawk 4 GPS Module(UART + I2C)

GPS Wiring

Connected pins

  • VCC_5V, VDD_3V3
  • TX / RX
  • SDA / SCL
  • GND

Not connected

  • safety_switch
  • safety_switch_led
  • buzzer-

Only the essential power and communication pins are connected.


EKF Status

Output of pxh> ekf2 status:

ekf2:0 EKF dt: 0.0100s, attitude: 1, local position: 0, global position: 0
ekf2: EKF update: 1695 events, 23826us elapsed, 14.06us avg, min 6us max 113us 8.072us rms
ekf2: IMU message missed: 0 events

SD Card and Logging Issue

  • SD card is successfully mounted
  • No flight log files are created
  • SDLOG_MODE is set to From boot until shutdown
  • When reading the SD card on a PC, no log files are present

Questions

  1. If the SD card is mounted correctly and SDLOG_MODE is set to From boot until shutdown,
  2. what could prevent flight logs from being generated?
  3. be the reason why no logs are recorded?
  4. Why won’t my multicoptor arm?
  1. Do you use a compliant SD card: Basic Concepts | PX4 Guide (main) ?
  2. can you check the status of logger: logger status in the mavlink shell?
  3. Having Preflight Fails prevents you from arming and you should not as the risk for a crash is increased.