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.
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>
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>
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>
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
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