Commit Graph
40 Commits
Author SHA1 Message Date
Peter Barker 5ab4cac340 AP_Compass: use the shared SITL compass transformation for SIM offsets
The simulated sensor subtracts SIM_MAGn_OFS from the field it reports
and then rotates and scales it, so the offset a compass wants is that
same value put through the same transformation.  Expose what the SIM
AHRS backend needs to work that out: whether an instance's field
reaches us unrotated, and which device id sits behind a priority index.
2026-09-04 09:29:27 +10:00
Peter BarkerandClaude Opus 5 a78ff48a62 AP_Compass: add a feature gate for copy-from-EKF calibration
AP_COMPASS_LEARN_COPY_FROM_EKF_ENABLED, defaulting to
COMPASS_LEARN_ENABLED && AP_AHRS_ENABLED, so the disarm-time copying of
EKF-learned offsets can be compiled out on its own.

save_ekf_learned_offsets() moves out of the COMPASS_LEARN_ENABLED block
in Compass_learn.cpp so the two are genuinely separable; the in-flight
learner drags in the EKF-GSF yaw estimator, which this does not need.

Verified with nm: Compass::save_ekf_learned_offsets is present in a
default build and absent when the define is 0, with COMPASS_LEARN_ENABLED
still enabled.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 09:29:27 +10:00
Peter BarkerandClaude Opus 5 84db702b81 AP_Compass: log an event when EKF-learned offsets are saved
The EKF frequently has nothing to offer when COMPASS_LEARN=2 asks for
its learned offsets: it must have completed an in-flight magnetic field
initialisation, be estimating the field states, be using a healthy
compass, and have converged its state variances.  Until now a failure
to meet any of that was silent, and indistinguishable in a log from the
feature simply not being enabled.

Log EKF_MAG_OFFSETS_SAVED when we do save something.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 09:29:27 +10:00
Peter BarkerandClaude Opus 5 1f1072c46d AP_Compass: add save_ekf_learned_offsets
Moves the "save compass offsets learned by the EKF" logic out of the
vehicle AP_Arming subclasses, where it was duplicated verbatim in
Copter, Sub and Blimp, and into the library that owns the parameters
being written.

The AHRS is now checked for health before its estimates are copied.

Note the loop over COMPASS_MAX_INSTANCES is not redundant: a single EKF
core only ever returns offsets for its own selected compass, but with
EK3_AFFINITY compass affinity each core takes a different compass and
the frontend asks every core for each instance in turn.

Also drops a stale reference to ::learn_offsets, which no longer
exists, and corrects the COMPASS_LEARN description, which still
advertised the removed compass-only fixed wing method.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 09:29:27 +10:00
Peter Barker 57688f5e03 AP_Compass: use get_roll_deg in place of degrees(get_roll_rad) etc. 2025-08-05 09:00:08 +09:00
Peter Barker 521de42cf7 AP_Compass: rename AHRS get_roll etc accessors to include _rad 2025-06-05 17:28:41 +10:00
Peter Barker 6298f7dc58 AP_Compass: make compass LearnType enum-class and parameter AP_Enum 2025-01-29 19:21:59 +11:00
Peter Barker dc74f97739 AP_Compass: move logger object up to AP_Vehicle 2024-02-13 10:54:29 +11:00
Peter Barker 084b0aea24 AP_Compass: make compass.mag_cal_fixed_yaw return boolean
this method could be used from a transmitter without GCS enabled, for example
2024-02-06 11:11:27 +11:00
Peter Barker 275a667d41 AP_Compass: allow more libraries to compile with no HAL_GCS_ENABLED 2023-09-05 22:23:51 +10:00
Peter Barker 437b313544 AP_Compass: do not use GSF if any model has been clipped 2022-05-11 17:45:47 +10:00
Andrew Tridgell 2b19b8a988 AP_Compass: switched to GSF based compass learning
this makes inflight compass learning faster, more accurate and much
simpler
2021-11-01 09:00:27 +11:00
Andrew Tridgell ffe8add56d AP_Compass: mark logger Write() calls as streaming where appropriate 2021-08-18 10:20:03 +10:00
Andrew Tridgell aa0a77049e AP_Compass: fixed build warning on g++ 10.2 2021-07-27 19:50:21 +10:00
Kawamura b305b3b074 AP_Compass: Send message to gcs for compass learn 2021-05-07 08:43:20 +10:00
Peter Barker c36e06e7fa AP_Compass: add documentation for COFS, compass-learning message 2020-04-14 07:34:59 +10:00
Andrew Tridgell 8f83bf5e80 AP_Compass: fixed in-flight learning for all compasses
after recent changes only first compass was learnt

See
https://discuss.ardupilot.org/t/break-in-latest-master-in-flight-compass-calibration/52602
2020-02-25 12:40:27 +11:00
Siddharth Purohit 8d227d401a AP_Compass: modify compass driver to support consistent ordering and hotplugging 2020-02-19 13:59:53 +09:00
Peter Hall c870df0351 AP_Compass: get_time_flying in vehicle 2020-01-14 22:34:37 -07:00
Andrew Tridgell 6fd0ca36aa AP_Compass: added estimation of compass scale factor
this adds new COMPASS_SCALE, COMPASS_SCALE2 and COMPASS_SCALE3
parameters, which give the sensor scaling factor. It is used to
compensate for an incorrect scaling in a compass.

The 3D compass calibration process will set the correct value
automatically, otherwise users can set the value to a known value for
an existing compass
2019-12-03 20:48:23 +11:00
Andrew Tridgell f4576ec8f3 AP_Compass: reduce firmware size for AP_Periph 2019-08-27 10:29:56 +10:00
Andrew Tridgell 7206258587 AP_Compass: use new get_earth_field_ga() API 2019-06-03 12:21:29 +10:00
Peter Barker 5455d27e84 AP_Compass: specify floating point constants
Probably indicates compiler floating-point-constants directive isn't
working
2019-04-05 23:04:17 -07:00
Peter Barker 6fc76a32af GLOBAL: use AP::logger() and strip redundant Log_ from methods 2019-01-18 18:08:20 +11:00
Peter Barker b47733142f GLOBAL: rename DataFlash_Class to AP_Logger 2019-01-18 18:08:20 +11:00
Andrew Tridgell 70246cf954 AP_Compass: added notify events (LEDs and buzzer) for learning 2018-10-24 07:25:42 +10:00
Andrew Tridgell 23ddd994ec AP_Compass: allow multiple COMPASS_LEARN runs per boot 2018-10-24 07:25:42 +10:00
Andrew Tridgell 026089747d AP_Compass: use LEARN_NONE on learn completion
master doesn't yet have the statistical EKF learning
2018-10-24 07:25:42 +10:00
Andrew Tridgell 0a7170774a AP_Compass: allow learning of all compasses
slave secondary compasses to primary
2018-10-24 07:25:42 +10:00
Andrew Tridgell 5ac6309848 AP_Compass: enable in-flight compass learning system
using COMPASS_LEARN=3
2018-10-24 07:25:42 +10:00
Andrew Tridgell a260792e9e AP_Compass: use WITH_SEMAPHORE()
and removed usage of hal.util->new_semaphore()
2018-10-17 12:54:22 +11:00
Randy Mackay 3bec25da85 AP_Compass: resolve compiler warnings 2018-02-10 08:54:34 +09:00
Andrew Tridgell 57a3bc1397 AP_Compass: new compass learning system
this learns compass offsets using magnetic tables and compass
observations
2018-02-08 17:36:33 +11:00
Mathieu OTHACEHE 152edf7189 Global: remove mode line from headers
Using a global .dir-locals.el file is a better alternative than
reincluding the same emacs header in every file of the project.
2016-10-24 09:42:01 -02:00
Lucas De Marchi e6059f5197 AP_Compass: rename files to follow other libraries
AP_Compass.h is the main header to be exported and AP_Compass.cpp its
implementation. There's no need for an additional header.
2016-03-23 17:50:38 -03:00
dgrat f56f584233 Compass: Improved field rounding in learning
Signed-off-by: Daniel Frenzel <dgdanielf@gmail.com>
2015-07-06 11:31:58 +10:00
Tom Pittenger bf1d128d70 Compass: fix compile warnings re float constants
Also fix example sketch
2015-04-24 12:29:07 +09:00
Andrew Tridgell a871c87cad AP_Compass: use state array for compass variables 2015-03-13 18:46:15 +11:00
Andrew Tridgell 189d635493 AP_Compass: constrain compass offsets to +/- 2000
this is prompted by a user log showing NaN compass offsets, resulting
in a crash. The patch ensures we never end up with NaN offsets, and
also constrains the offsets to a reasonable limit
2014-02-16 13:33:41 +11:00
Andrew Tridgell 9bb8f73d56 Compass: split compass learning out to its own C++ file 2014-02-16 13:21:06 +11:00