Article

A saved geofence setting is not proof that the boundary is active

A ground-control station can show a new geofence setting while the autopilot is still enforcing the old one. The parameter write may have succeeded, the vehicle may report that fencing is enabled, and the pilot can still have the wrong protection for the planned operation.

That is the failure described in an ArduPilot pull request reviewed in November 2026. Its author reports that changing FENCE_TYPE while fencing was already enabled stored the new bitmask without updating which boundaries were actively enforced. The difference persisted until the fence enable state was toggled or the vehicle rebooted.

The proposed correction sounds small: notice a configuration change and apply it. The associated regression tests show why it is not small. A fence has several independent ways to become active, and the rules for altitude floors, commanded changes and landing are not all interchangeable.

Three different questions hide inside a fence switch

ArduPilot's geofencing documentation distinguishes the type of boundary, the enable mechanism and the action taken on a breach.

FENCE_TYPE is a bitmask defining which kinds of boundaries are configured. They can include a maximum altitude, a home-centered circle, uploaded inclusion or exclusion regions, and a minimum altitude, depending on vehicle. It is not a single on/off switch.

FENCE_ENABLE is one mechanism for making the configured fences active. But a pilot can also use an auxiliary RC switch or a MAVLink command, and Plane has automatic fence enable settings. The minimum-altitude fence has special rules around arming and landing. A configured type therefore cannot be treated as synonymous with an enforced type.

FENCE_ACTION governs what happens when a fence is breached, with behavior depending on the vehicle and flight mode. A correctly configured breach action is of little help if the intended boundary never entered the active set.

The distinctions can be represented as three questions:

  • Configuration: Which fence types and geometries has the vehicle stored?
  • Runtime state: Which of those types is the controller enforcing right now?
  • Response: What does the vehicle do if the active boundary is crossed?

The first is straightforward to display in a parameter editor. The second is a property of a running state machine.

How a correct parameter read can give a false sense of assurance

Consider a hypothetical test aircraft with a maximum-altitude fence enabled. An operator changes FENCE_TYPE to add a horizontal boundary, and the parameter readback shows the new bitmask.

A readback proves that the setting was accepted and stored. It does not prove the fence runtime has registered the new horizontal type. According to the contributor's report, the earlier ArduPilot behavior continued with the set of boundaries selected at the previous enable transition. The next reboot or fence toggle caused the new selection to take effect.

That makes the defect unusually hard to spot in a routine preflight check. A pilot may see the expected number, and a separate indicator may say fencing is on. Neither observation identifies every currently enforced type.

It would be misleading to turn this into a claim that ArduPilot geofencing is generally unreliable. The PR describes a particular update path in the code under review. It includes a specific test for changing the type while enabled; it does not provide an independent survey of flight incidents or show that all maintained versions exhibit the defect.

The operational lesson is more general. Configuration persistence, successful command acknowledgement and active protection are different evidence. A safety-critical change should have an observable effect in a controlled test.

Why simply re-enabling everything can make the problem worse

The first instinct in a patch is to detect FENCE_TYPE changes and send them through the same routine used for FENCE_ENABLE. The PR's account says an earlier candidate did that and introduced a new problem.

Imagine fencing was activated by MAV_CMD_DO_FENCE_ENABLE rather than by setting FENCE_ENABLE=1. A change to the type selection then passed through the parameter-enable reset path. In the author's tests, that switched off a fence that the command had enabled. A code change intended to improve boundary updates had disabled the safety mechanism.

The MAVLink common message set defines MAV_CMD_DO_FENCE_ENABLE and fence-type masks for interactive control. The command layer is separate from the persistent parameter layer. A controller must preserve the intention of a recent command even if a different configuration field changes.

This is a recurring software design trap: using the same function to perform two operations whose side effects are not the same. Recomputing which fence types exist is not permission to reset whether fencing is enabled.

The PR discussion explains several failed iterations of the proposed fix. Their value is not the number of revisions. It is that the failures expose previously hidden state transitions.

The minimum-altitude fence breaks simple Boolean logic

A particularly revealing series of test cases concerns the minimum-altitude floor.

The ArduPilot documentation explains that minimum-altitude behavior differs from the other fence types. Enabling it while disarmed can prevent arming; landing modes can disable floor enforcement automatically so the vehicle can descend safely. Plane and Copter can also have automatic enable and disable paths.

A single Boolean such as fencing_on cannot express every combination of these states. There can be a commanded set of active fences, a selected type bitmask, and an exception that temporarily disables one type while leaving others active.

According to the PR author, one attempted revision used the nonempty set of active fence types as proof that fencing was on. That failed when the last configured type was removed and then a different type was added. Another tried one global enable flag and failed when only the floor remained or a floor-only disable occurred while no types were configured. A later revision failed to restore minimum-altitude enforcement after removing and re-adding that type.

These are not contrived objections to convenience. They test the difference between an empty active set because no type is selected and an empty active set because the operator explicitly disabled enforcement. The state machine needs to retain the distinction when the configuration changes again.

The correct response to these complexities is not to expose an extra switch and ask pilots to remember more combinations. It is to make the runtime state explicit in software and to cover the meaningful transitions with tests.

What the new tests establish, and what they cannot

The contributor reports writing a regression test that failed before the proposed fix and passed afterward. Several subsequent test cases were added after earlier versions of the fix broke commanded enable behavior or the floor's special handling.

In the reviewed branch, the author reports that 24 fence tests across Copter, Plane and Rover passed, including enable switches, breach reactions, altitude floors, margin changes and route-specific fence tests. The PR also describes manually testing in SITL.

That is considerably more informative than a screenshot of a parameter editor. The proposed tests exercise behavior through the vehicle rather than verifying only that the new number is displayed.

There are still limits. The contributor reports no hardware testing for this change. Sub shares some fence library paths but lacks an equivalent dedicated fence autotest in the described test suite; its path was source-reviewed. The results are the contributor's test report, not independent flight validation or proof that a particular released firmware version contains the correction.

Read the test description in PR #35067. The failure cases are useful review material even for developers using another autopilot, because they are about state transitions rather than one code style.

A practical validation matrix for geofence changes

For an integration laboratory, the test should distinguish saved settings from actual enforcement without risking a real boundary breach. SITL is the appropriate first environment.

A compact matrix can cover several dimensions:

  1. Entry path. Enable a fence from FENCE_ENABLE, from an RC auxiliary switch, and using MAV_CMD_DO_FENCE_ENABLE.
  2. Configuration change. Add a type, remove one type, replace one type with another in a single write, and remove all types before adding one back.
  3. Vehicle state. Exercise disarmed, armed, landing and automated-enable transitions where supported.
  4. Boundary response. Simulate a position that crosses the relevant active boundary and verify the intended fence status and mode response.
  5. Persistence. Compare the immediate effect of a parameter change with the effect after an explicit disable-enable sequence or reboot.

A test should assert both the reported status and the simulated behavior. If it only checks FENCE_TYPE after a write, it could pass while the runtime ignores the new type.

MAVLink FENCE_STATUS and SYS_STATUS provide useful signals for observability. The ArduPilot documentation also describes a geofence bit in the system status information. However, a single healthy status bit may mean merely that the current active fence has not been breached. It does not necessarily enumerate the intended configured geometry.

No live vehicle should be intentionally flown into a prohibited zone to reproduce this defect. A simulator, an authorized isolated bench setup, and carefully controlled parameter tests provide the evidence without the operational risk.

A boundary has more than one geometry

Fence validation is not complete when the type mask is correct. An inclusion polygon can overlap another, a circle can be centered on home, and altitude limits may use different reference frames.

ArduPilot's current documentation explains that maximum and minimum altitude limits can be referenced to home, mean sea level, the estimator origin or terrain, where supported. Polygon inclusion and exclusion areas are horizontal constraints. Changing the reference frame or terrain availability can change what a number means at the point where the aircraft flies.

There are therefore two independent checks:

  • Does the control logic enforce the selected fence types?
  • Are the configured boundary coordinates and reference frames appropriate for the actual mission?

A correctly enforced ceiling in the wrong altitude frame remains a bad ceiling. A correct polygon is not protection if it has not been uploaded or activated. The PR targets the first problem; it does not substitute for a mission-specific geometry review.

This is why geofence assurance belongs in the same operational discipline as mission upload verification, failsafe configuration and preflight sensor checks. The right numerical settings matter, but so does evidence about the vehicle's effective state.

The useful conclusion

ArduPilot's proposed patch addresses a concrete inconsistency: changing a stored fence-type bitmask did not immediately change the set of enforced boundaries. The associated review history shows that the naive fix can introduce a more dangerous inconsistency by resetting operator commands or mishandling the altitude floor.

For developers, the result is a state-machine testing problem. For pilots, it is a verification problem. A saved parameter and a green status indicator can be necessary checks, but neither alone proves that the intended airspace boundary is active.

Until a tested fix is present in the deployed firmware, treat mid-session fence-type changes cautiously and follow the flight stack's validated configuration procedure. More importantly, build a preflight check around the effective enforced boundary, not only the value visible in a settings editor.