Skip to content

[Bug] EKF2_DECL_TYPE description doesn't match the code: EKF2_MAG_DECL is ignored unless bit 1 is set #29196

Open

Description

@palvarben

Describe the bug

Describe the bug

The description of EKF2_DECL_TYPE (params_magnetometer.yaml) says:

0 : Set to true to use the declination from the geo_lookup library when the GPS position becomes available, set to false to always use the EKF2_MAG_DECL value.
1 : Set to true to save the EKF2_MAG_DECL parameter to the value returned by the EKF when the vehicle disarms.

The behaviour is different:

  1. With EKF2_DECL_TYPE = 0, EKF2_MAG_DECL is ignored and a declination of 0° is used, although the description says bit 0 cleared means "always use the EKF2_MAG_DECL value".
  2. EKF2_MAG_DECL is only used when bit 1 is set (EKF2_DECL_TYPE = 2 or 3).
  3. EKF2_MAG_DECL is saved without any disarm. The description says the value is saved "when the vehicle disarms", but in the test the board was never armed, so a disarm never happened. As soon as a WMM declination was available (here after setting an origin), it was written to EKF2_MAG_DECL in the same boot (confirmed with a debug print in EKF2). The new value was only visible after a reboot.

To reproduce

Test without GPS, board static in the same orientation for all runs, never armed. EKF2_MAG_DECL set to 30 before each run. After each reboot: waited for cs_yaw_align and cs_mag_hdg, then read the yaw from ATTITUDE. In runs 5–8, an origin was set to trigger the WMM lookup:

commander set_ekf_origin <lat> <lon> <alt>

Declination applied = yaw − yaw of run 1 (the 0° baseline). The values in the declination applied column are rounded.

Run EKF2_DECL_TYPE Origin set Yaw Declination applied EKF2_MAG_DECL after the run Source used
1 0 no −93° 0° 30 (unchanged) none (0)
2 1 no −93° 0° 30 (unchanged) none (0)
3 2 no −63° +30° 30 (unchanged) EKF2_MAG_DECL
4 3 no −63° +30° 30 (unchanged) EKF2_MAG_DECL
5 0 yes −93° 0° 30 (unchanged) none (0)
6 1 yes −97° −4° 30 (unchanged) WMM
7 2 yes −97° −4° −3.95 (overwritten) WMM value (EKF2_MAG_DECL was overwritten with it)
8 3 yes −97° −4° −3.95 (overwritten) WMM
  • Runs 1 and 5: with EKF2_DECL_TYPE = 0, EKF2_MAG_DECL (30) is not used. This contradicts "set to false to always use the EKF2_MAG_DECL value".
  • Runs 3 and 4: EKF2_MAG_DECL is used only when bit 1 is set.
  • Runs 7 and 8: with bit 1 and a WMM value, EKF2_MAG_DECL is overwritten in the same boot, without arming. A debug print in the save block confirmed the write in both runs (wmm -3.95, param 30.00). In QGC the new value only appeared after a reboot.

Aditional information

Expected behaviour

The description should match the actual behaviour:

EKF2 uses the first of these that applies:

  1. Bit 0 set and a global position is available: the declination from the World Magnetic Model (WMM) at that position.
  2. Bit 1 set: EKF2_MAG_DECL. As soon as a global position is available, EKF2 overwrites EKF2_MAG_DECL with the WMM declination for that position (whether bit 0 is set or not, and independent of arming or disarming). A manually configured value is therefore only used until a position is available.
  3. Otherwise: 0.

To use a manual declination on a vehicle without a position source, set bit 1 and enter the value in EKF2_MAG_DECL.

Bit labels:

  • 0: Use WMM declination when a position is available
  • 1: Use EKF2_MAG_DECL, and store the WMM declination in it when a position is available

Flight Log / Additional Information

Version

PX4 v1.17.0. The code is unchanged on main.

Hardware

Pixhawk 6X, external DroneCAN magnetometer, no GNSS

Activity

  1. added
    status:needs-triageAuto-assigned to new issues and removed after maintainers review it and assign the specific label.
    on Oct 13, 2026
  2. changed the title [-][Bug][/-] [+][Bug] EKF2_DECL_TYPE description doesn't match the code: EKF2_MAG_DECL is ignored unless bit 1 is set[/+] on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:needs-triageAuto-assigned to new issues and removed after maintainers review it and assign the specific label.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions