GeoFencing

ArduPilot supports a home based Cylindrical (“TinCan”) and Polygonal and/or Cylindrical, Inclusion and/or Exclusion regions. Inclusion and Exclusion Fences are defined easily in Mission Planner under the PLAN screen and loaded to the autopilot, using the FENCES item in the drop down box, just like Missions or Rally Points are planned.

Some vehicles can also have maximum and/or minimum altitude limits. Some flight modes will try to prevent exceeding these limits automatically, a fence breach will be declared in all modes if exceeded.

Upon Fence breach, selectable actions are taken.

General Setup

  • Set FENCE_ENABLE = 1 to enable fences. This enables any fences that are setup, except the ALT_MIN fence, which must be enabled by using any fence enable means (GCS message, AUTOENABLE in plane, RC switch)

  • Set FENCE_ACTION = to whatever you wish for a breach action. These will vary depending on vehicle type. See Fence Breach Actions above.

  • Set FENCE_OPTIONS to “1” to prevent mode changes after a fence breach until the vehicle returns within the fence boundary (Plane only, Copter/Rover do not allow mode changes while in breach)

  • Set FENCE_ALT_MAX = to the altitude limit you want (in meters). This is unavailable in Rover.

  • Set FENCE_MARGIN = to the distance from the fence horizontal boundary the vehicle must maintain in order to prevent a breach.

  • Set the FENCE_ALT_MIN as a minimum altitude breach boundary.

  • Set FENCE_AUTOENABLE = (Plane Only)to allow automatic enabling of the fence (different than FENCE_ENABLE) under certain vehicle conditions, such as upon arming or takeoff. A value of 0 disables this feature. FENCE_ENABLE is ignored if this feature is enabled. Using FENCE_AUTOENABLE = 3 (enable on ARM) is the only recommended use. “1” or “2” functions are being deprecated shortly since they can produce undesirable results in terms of containment.

  • FENCE_RET_RALLY allows returning to the nearest RALLY point (See: Rally Points), if loaded, instead of HOME.

  • Set FENCE_TYPE = is a bitmap set to enable the various fence types: MIN or MAX altitude, simple CIRCLE tin can around HOME, or POLYGON fences. The POLYGON fences must also have been loaded via a fence list from a ground control station in order to be active. See below for detailed setup of Cylindrical Fence and Inclusion and Exclusion Fences.

Note

Polygon fence type includes the circular fences specified in the Inclusion/Exclusion fence list. The simple home centered CIRCLE fence is a separate fence. Rover ignores altitudes, if set.

Defaults for FENCE_TYPE are:

  • Rover: CIRCLE and POLYGON

  • Copter: ALT MAX, CIRCLE, and POLYGON

  • Plane: POLYGON

Detailed Setup

Types of Fences

TYPE OF FENCE

FENCE_TYPE bit

PLANE

COPTER

ROVER

Global Maximum Altitude
  • FENCE_ALT_MAX defines max altitude

0

X

X

Cylindrical (“TinCan”)
  • Circle Centered on Home

  • Parameters for radius, height

1

X

X

X

Inclusion/Exclusion Zones
  • Arbitrary Locations

  • Polygonal or Circular

  • Inclusion or Exclusion

  • Defined by list, like missions

  • No height/altitude restriction

2

X

X

X

Global Minimum Altitude
  • FENCE_ALT_MIN defines min altitude

3

X

Note

if FENCE_TYPE =2 inclusion zones overlap, a fence breach will occur when crossing a boundary, even if within another inclusion zone, UNLESS FENCE_OPTIONS bit 1 is set to make all inclusions zones a union set.

Fence Breach Actions

If enabled, and the fence boundaries or altitudes(FENCE_ALT_MAX and FENCE_ALT_MIN), if non-zero, are exceeded, Plane will execute the FENCE_ACTION below:

FENCE_ACTION

Plane

0

Report Only

1

RTL

6

Guided to return point

7

Guided to return point with pilot throttle control

The return (and loiter) point, unless FENCE_RET_RALLY is enabled, is the geometric center of the breached fence boundary. If FENCE_ACTION is set to a guided return mode (6 or 7), the altitude at which it returns is determined by FENCE_RET_ALT or if FENCE_RET_ALT is zero, midway between the altitude limits, if non-zero. If both altitude limits are zero, then it will return at current altitude.

The return point can also be replaced by the nearest rally point (See: Rally Points) as a destination, if FENCE_RET_RALLY is enabled.

Note

while executing any action that requires a mode change (ie. all except Report Only), any additional fence breaches are recorded but ignored. For example, RTL that has an AutoLand will breach a MIN_ALT fence, if enabled, but take no action and finish the landing.

Modes changes cannot be executed after the fence breach unless the FENCE_OPTIONS bit 0 is set to “0”. By default it is set to “1” to prevent mode changes. When set, the vehicle must return to within the fence boundary in order to change modes. If mode changes are allowed, you can also return to the mode that was active upon breach by using an RC auxiliary switch set to option “96” (Re-read mode switch).

Enabling the Fence with an RC Channel Auxiliary Switch

It is not necessary to set-up a switch to enable or disable the fence but if you wish to control the fence with a switch follow these steps:

An RCx_OPTION can be set via the Config/Tuning > Full Parameter List screen, for example using RC channel 7:

  • Set RC7_OPTION = 11 (Fence Enable)

  • setting the switch high (i.e. PWM > 1800) will enable all configured fences, low (under 1800) will disable all fences.

Note

if the Minimun Altitude fence is enabled by the switch while on the ground and disarmed, a pre-arm failure will occur preventing arming.

Automatic Altitude Breach Avoidance

For landing modes (NAV_LAND,QLAND,LAND,etc.) in Copter and Plane, the FENCE_ALT_MIN limit is automatically disabled.

When in Mode FBWB or CRUISE, Plane will attempt to limit altitude target changes by the pilot (ie using Pitch stick for climb/descent rate demand inputs) to avoid breaching a maximum or minimum altitude fence.

Note

altitude control imperfections can still result in a breach unless the FENCE_MARGIN param is loose enough to accommodate these imperfections.

Enabling Fences in Mission Planner

To enable Fences, go to the Mission Planner full parameter list (CONFIG->Full Parameter Tree), search for items with FENCE_:

../_images/fence_enable.png

Use for R/C Training

One of the main uses of geo-fencing is to teach yourself (or someone else) to fly radio controlled vehicles. When you have a properly configured geo-fence it is very hard to crash, and you can try manoeuvres that would normally be too likely to end in a crash, trusting the autopilot to ‘bounce’ the vehicle off the geo-fence before the flight ends in disaster.

Geo-fencing can be combined with any flight mode. So for a raw beginner, you would combine it with one of the stabilised flight modes . Once the pilot has gained some confidence you could combine it with ACRO mode in Copter or MANUAL mode in Plane, which gives direct control of the vehicle and allows for the most interesting aerobatic manoeuvres.

Stick-mixing on fence breach

ArduPilot enables ‘stick mixing’ by default when in auto modes. This means that you can change the path of a loiter, for example, by using your transmitter sticks.

When you are using geo-fencing, stick mixing will be disabled on fence breach until your plane is back inside the fenced region. This is to ensure that the bad control inputs that caused you to breach the fence don’t prevent it from recovering to the return point.

As soon as you are back inside the fence stick mixing will be re-enabled, allowing you to control the GUIDED mode that the plane will be in. If by using stick mixing you manage to take the plane outside the fence again then stick mixing will again be disabled until you are back inside the fence.