Skip to content

Commit e57b8f6

Browse files
committed
AP_NavEKF3: load hover Z-bias correction from INS params at init
Load _accelBiasHoverZ_correction from INS_ACC_VRFB_Z parameters during InitialiseFilter() instead of initializing to zero. This ensures the Replay tool (which has no vehicle code to call setHoverZBiasCorrection) gets the correct correction values from the log's parameter set. Without this, if a previous flight saved a non-zero bias to INS params, the recording would apply the correction but Replay would not, causing deterministic mismatch in all EKF outputs.
1 parent bd13c5f commit e57b8f6

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

libraries/AP_DAL/examples/AP_DAL_Standalone/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <AP_NavEKF2/AP_NavEKF2.h>
88
#include <AP_NavEKF3/AP_NavEKF3.h>
99
#include <AP_Logger/AP_Logger.h>
10+
#include <AP_InertialSensor/AP_InertialSensor.h>
1011

1112
void AP_Param::setup_object_defaults(void const*, AP_Param::GroupInfo const*) {}
1213

@@ -21,6 +22,11 @@ void *nologger = nullptr;
2122
AP_Logger &AP::logger() {
2223
return *((AP_Logger*)nologger); // this is not usually a good idea...
2324
}
25+
26+
void *noins = nullptr;
27+
AP_InertialSensor &AP::ins() {
28+
return *((AP_InertialSensor*)noins); // link stub only
29+
}
2430
void AP_Logger::WriteBlock(void const*, unsigned short) {}
2531

2632
class AP_HAL_DAL_Standalone : public AP_HAL::HAL {

libraries/AP_NavEKF3/AP_NavEKF3.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <AP_HAL/AP_HAL.h>
66

77
#include <GCS_MAVLink/GCS.h>
8+
#include <AP_InertialSensor/AP_InertialSensor.h>
89
#include <AP_Logger/AP_Logger.h>
910
#include <AP_Vehicle/AP_Vehicle_Type.h>
1011
#include <AP_BoardConfig/AP_BoardConfig.h>
@@ -816,10 +817,18 @@ bool NavEKF3::InitialiseFilter(void)
816817
// breaking the feedback loop between learning and correction. The INS parameter
817818
// may be updated by learning during flight, but only the frozen value is used
818819
// for correction.
819-
// Initialize all IMU corrections to zero
820-
// Vehicle code will set actual corrections via setHoverZBiasCorrection()
821-
for (uint8_t i = 0; i < INS_MAX_INSTANCES; i++) {
822-
_accelBiasHoverZ_correction[i] = 0.0f;
820+
// Load from INS parameters so Replay (which has no vehicle code) gets the
821+
// correct correction value. Vehicle code may override via
822+
// setHoverZBiasCorrection() based on its learning mode setting.
823+
{
824+
const auto &real_ins = AP::ins();
825+
for (uint8_t i = 0; i < INS_MAX_INSTANCES; i++) {
826+
constexpr float MAX_HOVER_BIAS_CORRECTION = 0.3f;
827+
_accelBiasHoverZ_correction[i] = constrain_float(
828+
real_ins.get_accel_vrf_bias_z(i),
829+
-MAX_HOVER_BIAS_CORRECTION,
830+
MAX_HOVER_BIAS_CORRECTION);
831+
}
823832
}
824833

825834
// check if there is enough memory to create the EKF cores

0 commit comments

Comments
 (0)