Hi @Paul_Riseborough, thanks for directing me to this forum.
This question is for a non-PX4 flight controller which is using the ECL EKF by creating an Ekf() object and using the methods in estimator_interface.h.
If I understand the EKF correctly, it automatically sets an initial declination based on GPS lookup tables, and then adjusts it from there. Is that correct?
In PX4, is the declination (or a declination offset or something) saved and loaded, or is it re-discovered from scratch every time? I was thinking that saving and loading would improve start-up heading accuracy, especially for multicopters, but I don’t see any public methods to do that with.
The option to save the initial declination loaded from the geo library to the EKF2_MAG_DECL parameter on disarm so that it can be loaded as the startup default for the next power cycle is supposed to be controlled via setting of the EKF2_DECL_TYPE parameter. However inspection of the code shows that this capability has been removed from the ekf2_main.cpp so I will raise an issue against PX4/Firmware to get that reinstated
The startup value of declination to be saved on the next disarm is provided via the copy_mag_decl_deg(float *val) accessor function.
The comment on that function is misleading. It should read
// The value of magnetic declination that we wish to save to the EKF2_MAG_DECL parameter for the next startup
I will also correct the naming of copy_mag_decl_deg. Use of the copy prefix is misleading given it is only a getter function. It should be named get_mag_decl_deg.