From 2b6d8761308617da21565f1e71c7e84dcf472030 Mon Sep 17 00:00:00 2001 From: jonas Date: Thu, 19 Nov 2026 21:19:43 +0100 Subject: [PATCH] fix(navigator): report no contingency breach while a fence loads While a changed fence loads, the fence counts as empty and the point checks restrict nothing. The contingency geofence check did not follow: isCircleInside() went on to checkPaths(), which still walked the areas of the previous fence, could not read them from the invalidated cache and answered "unavailable". Navigator reported that as a breach at every position until the load ended, so GF_CONT_ACTION triggered in flight and arming was denied on the ground. checkPaths() now leaves the fence areas out while no fence is loaded. The input checks still run first. The guard was lost when the circle check moved into checkPaths(). Assisted-by: Claude:claude-fable-5-2 Signed-off-by: jonas --- src/modules/navigator/geofence.cpp | 6 ++++++ .../navigator/test/test_geofence_margin.cpp | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/modules/navigator/geofence.cpp b/src/modules/navigator/geofence.cpp index a9d1eaee15c..e9a18e3cb0d 100644 --- a/src/modules/navigator/geofence.cpp +++ b/src/modules/navigator/geofence.cpp @@ -725,6 +725,12 @@ bool Geofence::checkPaths(const PathCheck *paths, size_t num_paths, bool *result < max_home_distance - getContGeofenceMargin(); } + // Like the point checks, an unloaded fence restricts nothing: while a changed fence loads, + // the areas of the previous one can no longer be read. + if (isEmpty()) { + return true; + } + for (int p = 0; p < _num_polygons; ++p) { const PolygonInfo &polygon = _polygons[p]; diff --git a/src/modules/navigator/test/test_geofence_margin.cpp b/src/modules/navigator/test/test_geofence_margin.cpp index 0bb882df04b..c2c72197fd9 100644 --- a/src/modules/navigator/test/test_geofence_margin.cpp +++ b/src/modules/navigator/test/test_geofence_margin.cpp @@ -351,3 +351,22 @@ TEST_F(GeofenceLongLegMarginTest, EdgeBesideTheLegEnd) EXPECT_TRUE(legClear(100.f)); EXPECT_FALSE(legClear(200.f)); } + +// Navigator asks five times a second, also while a changed fence loads over the previous one. +TEST_F(GeofenceCircleTest, ChangedFenceLoadingRestrictsNothing) +{ + ASSERT_TRUE(loadFence(exclusionSquare())); + // The new square is 200 m further east; both leave Home clear. + ASSERT_TRUE(storeFence(polygon(false, {{-50.f, 450.f}, {50.f, 450.f}, {50.f, 550.f}, {-50.f, 550.f}}))); + _fence.updateFence(); + + for (int step = 0; step < 100 && !_fence.isReadyForPathChecks(); ++step) { + _fence.run(); + EXPECT_TRUE(circleInside(0.f, 0.f, 80.f)) << "step " << step; + px4_usleep(1000); + } + + ASSERT_TRUE(_fence.isReadyForPathChecks()); + EXPECT_TRUE(circleInside(0.f, 300.f, 40.f)); // where the old square was + EXPECT_FALSE(circleInside(0.f, 500.f, 40.f)); // in the new square +}