MAVLINKHUD

Overview

The FENCE parameter group configures the Geofence safety system. A Geofence is a virtual perimeter (3D box, cylinder, or complex polygon) that the vehicle is not allowed to leave (Stay-In) or enter (Stay-Out).

If the vehicle breaches a fence, the autopilot takes autonomous action (usually RTL or Land) to bring it back to safety.

Key Concepts

1. Fence Types (FENCE_TYPE)

ArduPilot supports multiple fence styles:

  • Altitude (ALT_MAX): Prevents the vehicle from flying above a legal ceiling.
  • Circle (RADIUS): A cylindrical "Stay-In" fence around the Home or takeoff point.
  • Polygon: Custom shapes drawn in the GCS (Mission Planner/QGC).

2. Actions (FENCE_ACTION)

What happens when a breach occurs?

  • 0: Report Only (GCS warns, but no autonomous move).
  • 1: RTL (Returns to Home or nearest Rally point).
  • 2: Land (Immediate descent).

3. Failsafes and Margins

  • FENCE_MARGIN: The distance from the fence boundary where the "Warning" trigger fires, allowing the autopilot to brake before actually crossing the line.
  • FENCE_ALT_MIN: (Plane) Prevents the aircraft from diving below a safe terrain-clearance floor.

Parameter Breakdown

  • FENCE_ENABLE: Master switch.
  • FENCE_TYPE: Bitmask of active fence types (1=Alt, 2=Circle, 4=Polygon).
  • FENCE_ACTION: Breach behavior.
  • FENCE_ALT_MAX: The hard altitude ceiling (meters).
  • FENCE_RADIUS: Maximum distance from Home (meters).

Integration Guide

Setting up a Basic Safety Fence

  1. Enable: Set FENCE_ENABLE = 1.
  2. Ceiling: Set FENCE_ALT_MAX = 120 (FAA legal limit in meters).
  3. Boundary: Set FENCE_RADIUS = 300 (Visible line of sight).
  4. Action: Set FENCE_ACTION = 1 (RTL).
  5. Verify: Check for "Fence: OK" in the GCS pre-arm checklist.

Developer Notes

  • Library: libraries/AC_Fence.
  • Storage: Polygon points are stored alongside mission waypoints but in a separate memory area.
  • Precision: Fence checks run at the main loop rate (400Hz) for near-instant detection.

FENCE_ACTION

Default 1
Range 0 5

Fence Action (FENCE_ACTION)

Description

Defines the automatic flight behavior triggered by a fence breach.

Tuning & Behavior

  • Default Value: 1 (RTL or Land)
  • Values: 0:Report Only, 1:RTL or Land, 2:Always Land, 3:SmartRTL, 4:Brake or Land
  • Note: Plane uses 1:RTL, 6:Guided.

FENCE_ALT_MAX

m
Default 100
Range 10 1000

Fence Maximum Altitude (FENCE_ALT_MAX)

Description

The "Ceiling" of the geofence. If the vehicle flies higher than this altitude (relative to Home), the fence action will be triggered.

FENCE_ALT_MIN

m
Default -10
Range -100 100

Fence Minimum Altitude (FENCE_ALT_MIN)

Description

The "Floor" of the geofence. Useful for preventing underwater vehicles from diving too deep or keeping aircraft above a certain height.

FENCE_AUTOENABLE

Default 0
Range 0 3

Fence Auto-Enable (FENCE_AUTOENABLE)

Description

Allows the flight controller to automatically engage the geofence system at specific flight stages, such as after reaching a safe altitude following takeoff.

Tuning & Behavior

  • Default Value: 0 (Always Disabled)
  • Values:
    • 1: AutoEnableOnTakeoff
    • 2: AutoEnableDisableFloorOnLanding
    • 3: AutoEnableOnlyWhenArmed

FENCE_ENABLE

Default 0
Range 0 1

Fence enable/disable (FENCE_ENABLE)

Description

Master power switch for the geofence system. When enabled, the vehicle will monitor its position against defined boundaries and take automatic action if they are breached.

Tuning & Behavior

  • Default Value: 0 (Disabled)
  • Requires at least one fence type (e.g., Circle or Polygon) to be configured in FENCE_TYPE.

FENCE_MARGIN

m
Default 2.0
Range 1 10

Fence Margin (FENCE_MARGIN)

Description

A buffer zone inside the fence boundary. The flight controller will attempt to turn the vehicle back once it enters this margin, rather than waiting for the hard boundary of the fence itself.

FENCE_NTF_FREQ

MHz
Default 0
Range 1000 6000

Video Transmitter Frequency (FENCE_NTF_FREQ)

Description

This parameter is not found as FENCE_NTF_FREQ in the main codebase. It appears to be a miscategorized Video Transmitter parameter.

  • Note: Hardware frequency setting for VTX is typically handled via VTX_FREQ.

FENCE_OPTIONS

Default 0

Fence options (FENCE_OPTIONS)

Description

Configuration bitmask for tailoring fence logic, such as preventing flight mode changes until a breach is cleared.

Tuning & Behavior

  • Default Value: 0
  • Bitmask:
    • Bit 0: Disable mode change following action until breach cleared
    • Bit 1: Allow union of inclusion areas

FENCE_RADIUS

m
Default 300
Range 30 10000

Circular Fence Radius (FENCE_RADIUS)

Description

Defines the maximum horizontal distance from the Home point allowed before a fence breach occurs.

  • Requires Bit 1 to be set in FENCE_TYPE.

FENCE_RET_ALT

m
Default 0
Range 0 32767

Fence Return Altitude (FENCE_RET_ALT)

Description

Specifies the safe altitude to maintain while returning from a geofence breach.

  • Units are in meters.

FENCE_RET_RALLY

Default 0
Range 0 1

Fence Return to Rally (FENCE_RET_RALLY)

Description

For ArduPlane, specifies whether a fence breach should trigger a return to the nearest rally point instead of the primary fence return point.

  • 0: Fence Return Point
  • 1: Nearest Rally Point

FENCE_TOTAL

Default 0
Range 1 20

Fence polygon point total (FENCE_TOTAL)

Description

Reports the total number of vertices (points) currently loaded for the polygon fence.

  • Do not update this value manually.

FENCE_TYPE

Default 7

Fence Type (FENCE_TYPE)

Description

Defines which boundary types are active. Multiple types can be enabled simultaneously using the bitmask.

Tuning & Behavior

  • Default Value: 7 (Max Alt, Circle, and Polygon)
  • Bitmask:
    • Bit 0: Max Altitude
    • Bit 1: Circle Centered on Home
    • Bit 2: Polygon (loaded from SD card or GCS)
    • Bit 3: Min Altitude (Floor)