From 200d5ddc18e1683d6a7a0e516bd69fccf9bcc964 Mon Sep 17 00:00:00 2001 From: jonas Date: Fri, 20 Nov 2026 10:30:18 +0100 Subject: [PATCH] refactor(navigator): pass GF_CONT_ACTION on like GF_ACTION Navigator turned the values GF_CONT_ACTION does not offer into Warning. Commander does the same where the action is taken, so the list of offered actions was written twice. Navigator now passes the parameter on, as it does for GF_ACTION, and only reports None while the contingency geofence is disabled. Only a value outside the parameter's list behaves differently: with 4 (Terminate) a breach still only warns, but Go-to targets outside the contingency geofence are refused. Assisted-by: Claude:claude-fable-5-2 Signed-off-by: jonas --- src/modules/navigator/geofence.cpp | 19 ------------------- src/modules/navigator/geofence.h | 11 ++++++----- .../test/test_contingency_geofence_breach.cpp | 4 ---- 3 files changed, 6 insertions(+), 28 deletions(-) diff --git a/src/modules/navigator/geofence.cpp b/src/modules/navigator/geofence.cpp index e9a18e3cb0d..4b8da9e121a 100644 --- a/src/modules/navigator/geofence.cpp +++ b/src/modules/navigator/geofence.cpp @@ -903,25 +903,6 @@ bool Geofence::isBelowMaxAltitude(float altitude) return inside_fence; } -uint8_t Geofence::getContGeofenceAction() const -{ - if (getContGeofenceMargin() <= FLT_EPSILON) { - return geofence_result_s::GF_ACTION_NONE; - } - - switch (_param_gf_cont_action.get()) { - case geofence_result_s::GF_ACTION_NONE: - case geofence_result_s::GF_ACTION_LOITER: - case geofence_result_s::GF_ACTION_RTL: - case geofence_result_s::GF_ACTION_LAND: - return static_cast(_param_gf_cont_action.get()); - - default: - // The contingency geofence does not offer Terminate. - return geofence_result_s::GF_ACTION_WARN; - } -} - bool Geofence::isWithinAltitudeBand(float altitude) { if (!isEmpty() && _altitude_max > _altitude_min) { diff --git a/src/modules/navigator/geofence.h b/src/modules/navigator/geofence.h index 9144eb250b9..8f7be547d4c 100644 --- a/src/modules/navigator/geofence.h +++ b/src/modules/navigator/geofence.h @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -223,11 +224,11 @@ public: int getSource() { return _param_gf_source.get(); } int getGeofenceAction() { return _param_gf_action.get(); } - /** - * GF_CONT_ACTION as a GF_ACTION value: None while the contingency geofence is disabled, Warning for values - * it does not offer. - */ - uint8_t getContGeofenceAction() const; + /** GF_CONT_ACTION, or None while the contingency geofence is disabled. */ + int getContGeofenceAction() const + { + return getContGeofenceMargin() > FLT_EPSILON ? _param_gf_cont_action.get() : geofence_result_s::GF_ACTION_NONE; + } float getMaxHorDistanceHome() { return _param_gf_max_hor_dist.get(); } diff --git a/src/modules/navigator/test/test_contingency_geofence_breach.cpp b/src/modules/navigator/test/test_contingency_geofence_breach.cpp index ac9e5b2f414..cbdfc17d054 100644 --- a/src/modules/navigator/test/test_contingency_geofence_breach.cpp +++ b/src/modules/navigator/test/test_contingency_geofence_breach.cpp @@ -373,10 +373,6 @@ TEST_P(ContGeofenceSourceTest, PublishesTheContGeofenceAction) setParam("GF_CONT_ACTION", static_cast(geofence_result_s::GF_ACTION_NONE)); EXPECT_EQ(checkAt(inside()).geofence_cont_action, geofence_result_s::GF_ACTION_NONE); - - // Terminate is not offered. - setParam("GF_CONT_ACTION", static_cast(geofence_result_s::GF_ACTION_TERMINATE)); - EXPECT_EQ(checkAt(inside()).geofence_cont_action, geofence_result_s::GF_ACTION_WARN); } TEST_P(ContGeofenceSourceTest, HoldLoitersAtTheTriggerPosition)