Skip to content

test(geofence): cover emergency breaches and recovery - #30037

Open
JonasPerolini wants to merge 6 commits into
PX4:mainfrom
JonasPerolini:JonasPerolini/emergency-geofence-tests
Open

JonasPerolini wants to merge 6 commits into
PX4:mainfrom
JonasPerolini:JonasPerolini/emergency-geofence-tests

Conversation

@JonasPerolini

Copy link
Copy Markdown
Contributor

Summary

Flight and unit tests for the emergency geofence (GF_ACTION).

Problem

No flight tests what an emergency geofence breach does: the flight mode it leads to, how the vehicle is brought back, and which commands are refused. The contingency geofence flights only cover the margin.

Solution

SIH flights, multicopter unless noted:

  • Hold and Land start at the fence. A Go-to sent while still outside brings the vehicle back, and crossing back in keeps its target. The next breach acts again: Hold holds at the new breach and refuses a Go-to outside the fence, Land lands outside, where the breach then denies arming.
  • GF_MAX_HOR_DIST with Return lands at Home. GF_MAX_VER_DIST with Hold holds at the limit.
  • An exclusion circle triggers Hold with GF_SOURCE set to GNSS.
  • Warning reports the breach and keeps Position mode.
  • VTOL in fixed-wing: the Hold loiter keeps its center while it crosses the edge, and a Go-to sent while outside brings it back.

Unit tests cover both fences in Commander (action mapping, Go-to takeover, re-entry, the next breach, no deferral) and in Navigator (breach flags for each fence shape, the position source, Go-to targets above GF_MAX_VER_DIST).

Terminate is not flown: in SIH the lockstep stalls once control allocation stops.

Testing

All geofence flights pass in SIH at speed factor 10, the new ones at least three times, and the Warning, altitude and Land flights also at speed factor 1. The recovery flights fail when PX4 refuses a Go-to sent outside the fence, the Hold flight when PX4 accepts a target outside it, and the Land flight when the breach no longer denies arming or is reported as something else.

Assisted-by: Codex, Claude:claude-opus-5-5

@github-actions github-actions Bot added kind:test Adds or improves tests. scope:navigation Missions, RTL, geofence, takeoff, landing, or navigator behavior. labels Nov 26, 2026
Navigator and Commander unit tests cover the breach geometry and the
action policy of both geofences. SIH flights cover real breaches, the
flight mode each action leads to, the Go-to recovery and the next
breach.

Assisted-by: Codex
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: jonas <jonspero@me.com>
Each row is now its own named test: a failing row no longer stops the
other rows, the output names the row, and the contingency geofence
Terminate exception is a row of its own instead of a ternary. The
deferral test now runs Hold, Return and Land on each fence, instead of
Land on both.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: jonas <jonspero@me.com>
A name function returns the name of each shape directly. The stream
operator only existed to print it.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: jonas <jonspero@me.com>
…ight

The refusal flight repeated unit tests: the mission leg check and the
target check are covered in the Navigator tests. Only the Go-to
handling inside Navigator::run() needs a flight, so the Hold flight now
sends a Go-to outside the fence and checks that its Hold does not move.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: jonas <jonspero@me.com>
…d tests

Each trigger and each fence is now its own named test, and each action
rule is a test of its own. The loop version traced the action as a raw
uint8_t byte, so a failure did not say which action failed.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: jonas <jonspero@me.com>
@JonasPerolini
JonasPerolini force-pushed the JonasPerolini/emergency-geofence-tests branch from 332a1e1 to 8dc686c Compare November 26, 2026 08:17

@julianoes julianoes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems legit I guess 😄

return int(self._system.get_system_id())

@contextmanager
def observe_event(self, *texts: str, name: Optional[str] = None) -> Iterator[threading.Event]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're depending on event strings with this which isn't super pretty, but it's the best we have. And I guess that's ok since the test will break if any of these strings change and we'll adapt it.

@JonasPerolini
JonasPerolini marked this pull request as ready for review November 26, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:test Adds or improves tests. scope:navigation Missions, RTL, geofence, takeoff, landing, or navigator behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants