MAVLINKHUD

GPS Integration

Executive Summary

Global Navigation Satellite Systems (GNSS), commonly referred to as GPS, provide the absolute position reference for autonomous vehicles. While a standard phone GPS is accurate to within 5 meters, modern drone operations often require centimeter-level precision. ArduPilot supports advanced configurations including Dual GPS Blending for reliability and Real-Time Kinematic (RTK) for precision. It can even use Moving Baseline technology to calculate the drone's heading (Yaw) without a magnetic compass.

Theory & Concepts

1. Standard vs. RTK GPS: The Physics of Precision

To understand why RTK is necessary, we must understand how standard GPS works.

  • Time of Flight (Standard GPS): A satellite sends a signal stamped with the time. The receiver calculates how long the signal took to arrive (speed of light). Because the atmosphere (Ionosphere/Troposphere) slows the signal down unpredictably, this timing is always slightly "fuzzy."
    • Result: Accuracy is limited to ~2-5 meters.
  • Carrier Phase (RTK): Instead of just timing the "pings" (Code Phase), an RTK receiver counts the actual radio waves (Carrier Phase) of the 1.5GHz signal. Since the wavelength is only ~19cm, counting waves allows for millimeter-level measurement.
    • The Catch: The receiver can count waves, but it doesn't know the total number of waves (Integer Ambiguity). It needs a Base Station at a known location to tell it "I see 5,000,002 waves."
    • Result: By subtracting the Base Station's error from the Rover's measurement, atmospheric errors cancel out. Accuracy improves to ~1-2 centimeters.

2. Moving Baseline (Compass-Less Yaw)

Magnetic Compasses are the Achilles' heel of drones. They are easily confused by power lines, bridges, and even the drone's own motors. Moving Baseline GPS replaces the compass entirely.

  • The Setup: You install two GPS antennas on the drone (e.g., one on the nose, one on the tail).
  • The Logic: One GPS acts as a "Moving Base," sending corrections to the other "Rover."
  • The Magic: Because the two antennas are so close (e.g., 30cm) and share the exact same atmospheric conditions, the relative vector between them can be calculated with extreme precision (< 1cm).
  • The Result: If you know the nose is exactly 30cm in front of the tail, and you measure the vector between them, you can calculate the Heading (Yaw) using simple trigonometry. This heading is immune to magnetic interference.

3. Dilution of Precision (DOP)

You will often see "HDOP" (Horizontal Dilution of Precision) in the logs. This is a multiplier of error based on satellite geometry.

  • Bad Geometry: All satellites are clustered in one part of the sky. The triangulation triangles are skinny. Small timing errors create huge position errors.
  • Good Geometry: Satellites are spread out (North, South, East, West, Zenith). The triangles are wide.
  • Why Dual GPS Helps: Two antennas have different views of the sky. If one is blocked by the drone's body (e.g., in a bank), the other might still have a clear view, maintaining a lower HDOP.

Architecture (The Engineer's View)

1. Auto-Switching (Redundancy)

This is the default mode (GPS_AUTO_SWITCH = 1). The goal is to always use the single best sensor.

  • Logic:
    1. Fix Status: Priority 1. An RTK Fixed unit beats an RTK Float unit, which beats a 3D Lock unit.
    2. Satellite Count: Priority 2. If Fix Status is equal, the unit with more satellites wins.
  • Hysteresis: To prevent rapid toggling (which confuses the EKF), ArduPilot requires the new GPS to be "better" for a set time (e.g., 5 seconds for a 2-satellite lead).
  • Code Path: AP_GPS::update_primary().

2. GPS Blending (Accuracy)

If enabled (GPS_AUTO_SWITCH = 2), ArduPilot creates a Virtual GPS instance.

  • Logic: It calculates a weighted average of all healthy GPS units.
  • Weighting: The weight is based on the reported Accuracy (Speed Accuracy, Horizontal Accuracy, Vertical Accuracy).
    • Effect: If GPS1 reports 0.5m accuracy and GPS2 reports 1.0m, GPS1 contributes 66% to the blended solution.
  • Benefits: Smoother flight tracks and glitch resistance. If one GPS wanders, the other pulls the average back.

3. Moving Baseline (GPS Yaw)

This technique replaces the Magnetic Compass.

  • Hardware: Two GPS antennas on the drone (Rover and Base).
  • Mechanism: The "Base" sends RTCM corrections to the "Rover" over a serial wire. The "Rover" calculates the precise vector (baseline) to the "Base" with centimeter accuracy.
  • Result: Since the antennas are fixed to the frame, this vector reveals the Heading of the drone.
  • Advantage: Immune to magnetic interference (power lines, metal bridges).

Key Parameters

Parameter Default Description
GPS_AUTO_SWITCH 1 0=Disabled, 1=Use Best, 2=Blend, 4=Use Primary (if 3D fix).
GPS_BLEND_MASK 5 Which metrics to use for weighting (1=Horiz Pos, 2=Vert Pos, 4=Speed).
GPS_POS_X/Y/Z 0 Antenna position offsets. Critical for Moving Baseline calculations.
GPS_TYPE 1 1=Auto, 17=UBlox, 18=NovaTel. Setting specific types speeds up boot time.

Source Code Reference

Practical Guide: Configuring Dual GPS

Why buy two GPS units? Because redundancy prevents flyaways.

Option A: Use Best (Redundancy)

  • Parameter: GPS_AUTO_SWITCH = 1
  • Behavior: ArduPilot uses GPS1. If GPS1 loses 3D lock or its HDOP spikes, it switches to GPS2.
  • Best For: Systems with one "Good" GPS (RTK) and one "Cheap" GPS (Backup). You don't want to blend the cheap data into the good data.

Option B: Blending (Accuracy)

  • Parameter: GPS_AUTO_SWITCH = 2
  • Parameter: GPS_BLEND_MASK = 5 (Horizontal + Vertical Position)
  • Behavior: ArduPilot computes a weighted average.
  • Best For: Two identical GPS units (e.g., dual Here4).
  • Warning: Blending requires both units to report accurate error metrics. If a cheap clone GPS reports "0.1m accuracy" when it's actually drifting 5m, it will corrupt the blended solution. Only blend identical, high-quality units.