Skip to content

修改磁场模型,采用与px4飞控相同的磁场模型WMM-2020(Port WMM-2020 magnetic model from PX4 for EarthUtils) - #177

Closed
lql2511 wants to merge 1 commit into
Cosys-Lab:mainfrom
lql2511:port/wmm2020-v3.3
Closed

lql2511 wants to merge 1 commit into
Cosys-Lab:mainfrom
lql2511:port/wmm2020-v3.3

Conversation

@lql2511

@lql2511 lql2511 commented Oct 14, 2026 •

Copy link
Copy Markdown

Summary

Replace AirSim's dipole magnetic field model with the WMM-2020 lookup
table model used by PX4, so that HIL_SENSOR magnetic output matches
PX4's behavior.

Changes

  • Add AirLib/include/common/WorldMagneticModel.hpp (ported from PX4, BSD 3-Clause)
  • Update EarthUtils::getMagField() to use WMM-2020 declination/inclination/strength
  • Keep the legacy dipole implementation as a comment for reference

Coordinate convention

Output follows the NED frame expected by PX4 HIL_SENSOR:

  • X = H * cos(D)
  • Y = H * sin(D)
  • Z = F * sin(I) (positive Z is down)

Testing

  • Project builds successfully
  • Magnetic field output compared against PX4 reference values
  • Simulation tested

License

PX4's WMM-2020 code is BSD 3-Clause, compatible with AirSim's MIT license.

@WouterJansen

Copy link
Copy Markdown
Contributor

Thank you! I will be manually redoing this update as I prefer it to use WMM-2025 and include some unit testings.

WouterJansen added a commit that referenced this pull request Nov 13, 2026
Reworked from PR #177 by lql2511 (which ported PX4's WMM-2020 tables):
- WMM-2020 expired at the end of 2024, so the tables are regenerated from
  the official WMM-2025 coefficients (NOAA NCEI/BGS, public domain),
  evaluated at 2027.5 (middle of the 2025-2030 validity), in PX4's exact
  table layout. scripts/wmm/generate_wmm_tables.py synthesises the field
  directly from the coefficient file; validated by reproducing PX4's
  published WMM-2020 tables (declination/inclination identical at every
  grid point, intensity within one quantisation step).
- WorldMagneticModel.hpp: PX4's bilinear lookup (BSD-3, notice kept).
- EarthUtils::getMagFieldWMM() added next to the existing dipole model,
  instead of replacing it.
- MagnetometerSimpleParams: new ReferenceSource_WMM, now the default;
  selectable per sensor in settings.json with "ReferenceSource":
  "WMM" | "Dipole" | "Constant".
- Standalone MSVC /W4 test: clean; mid-latitude error vs the exact model
  ~0.3 deg and ~0.3% in strength (10 degree grid, same as PX4).
- docs/sensors.md, CHANGELOG, THIRD_PARTY_LICENSES (PX4 BSD-3, WMM public
  domain) updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants