MAVLINKHUD

Overview

The AHRS (Attitude Heading Reference System) parameters control the fundamental orientation logic of the autopilot. This library is responsible for determining "Which way is Up" and "Which way is North."

While the modern Extended Kalman Filter (EKF) does the heavy lifting for state estimation, the AHRS library manages:

  1. Board Orientation: Telling the software how the flight controller is mounted relative to the vehicle frame.
  2. Estimator Selection: Choosing between EKF2, EKF3, or the legacy DCM (Direction Cosine Matrix) filter.
  3. Fallback Logic: Providing a backup attitude solution if the EKF fails or diverges.

Key Concepts

1. Board Orientation (AHRS_ORIENTATION)

This is the most critical parameter in setup. If this is wrong, the vehicle will flip over instantly on takeoff.

  • It defines the rotation of the flight controller board relative to the vehicle's forward direction.
  • Example: If the USB port points to the right wing, you likely need YAW_90.

2. Estimator Type (AHRS_EKF_TYPE)

ArduPilot supports multiple estimator backends.

  • 0: Disabled (DCM only). Not recommended for modern GPS flight.
  • 2: EKF2 (Legacy, 22-state). Stable, widely used in older versions.
  • 3: EKF3 (Modern, 24-state). Supports newer features like Moving Baseline Yaw, Optical Flow, and Visual Odometry. Default for 4.1+.

3. Custom Rotations

If standard 90-degree increments are insufficient (e.g., mounting on a 45-degree arm), the AHRS_CUSTOM_ROLL, PITCH, and YAW parameters (or CUSTOM_ORIENTATION group) allow for precise alignment.

Parameter Breakdown

  • AHRS_ORIENTATION: Board rotation enum (0=None, 2=Yaw90, 8=Roll180, etc.).
  • AHRS_EKF_TYPE: Active state estimator selector.
  • AHRS_GPS_USE: Determines if the legacy DCM filter is allowed to use GPS for correction.
  • AHRS_TRIM_X / Y: (Radians) Internal trim states for level horizon. Usually set via "Calibrate Level".

Integration Guide

Setting Orientation

  1. Check Arrow: Look for the arrow on your flight controller case.
  2. Mount: Secure the board.
  3. Configure: If the arrow points Forward, AHRS_ORIENTATION = 0. If Right, AHRS_ORIENTATION = 2 (Yaw 90).
  4. Verify: Open the HUD in your GCS. Tilt the vehicle nose DOWN. The HUD horizon should move UP. Tilt Right, HUD moves Left. If it moves incorrectly, your orientation is wrong.

Developer Notes

  • Library: libraries/AP_AHRS
  • Classes: AP_AHRS_DCM, AP_AHRS_NavEKF.
  • Redundancy: The AHRS library often runs the DCM filter in the background as a "sanity check" for the EKF. If the EKF "blows up" (diverges), the system may failover to the DCM (Msg: "EKF Fail, switching to DCM").

AHRS_COMP_BETA

Default 0.1
Range 0.001 0.5

AHRS Velocity Complementary Filter Beta Coefficient (AHRS_COMP_BETA)

Description

Controls the weighting between GPS data and air data for ground velocity estimation.

Tuning & Behavior

  • Default Value: 0.1
  • Range: 0.001 to 0.5
  • A larger beta value increases reliance on air data (airspeed/heading).
  • A smaller beta value increases reliance on GPS data.

AHRS_CUSTOM_ROLL

deg
Default 0
Range -180 180

Board orientation roll offset (AHRS_CUSTOM_ROLL)

Description

Fine-tuning for the autopilot mounting angle in the roll axis.

Tuning & Behavior

  • Default Value: 0 deg
  • Range: -180 to 180 deg
  • Only active if AHRS_ORIENTATION is set to 100 (Custom).

AHRS_CUSTOM_YAW

deg
Default 0
Range -180 180

Board orientation yaw offset (AHRS_CUSTOM_YAW)

Description

Fine-tuning for the autopilot mounting angle in the yaw axis.

Tuning & Behavior

  • Default Value: 0 deg
  • Range: -180 to 180 deg
  • Only active if AHRS_ORIENTATION is set to 100 (Custom).

AHRS_EKF_TYPE

Default 3

Use NavEKF Kalman filter version (AHRS_EKF_TYPE)

Description

Selects the primary Extended Kalman Filter (EKF) version for flight estimation.

Tuning & Behavior

  • Default Value: 3 (EKF3)
  • Values: 0:Disabled, 2:Enable EKF2, 3:Enable EKF3, 11:ExternalAHRS
  • EKF3 is the modern standard for ArduPilot.

AHRS_GPS_GAIN

Default 1.0
Range 0.0 1.0

AHRS GPS gain (AHRS_GPS_GAIN)

Description

Weighting of GPS data for correcting the attitude estimate.

Tuning & Behavior

  • Default Value: 1.0
  • Range: 0.0 to 1.0
  • Critical for Plane safety during coordinated turns.

AHRS_GPS_MINSATS

Default 6
Range 0 10

AHRS GPS Minimum satellites (AHRS_GPS_MINSATS)

Description

Threshold for GPS satellite count required for velocity-based attitude correction.

Tuning & Behavior

  • Default Value: 6
  • Range: 0 to 10

AHRS_GPS_USE

Default 1
Range 0 2

AHRS use GPS for DCM navigation (AHRS_GPS_USE)

Description

Switch between GPS-aided navigation and pure dead-reckoning.

Tuning & Behavior

  • Default Value: 1 (Use GPS for DCM position)
  • Values: 0:Disabled, 1:Use GPS for DCM position, 2:Use GPS for DCM position and height

AHRS_OPTIONS

Default 0

Optional AHRS behaviour (AHRS_OPTIONS)

Description

Bitmask for advanced AHRS configuration, primarily controlling fallback logic.

Tuning & Behavior

  • Default Value: 0
  • Bitmask:
    • 0: DisableDCMFallbackFW
    • 1: DisableDCMFallbackVTOL
    • 2: DontDisableAirspeedUsingEKF

AHRS_ORIENTATION

Default 0
Range 0 43

Board Orientation (AHRS_ORIENTATION)

Description

Software rotation for the flight controller mounting orientation.

Tuning & Behavior

  • Default Value: 0 (None)
  • Common Values: 0:None, 1:Yaw45, 2:Yaw90, 4:Yaw180, 8:Roll180, 100:Custom
  • Requires reboot and re-leveling after change.

AHRS_RP_P

Default 0.2
Range 0.1 0.4

AHRS RP_P (AHRS_RP_P)

Description

Proportional gain for roll and pitch attitude correction using accelerometer data.

Tuning & Behavior

  • Default Value: 0.2
  • Range: 0.1 to 0.4
  • Higher values correct tilt errors faster but are more sensitive to vibration.

AHRS_WIND_MAX

m/s
Default 0.0
Range 0 127

Maximum wind (AHRS_WIND_MAX)

Description

Safety limit for the discrepancy between groundspeed and airspeed, providing redundancy against airspeed sensor failure.

Tuning & Behavior

  • Default Value: 0.0 m/s (Disabled)
  • Range: 0 to 127 m/s

AHRS_YAW_P

Default 0.2
Range 0.1 0.4

Yaw P (AHRS_YAW_P)

Description

Proportional gain for heading correction using compass or GPS data.

Tuning & Behavior

  • Default Value: 0.2
  • Range: 0.1 to 0.4
  • Higher values track heading sources more aggressively.