MAVLINKHUD

GNSS & Magnetometry: State Estimation Sensors

CRITICAL An autonomous vehicle is a robot that makes decisions based on where it thinks it is. If the GPS drifts 5 meters, the drone moves 5 meters. If the Compass drifts 20 degrees, the drone spirals out of control. The sensors define the reality for the computer.

1. GNSS Generations: The Multipath Revolution

For years, the u-blox Neo-M8N was the industry standard. It is now obsolete. The shift to the M10 engine is not just an upgrade; it is a generational leap in reliability.

1.1 u-blox M8 (Legacy)

  • Architecture: Could track 3 constellations simultaneously (usually GPS + GLONASS + Galileo).
  • Sensitivity: Good for open fields.
  • The Failure Mode: Multipath Interference. In urban environments (near buildings) or under tree canopies, GPS signals bounce off surfaces. The M8 struggles to distinguish the direct signal from the reflected "echo." Since the echo has traveled further, the timing is off, and the GPS solution jumps ("glitches").

1.2 u-blox M10 (The Standard)

  • Architecture: Tracks 4 constellations simultaneously (Adds BeiDou).
  • Satellite Count: A typical M8 sees 12-16 satellites. An M10 in the same spot sees 30+.
  • The Physics: More satellites means better geometry (lower HDOP).
  • The Killer Feature: The M10 chip has advanced RF front-ends and algorithms specifically designed to filter out Multipath signals.
  • Real World Result: The drone holds position under a tree or next to a wall where an M8 would wander or lose lock entirely.

2. The Compass Problem: Resistive vs. Inductive

The Magnetometer (Compass) is the most hated sensor in the drone world. It is prone to interference and calibration errors. However, how the sensor works determines whether it will work for you.

2.1 Anisotropic Magnetoresistive (AMR)

  • Common Chips: QMC5883L, IST8310.
  • The Physics: The electrical resistance of a permalloy film changes when exposed to a magnetic field.
  • The Fatal Flaw: Resistance also changes with Temperature.
  • The Scenario: You calibrate the compass on your bench at 22°C. You fly on a sunny day. The board heats up to 45°C. The resistance changes. The sensor thinks the magnetic field has rotated.
  • The Consequence: Toilet Bowling. The FC thinks the drone is facing North-East when it is facing North. It tries to correct, entering a growing spiral.

2.2 Magneto-Inductive

  • Common Chip: PNI RM3100.
  • The Physics: It uses a solenoid coil as the inductor in an oscillation circuit. The magnetic field changes the inductance of the core, which shifts the frequency of the oscillation.
  • The Advantage: It measures Time (Frequency), not Resistance. Time does not drift with temperature.
  • Verdict: The RM3100 is virtually immune to thermal drift. For any professional or expensive rig, this sensor is mandatory.

3. Dealing with Interference (EMI)

The #1 cause of "Compass Variance" errors is the drone interfering with itself.

3.1 Ampere's Law & Twisted Pairs

  • The Physics: Any current flowing through a wire generates a magnetic field around it.
  • The Problem: The battery wires carrying 50 Amps to the ESCs create a massive magnetic field that swamps the Earth's weak magnetic field.
  • The Fix: Twist the Positive and Negative wires together tightly.
  • Why: The current flows in opposite directions in the two wires. The magnetic field from the positive wire is effectively canceled by the equal-and-opposite field from the negative wire. This simple mechanical step reduces noise floor by 90%.

3.2 The Inverse Cube Law

  • The Physics: The strength of a magnetic dipole field drops off with the cube of the distance (1/r³).
  • The Practicality: Distance is your best filter.
    • Mounting the compass flat on the top plate (1cm from PDB) = 100% Interference.
    • Mounting the compass on a 5cm mast = 0.8% Interference.
  • Rule: Always use a GPS mast. If you are building a small drone where a mast isn't possible, use a rear-mounted TPU holder to get the GPS/Compass as far from the power wires as possible.

4. ArduPilot Integration: Key Parameters

GPS_GNSS_MODE

  • Configuring Constellations: This bitmask tells the u-blox chip which satellites to listen to.
  • Recommendation: Set to 65 (GPS + SBAS + Galileo + BeiDou + GLONASS). Use all available constellations for maximum redundancy.

COMPASS_ORIENT

  • The #1 Setup Error: If your compass arrow points forward but the chip is mounted upside-down (common in GPS pucks), you must tell ArduPilot.
  • The Check: If the HUD moves correctly in Pitch/Roll but Yaw drifts or spins, your COMPASS_ORIENT is wrong.
  • Common Setting: 0 (None) if arrow is forward/up. 8 (Roll 180) if arrow is forward/down.

EKF3_CHECK_SCALE

  • The "Compass Variance" Trigger: ArduPilot's EKF monitors the "Innovation" (Error) between the GPS heading and the Compass heading.
  • The Threshold: If the error exceeds this scale (default 100-150%), the EKF declares the compass "Bad" and triggers a failsafe.
  • Diagnosis: If you get "Compass Variance" warnings in flight, do not increase this limit. It means your compass is physically mounted too close to power wires (Mag Interference). Fix the build, not the parameter.