From 4d944da530fe162d8dcd58fce3594bd9ec5ab98c Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 6 Apr 2018 22:17:04 +1000 Subject: [PATCH] AP_AHRS: add a singleton-getter cast into AP_AHRS_NavEKF This will allow libraries which absolutely require the EKF to easily get a cast copy of the singleton. --- libraries/AP_AHRS/AP_AHRS.h | 6 ++++++ libraries/AP_AHRS/AP_AHRS_NavEKF.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/libraries/AP_AHRS/AP_AHRS.h b/libraries/AP_AHRS/AP_AHRS.h index c1a8d62f0d..d6fd37fe4d 100644 --- a/libraries/AP_AHRS/AP_AHRS.h +++ b/libraries/AP_AHRS/AP_AHRS.h @@ -686,4 +686,10 @@ private: namespace AP { AP_AHRS &ahrs(); + + // use ahrs_navekf() only where the AHRS interface doesn't expose the + // functionality you require: +#if AP_AHRS_NAVEKF_AVAILABLE + AP_AHRS_NavEKF &ahrs_navekf(); +#endif }; diff --git a/libraries/AP_AHRS/AP_AHRS_NavEKF.cpp b/libraries/AP_AHRS/AP_AHRS_NavEKF.cpp index a68bb8a464..9383e308f4 100644 --- a/libraries/AP_AHRS/AP_AHRS_NavEKF.cpp +++ b/libraries/AP_AHRS/AP_AHRS_NavEKF.cpp @@ -1642,5 +1642,11 @@ uint8_t AP_AHRS_NavEKF::get_primary_gyro_index(void) const return AP::ins().get_primary_gyro(); } + +AP_AHRS_NavEKF &AP::ahrs_navekf() +{ + return static_cast(*AP_AHRS::get_singleton()); +} + #endif // AP_AHRS_NAVEKF_AVAILABLE