AP_AHRS: set origin via backend list rather than switch statement

one less thing to do when adding a backend
This commit is contained in:
Peter Barker
2026-09-26 07:07:37 +10:00
committed by Andrew Tridgell
parent 9f648ccabc
commit c9ba77a861
+10 -42
View File
@@ -1010,49 +1010,17 @@ AP_AHRS_Backend::Estimates *AP_AHRS::estimates_for_type(EKFType type)
bool AP_AHRS::set_origin(const Location &loc)
{
WITH_SEMAPHORE(_rsem);
#if HAL_NAVEKF2_AVAILABLE
const bool ret2 = ekf2.set_origin(loc);
#endif
#if HAL_NAVEKF3_AVAILABLE
const bool ret3 = ekf3.set_origin(loc);
#endif
#if AP_AHRS_EXTERNAL_ENABLED
const bool ret_ext = external.set_origin(loc);
#endif
// return success if active EKF's origin was set
bool success = false;
switch (active_EKF_type()) {
#if AP_AHRS_DCM_ENABLED
case EKFType::DCM:
break;
#endif
#if HAL_NAVEKF2_AVAILABLE
case EKFType::TWO:
success = ret2;
break;
#endif
#if HAL_NAVEKF3_AVAILABLE
case EKFType::THREE:
success = ret3;
break;
#endif
#if AP_AHRS_SIM_ENABLED
case EKFType::SIM:
// never allow origin set in SITL. The origin is set by the
// simulation backend
break;
#endif
#if AP_AHRS_EXTERNAL_ENABLED
case EKFType::EXTERNAL:
success = ret_ext;
break;
#endif
for (auto &backend_and_estimates : backends_and_estimates) {
auto &backend = backend_and_estimates.backend;
if (&backend == active_backend) {
continue;
}
// note that SITL and DCM ignore this set_origin call via
// an empty base-class implementation:
backend.set_origin(loc);
}
return success;
// return success if active EKF's origin was set
return active_backend->set_origin(loc);
}
// Record the current valid origin to parameters