Skip to content

Commit

Permalink
AP_AHRS: added common origin logic
Browse files Browse the repository at this point in the history
this aligns the origin between EKF2, EKF3 and ExternalAHRS, making for
smooth transitions between AHRS backends in flight
  • Loading branch information
tridge committed Aug 15, 2024
1 parent b3f4fa0 commit 2fddb64
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
52 changes: 51 additions & 1 deletion libraries/AP_AHRS/AP_AHRS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,22 @@ void AP_AHRS::update_EKF2(void)
EKF2.getFilterStatus(filt_state);
update_notify_from_filter_status(filt_state);
}

/*
if we now have an origin then set in all backends
*/
if (!done_common_origin) {
Location new_origin;
if (EKF2.getOriginLLH(new_origin)) {
done_common_origin = true;
#if HAL_NAVEKF3_AVAILABLE
EKF3.setOriginLLH(new_origin);
#endif
#if AP_AHRS_EXTERNAL_ENABLED
external.set_origin(new_origin);
#endif
}
}
}
}
#endif
Expand Down Expand Up @@ -685,6 +701,21 @@ void AP_AHRS::update_EKF3(void)
EKF3.getFilterStatus(filt_state);
update_notify_from_filter_status(filt_state);
}
/*
if we now have an origin then set in all backends
*/
if (!done_common_origin) {
Location new_origin;
if (EKF3.getOriginLLH(new_origin)) {
done_common_origin = true;
#if HAL_NAVEKF2_AVAILABLE
EKF2.setOriginLLH(new_origin);
#endif
#if AP_AHRS_EXTERNAL_ENABLED
external.set_origin(new_origin);
#endif
}
}
}
}
#endif
Expand All @@ -698,6 +729,22 @@ void AP_AHRS::update_external(void)
if (_active_EKF_type() == EKFType::EXTERNAL) {
copy_estimates_from_backend_estimates(external_estimates);
}

/*
if we now have an origin then set in all backends
*/
if (!done_common_origin) {
Location new_origin;
if (external.get_origin(new_origin)) {
done_common_origin = true;
#if HAL_NAVEKF2_AVAILABLE
EKF2.setOriginLLH(new_origin);
#endif
#if HAL_NAVEKF3_AVAILABLE
EKF3.setOriginLLH(new_origin);
#endif
}
}
}
#endif // AP_AHRS_EXTERNAL_ENABLED

Expand Down Expand Up @@ -1411,6 +1458,9 @@ bool AP_AHRS::set_origin(const Location &loc)
#if HAL_NAVEKF3_AVAILABLE
const bool ret3 = EKF3.setOriginLLH(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;
Expand Down Expand Up @@ -1440,7 +1490,7 @@ bool AP_AHRS::set_origin(const Location &loc)
#endif
#if AP_AHRS_EXTERNAL_ENABLED
case EKFType::EXTERNAL:
// don't allow origin set with external AHRS
success = ret_ext;
break;
#endif
}
Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_AHRS/AP_AHRS.h
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,9 @@ class AP_AHRS {
bool option_set(Options option) const {
return (_options & uint16_t(option)) != 0;
}

// true when we have completed the common origin setup
bool done_common_origin;
};

namespace AP {
Expand Down

0 comments on commit 2fddb64

Please sign in to comment.