Due to the failure of the magnetometer and IMU, when the EKF switches, ref_alt will suddenly change, causing the follow_target.alt to become abnormal. The solution is in TargetEstimator.cpp: replace the ref_alt altitude with home_alt.
Author: wenyijing355-cyberCreated Sep 26, 2026Updated Sep 26, 2026
Labelsstatus:needs-triage
Describe the bug
Due to the failure of the magnetometer and IMU, when the EKF switches, ref_alt will suddenly change, causing the follow_target.alt to become abnormal. The solution is in TargetEstimator.cpp: replace the ref_alt altitude with home_alt. Vector3 TargetEstimator::get_lat_lon_alt_est() const { Vector3 lat_lon_alt{(double)NAN, (double)NAN, (double)NAN};
if (Vector2f(_filter_states.pos_ned_est).isAllFinite()) {
_reference_position.reproject(_filter_states.pos_ned_est(0), _filter_states.pos_ned_est(1), lat_lon_alt(0),
lat_lon_alt(1));
// 与 measurement_update 保持一致:输出端同样使用 home 高度,
// 保证测量与输出使用同一参考系,EKF 切换时不再产生阶跃
const home_position_s &home = _home_position_sub.get();
const float ref_alt = (home.valid_alt && PX4_ISFINITE(home.alt))
? home.alt
: _vehicle_local_position.ref_alt;
lat_lon_alt(2) = -(double)_filter_states.pos_ned_est(2) + (double)ref_alt;
}
return lat_lon_alt;
}
Flight Log / Additional Information
No response
Source: PX4/PX4-Autopilot