diff --git a/docs/en/config/safety.md b/docs/en/config/safety.md index 0394f4b8ae0..e042845851f 100644 --- a/docs/en/config/safety.md +++ b/docs/en/config/safety.md @@ -307,7 +307,7 @@ PX4 also keeps planned flight inside the pre-geofence: It is also rejected if a leg between positions or a fixed-wing loiter circle comes closer to the plan than the margin. - The target of a _Go to location_ ([reposition](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_REPOSITION)) or of an altitude change, and the centre of a fixed-wing orbit or figure-eight, is refused if it lies outside the pre-geofence (unless the action is `Warning`). As for the geofence, only the target is checked, not the path to it or the loiter circle around it. - A vehicle that is outside the pre-geofence can still be paused or change its altitude, because only what the command changes is checked. + An altitude change keeps the vehicle's position, so it is refused while the vehicle is horizontally outside the pre-geofence: send the vehicle back inside first. - [Return mode](../flight_modes/return.md#geofence_awareness) plans its route around the Geofence Plan with the margin added. ## Position Estimation Failsafes diff --git a/src/modules/navigator/navigator_main.cpp b/src/modules/navigator/navigator_main.cpp index 9da5379e78d..c3d241222bd 100644 --- a/src/modules/navigator/navigator_main.cpp +++ b/src/modules/navigator/navigator_main.cpp @@ -1929,15 +1929,8 @@ bool Navigator::pre_geofence_allows_position(const vehicle_global_position_s &po (_geofence.getPreGeofenceAction() != geofence_result_s::GF_ACTION_WARN)) { if (PX4_ISFINITE(pos.lat) && PX4_ISFINITE(pos.lon) && PX4_ISFINITE(pos.alt)) { - // Unlike geofence_allows_position(), only what the command changes is checked. Example: a vehicle that - // holds outside the pre-geofence can still change its altitude, because that command keeps its position. - const bool keeps_position = fabs(pos.lat - _global_pos.lat) < DBL_EPSILON - && fabs(pos.lon - _global_pos.lon) < DBL_EPSILON; - const bool keeps_altitude = fabsf(pos.alt - _global_pos.alt) < FLT_EPSILON; - - return (keeps_position || (_geofence.isCloserThanPreMaxDistToHome(pos.lat, pos.lon) - && _geofence.isInsidePreGeofence(pos.lat, pos.lon))) - && (keeps_altitude || _geofence.isBelowPreMaxAltitude(pos.alt)); + return _geofence.isCloserThanPreMaxDistToHome(pos.lat, pos.lon) && _geofence.isBelowPreMaxAltitude(pos.alt) + && _geofence.isInsidePreGeofence(pos.lat, pos.lon); } } diff --git a/src/modules/navigator/test/test_pre_geofence_breach.cpp b/src/modules/navigator/test/test_pre_geofence_breach.cpp index 7ed4d9d0517..1a7b2708354 100644 --- a/src/modules/navigator/test/test_pre_geofence_breach.cpp +++ b/src/modules/navigator/test/test_pre_geofence_breach.cpp @@ -267,23 +267,6 @@ TEST_F(PreGeofenceBreachTest, ReturnKeepsTheMargin) } #endif // CONFIG_NAVIGATOR_GEOFENCE_AVOIDANCE -// A command without a position or an altitude keeps the vehicle's own, also outside the pre-geofence. -TEST_F(PreGeofenceBreachTest, TargetsKeepTheVehiclePositionAndAltitude) -{ - setParam("GF_PRE_MAX_HDIST", 400.f); - setParam("GF_PRE_MAX_VDIST", 80.f); - const Place vehicle{0.f, 420.f, kHomeAltitude + 90.f}; - ASSERT_TRUE(preGeofenceBreached(checkAt(vehicle))); - - EXPECT_TRUE(targetAllowed(vehicle)); - // Back inside horizontally, or down below the altitude limit. - EXPECT_TRUE(targetAllowed({0.f, 300.f, vehicle.altitude})); - EXPECT_TRUE(targetAllowed({vehicle.north, vehicle.east, kAltitude})); - // Further out or up. - EXPECT_FALSE(targetAllowed({0.f, 440.f, vehicle.altitude})); - EXPECT_FALSE(targetAllowed({vehicle.north, vehicle.east, kHomeAltitude + 95.f})); -} - // What triggers the pre-geofence. Each source has its geofence twin further out. enum class Source { HomeDistance, // GF_PRE_MAX_HDIST 400 m inside GF_MAX_HOR_DIST 500 m