From ca846443d10dd13f664e3f197d579913f8830d32 Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Tue, 22 Aug 2023 21:57:17 +0100 Subject: [PATCH] AP_NavEKF: fallback to no baro on boards that have no baro --- libraries/AP_NavEKF/AP_NavEKF_Source.cpp | 13 +++++++++++++ libraries/AP_NavEKF/AP_NavEKF_Source.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libraries/AP_NavEKF/AP_NavEKF_Source.cpp b/libraries/AP_NavEKF/AP_NavEKF_Source.cpp index 633ee47b34..0f80af9f69 100644 --- a/libraries/AP_NavEKF/AP_NavEKF_Source.cpp +++ b/libraries/AP_NavEKF/AP_NavEKF_Source.cpp @@ -17,6 +17,7 @@ #include #include #include +#include extern const AP_HAL::HAL& hal; @@ -231,6 +232,18 @@ AP_NavEKF_Source::SourceYaw AP_NavEKF_Source::getYawSource() const return _source_set[active_source_set].yaw; } +// get pos Z source +AP_NavEKF_Source::SourceZ AP_NavEKF_Source::getPosZSource() const +{ +#ifdef HAL_BARO_ALLOW_INIT_NO_BARO + // check for special case of missing baro + if ((_source_set[active_source_set].posz == SourceZ::BARO) && (AP::dal().baro().num_instances() == 0)) { + return SourceZ::NONE; + } +#endif + return _source_set[active_source_set].posz; +} + // align position of inactive sources to ahrs void AP_NavEKF_Source::align_inactive_sources() { diff --git a/libraries/AP_NavEKF/AP_NavEKF_Source.h b/libraries/AP_NavEKF/AP_NavEKF_Source.h index d07fb986fe..b8bfa67d18 100644 --- a/libraries/AP_NavEKF/AP_NavEKF_Source.h +++ b/libraries/AP_NavEKF/AP_NavEKF_Source.h @@ -55,7 +55,7 @@ public: // get current position source SourceXY getPosXYSource() const { return _source_set[active_source_set].posxy; } - SourceZ getPosZSource() const { return _source_set[active_source_set].posz; } + SourceZ getPosZSource() const; // set position, velocity and yaw sources to either 0=primary, 1=secondary, 2=tertiary void setPosVelYawSourceSet(uint8_t source_set_idx);