mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-02 10:23:25 +08:00
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:
committed by
Andrew Tridgell
parent
9f648ccabc
commit
c9ba77a861
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user