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 <jonspero@me.com>
This commit is contained in:
jonas committed 2026-11-19 21:19:43 +01:00
1 parent 63c65daac0
commit 2b6d876130
2 files changed
+25

No files matched your search

+6
View File
@@ -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];
@@ -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
}