MAVLINKHUD

Overview

The COMPASS parameter group configures the Magnetometers (Electronic Compasses). Reliable heading information is critical for GPS flight modes (Loiter, Auto, RTL) to determine the vehicle's yaw relative to the world.

ArduPilot supports up to 3 compasses. COMPASS (1), COMPASS2, and COMPASS3.

Key Concepts

1. Orientation (COMPASS_ORIENT)

Most Critical Setting. If using an external GPS/Compass module, the sensor is often mounted upside down or rotated relative to the flight controller.

  • External: Set COMPASS_EXTERNAL = 1.
  • Rotation: Match the mounting (e.g., ROTATION_ROLL_180).

2. Calibration (Offsets & Scaling)

  • Offsets (COMPASS_OFS_X/Y/Z): Compensates for "Hard Iron" distortion (permanent magnets, screws, currents) on the frame.
  • Scaling (COMPASS_SCALE): Compensates for "Soft Iron" distortion (ferrous metals stretching the field) and sensor axis sensitivity differences.

3. Declination (COMPASS_DEC)

The difference between Magnetic North and True North.

  • Auto (COMPASS_AUTODEC): Recommended. Calculates declination based on GPS location table.

4. Motor Compensation (COMPASS_MOT_...)

High current in power wires creates a magnetic field that shifts the compass as throttle increases.

  • CompassMot: A calibration routine that measures this interference vs. throttle/current and subtracts it in flight.

Parameter Breakdown

  • COMPASS_ENABLE: Master switch.
  • COMPASS_LEARN: In-flight learning of offsets (Compass Learn).
  • COMPASS_USE: Trusted for navigation? (Uncheck for internal compasses with high interference).
  • COMPASS_DEV_ID: Hardware ID.

Integration Guide

Typical Setup

  1. Hardware: Mount GPS/Compass mast away from power wires/ESCs.
  2. Calibrate: Run "Onboard Mag Calibration" ("The Dance"). Rotate vehicle on all axes until progress bars fill.
  3. Verify: Check if North is North.
  4. Prioritize: Disable internal compasses (COMPASS_USE2 = 0, etc.) if they show high interference ("Compass Variance" errors).

Developer Notes

  • Library: libraries/AP_Compass
  • MagFit: Advanced 3D ellipsoid fitting is used for calibration.

COMPASS_AUTODEC

Default 1
Range 0 1

Auto Declination (COMPASS_AUTODEC)

Description

Allows ArduPilot to automatically look up the correct magnetic declination using an internal world magnetic model and your current GPS coordinates.

COMPASS_AUTO_ROT

Default 2
Range 0 3

Automatically check orientation (COMPASS_AUTO_ROT)

Description

A calibration helper that determines if the user's COMPASS_ORIENT setting matches the physical data collected during calibration.

Tuning & Behavior

  • Default Value: 2 (CheckAndFix)
  • Values: 0:Disabled, 1:CheckOnly, 2:CheckAndFix

COMPASS_CAL_FIT

Default 16
Range 4 32

Compass calibration fitness (COMPASS_CAL_FIT)

Description

Determines the "pass/fail" strictness of the compass calibration algorithm.

Tuning & Behavior

  • Default Value: 16
  • Lower values (e.g., 4) are stricter and harder to pass, but result in better heading accuracy.
  • Higher values (e.g., 32) are more relaxed and useful if you are in a location with high local magnetic interference.

COMPASS_CUS_PIT

deg
Default 0
Range -180 180

Custom orientation pitch offset (COMPASS_CUS_PIT)

Description

Precise pitch-axis compensation for custom compass mounting.

COMPASS_CUS_ROLL

deg
Default 0
Range -180 180

Custom orientation roll offset (COMPASS_CUS_ROLL)

Description

Allows for precise, degree-by-degree compensation of the compass mounting angle in the roll axis.

  • Only active if COMPASS_ORIENT is set to 100 (Custom).

COMPASS_CUS_YAW

deg
Default 0
Range -180 180

Custom orientation yaw offset (COMPASS_CUS_YAW)

Description

Precise yaw-axis (heading) compensation for custom compass mounting.

COMPASS_DEC

rad
Default 0
Range -3.142 3.142

Compass declination (COMPASS_DEC)

Description

Manual offset to correct for the difference between Magnetic North and True North at your current location.

Tuning & Behavior

  • Default Value: 0 rad
  • Range: -3.142 to 3.142 rad
  • Usually set automatically if COMPASS_AUTODEC is enabled.

COMPASS_DEV_ID

Default 0

Compass device id (COMPASS_DEV_ID)

Description

Uniquely identifies the physical magnetometer hardware (e.g., its bus type and address).

  • ReadOnly: Automatically detected by the flight controller.

COMPASS_DEV_ID2

Default 0

Compass 2 device id (COMPASS_DEV_ID2)

Description

Automatically detected hardware ID for the secondary magnetometer.

COMPASS_DEV_ID3

Default 0

Compass 3 device id (COMPASS_DEV_ID3)

Description

Hardware ID for the tertiary magnetometer.

COMPASS_DEV_ID4

Default 0

Compass 4 device id (COMPASS_DEV_ID4)

Description

Automatically detected hardware ID for the 4th magnetometer.

COMPASS_DEV_ID5

Default 0

Compass 5 device id (COMPASS_DEV_ID5)

Description

Automatically detected hardware ID for the 5th magnetometer.

COMPASS_DEV_ID6

Default 0

Compass 6 device id (COMPASS_DEV_ID6)

Description

Automatically detected hardware ID for the 6th magnetometer.

COMPASS_DEV_ID7

Default 0

Compass 7 device id (COMPASS_DEV_ID7)

Description

Automatically detected hardware ID for the 7th magnetometer.

COMPASS_DEV_ID8

Default 0

Compass 8 device id (COMPASS_DEV_ID8)

Description

Automatically detected hardware ID for the 8th magnetometer.

COMPASS_DIA

Default 1.0

Compass soft-iron diagonal (COMPASS_DIA)

Description

Correction factors for "soft-iron" distortion, which occurs when nearby metal elements distort the magnetic field rather than creating their own.

COMPASS_DIA2

Default 1.0

Compass 2 soft-iron diagonal (COMPASS_DIA2)

Description

Soft-iron correction for the secondary magnetometer.

COMPASS_DIA3

Default 1.0

Compass 3 soft-iron diagonal (COMPASS_DIA3)

Description

Soft-iron correction for the tertiary magnetometer.

COMPASS_DISBLMSK

Default 0

Compass disable driver type mask (COMPASS_DISBLMSK)

Description

Prevents ArduPilot from probing for specific magnetometer hardware types. Useful for speeding up boot times or avoiding hardware conflicts.

Tuning & Behavior

  • Default Value: 0 (Probe everything)
  • Bitmask Examples:
    • Bit 0: HMC5883
    • Bit 11: DroneCAN
    • Bit 16: RM3100

COMPASS_ENABLE

Default 1
Range 0 1

Enable Compass (COMPASS_ENABLE)

Description

Master power switch for the magnetometer library.

Tuning & Behavior

  • Default Value: 1 (Enabled)
  • Values: 0:Disabled, 1:Enabled
  • Must be enabled to collect magnetometer data or perform a compass calibration.

COMPASS_EXTERN2

Default 0
Range 0 2

Compass 2 is attached via an external cable (COMPASS_EXTERN2)

Description

Tells ArduPilot if the secondary compass is an external unit.

COMPASS_EXTERN3

Default 0
Range 0 2

Compass 3 is attached via an external cable (COMPASS_EXTERN3)

Description

Tells ArduPilot if the tertiary compass is an external unit.

COMPASS_EXTERNAL

Default 0
Range 0 2

Compass is attached via an external cable (COMPASS_EXTERNAL)

Description

Tells ArduPilot whether the compass is part of the flight controller (Internal) or located on a separate module (External, like a GPS puck).

Tuning & Behavior

  • Default Value: 0 (Internal)
  • Values: 0:Internal, 1:External, 2:ForcedExternal
  • When set to 1 or 2, COMPASS_ORIENT is used instead of the board's global AHRS_ORIENTATION.

COMPASS_FLTR_RNG

%
Default 0
Range 0 100

Range in which sample is accepted (COMPASS_FLTR_RNG)

Description

A noise-rejection filter for magnetometer data. Rejects samples that differ significantly from the recent average.

  • 0 disables the filter.

COMPASS_LEARN

Default 0
Range 0 3

Learn compass offsets automatically (COMPASS_LEARN)

Description

Enables the "Compass Learning" feature where the flight controller refines the sensor offsets in-flight by analyzing the magnetometer data as the vehicle rotates.

Tuning & Behavior

  • Default Value: 0 (Disabled)
  • Values: 0:Disabled, 1:Internal-Learning, 2:EKF-Learning, 3:InFlight-Learning
  • Useful for refining a coarse initial calibration, but should generally be disabled once offsets have stabilized.

COMPASS_MOT

mGauss/A
Default 0
Range -1000 1000

Motor interference compensation (COMPASS_MOT)

Description

Scaling factors for dynamic magnetic interference. These values determine how much the compass heading should be adjusted based on the current power level.

COMPASS_MOT2

mGauss/A
Default 0
Range -1000 1000

Compass 2 Motor interference compensation (COMPASS_MOT2)

Description

Dynamic magnetic interference compensation for the secondary magnetometer.

COMPASS_MOT3

mGauss/A
Default 0
Range -1000 1000

Compass 3 Motor interference compensation (COMPASS_MOT3)

Description

Dynamic magnetic interference compensation for the tertiary magnetometer.

COMPASS_MOTCT

Default 0
Range 0 2

Motor interference compensation type (COMPASS_MOTCT)

Description

Enables the "CompassMot" feature, which compensates for magnetic interference generated by high-current battery wires and motors.

Tuning & Behavior

  • Default Value: 0 (Disabled)
  • Values: 0:Disabled, 1:Use Throttle (Simpler), 2:Use Current (Requires accurate battery monitor)

COMPASS_ODI

Default 0.0

Compass soft-iron off-diagonal (COMPASS_ODI)

Description

Advanced soft-iron calibration values that account for cross-axis magnetic field coupling.

COMPASS_ODI2

Default 0.0

Compass 2 soft-iron off-diagonal (COMPASS_ODI2)

Description

Advanced soft-iron correction for the secondary magnetometer.

COMPASS_ODI3

Default 0.0

Compass 3 soft-iron off-diagonal (COMPASS_ODI3)

Description

Advanced soft-iron correction for the tertiary magnetometer.

COMPASS_OFFS_MAX

Default 1800
Range 500 3000

Compass maximum offset (COMPASS_OFFS_MAX)

Description

A safety threshold for magnetometer calibration. If the resulting offsets are larger than this value, the calibration will be rejected as unhealthy.

Tuning & Behavior

  • Default Value: 1800 (Default)
  • Range: 500 to 3000
  • High offsets indicate the compass is too close to significant metal masses or high-current wires.

COMPASS_OFS

mGauss
Default 0
Range -400 400

Compass offsets (COMPASS_OFS)

Description

The fundamental hard-iron calibration values for the primary magnetometer. These represent static magnetic fields within the aircraft itself.

Tuning & Behavior

  • Default Value: 0 0 0
  • Usually set automatically during the "Compass Calibration" process.
  • Note: In the codebase, this is stored as separate X, Y, Z parameters but often presented as a vector.

COMPASS_OFS2

mGauss
Default 0
Range -400 400

Compass 2 offsets (COMPASS_OFS2)

Description

Hard-iron calibration values for the secondary magnetometer.

COMPASS_OFS3

mGauss
Default 0
Range -400 400

Compass 3 offsets (COMPASS_OFS3)

Description

Hard-iron calibration values for the tertiary magnetometer.

COMPASS_OPTIONS

Default 0

Compass options (COMPASS_OPTIONS)

Description

Advanced configuration for the compass library.

Tuning & Behavior

  • Default Value: 0
  • Bitmask:
    • Bit 0: CalRequireGPS (Force GPS lock for calibration)
    • Bit 1: Allow DroneCAN replacement

COMPASS_ORIENT

Default 0

Compass orientation (COMPASS_ORIENT)

Description

Defines the software rotation for the primary compass. This is critical if the compass (often part of the GPS module) is mounted in any direction other than perfectly forward and upright.

Tuning & Behavior

  • Default Value: 0 (None)
  • Common Values: 0:None, 8:Roll180 (very common for GPS/Compass modules), 100:Custom

COMPASS_ORIENT2

Default 0

Compass 2 orientation (COMPASS_ORIENT2)

Description

Software rotation for the secondary compass.

COMPASS_ORIENT3

Default 0

Compass 3 orientation (COMPASS_ORIENT3)

Description

Software rotation for the tertiary compass.

COMPASS_PMOT1

Default 0
Range -10.0 10.0

Compass Per-Motor Compensation (COMPASS_PMOT1)

Description

COMPASS_PMOT1 is an advanced calibration setting used to cancel out magnetic interference caused by high-current wires and motors.

In some small or tightly packed drones, the battery wires or motors are so close to the compass that they "pull" the needle whenever the throttle is applied. This causes the drone's heading to drift during a punch-out. This parameter stores the learned compensation factor for the first motor in the system.

Tuning & Behavior

  • Default: 0.
  • Calibration: This value is calculated automatically by running the Compass Motor Calibration (MagCali) routine in your Ground Control Station while safely tethering the drone and varying the throttle.
  • Recommendation: Do not edit this manually. Use the GCS calibration tool to find the correct values for your specific frame.

COMPASS_PMOT2

Default 0
Range null

Compass per-motor2 Z

Note: This parameter functions identically to COMPASS_PMOT1.

COMPASS_PMOT3

Default 0
Range null

Compass per-motor3 Z

Note: This parameter functions identically to COMPASS_PMOT1.

COMPASS_PMOT4

Default 0
Range null

Compass per-motor4 Z

Note: This parameter functions identically to COMPASS_PMOT1.

COMPASS_PMOT_1

Default 0

Per-motor interference - Motor 1 (COMPASS_PMOT_1)

Description

Individual magnetic interference coefficient for the first motor.

  • Note: Subsequent parameters (PMOT_2, PMOT_3, etc.) exist for each motor.

COMPASS_PMOT_2

Default 0
Range null

Compass per-motor2 Z

Note: This parameter functions identically to COMPASS_PMOT_1.

COMPASS_PMOT_3

Default 0
Range null

Compass per-motor3 Z

Note: This parameter functions identically to COMPASS_PMOT_1.

COMPASS_PMOT_4

Default 0
Range null

Compass per-motor4 Z

Note: This parameter functions identically to COMPASS_PMOT_1.

COMPASS_PMOT_EN

Default 0
Range 0 1

Per-motor interference enable (COMPASS_PMOT_EN)

Description

Enables an advanced version of CompassMot that tracks and compensates for the magnetic interference of each individual motor, rather than the aircraft's total power draw.

COMPASS_PMOT_EXP

Default 1.0

Per-motor interference exponent (COMPASS_PMOT_EXP)

Description

Mathematical exponent used to model how magnetic interference scales with individual motor power in advanced compensation modes.

COMPASS_PRIO1_ID

Default 0

Compass 1 Priority ID (COMPASS_PRIO1_ID)

Description

Forcefully designates a specific magnetometer (by its Device ID) as the primary sensor for heading estimation.

COMPASS_PRIO2_ID

Default 0

Compass 2 Priority ID (COMPASS_PRIO2_ID)

Description

Designates a specific magnetometer as the secondary priority sensor.

COMPASS_PRIO3_ID

Default 0

Compass 3 Priority ID (COMPASS_PRIO3_ID)

Description

Designates a specific magnetometer as the tertiary priority sensor.

COMPASS_SCALE

Default 0
Range 0 1.3

Compass scale factor (COMPASS_SCALE)

Description

A sensitivity adjustment for the magnetometer. If set to 0, no scaling is applied.

COMPASS_SCALE2

Default 0
Range 0 1.3

Compass 2 scale factor (COMPASS_SCALE2)

Description

Sensitivity adjustment for the secondary magnetometer.

COMPASS_SCALE3

Default 0
Range 0 1.3

Compass 3 scale factor (COMPASS_SCALE3)

Description

Sensitivity adjustment for the tertiary magnetometer.

COMPASS_USE

Default 1
Range 0 1

Use compass for yaw (COMPASS_USE)

Description

Determines if the primary compass data is actually used by the EKF (Extended Kalman Filter) to calculate the vehicle's heading (yaw).

Tuning & Behavior

  • Default Value: 1 (Enabled)
  • If disabled, the vehicle must rely on GPS-based yaw (GHY) or other heading sources.

COMPASS_USE2

Default 1
Range 0 1

Compass 2 used for yaw (COMPASS_USE2)

Description

Determines if the secondary compass data is used by the EKF.

COMPASS_USE3

Default 1
Range 0 1

Compass 3 used for yaw (COMPASS_USE3)

Description

Determines if the tertiary compass data is used by the EKF.