Fences

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.

  • 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

Rover Actions

Rover has no altitude actions, but if it reaches the Cylindrical fence boundary in either Steering or Acro modes, it will simply stop and not move beyond it. In other modes, it will execute the FENCE_ACTION.

Copter Actions

Copter will stop increasing altitude at FENCE_ALT_MAX in Loiter, PosHold, and AltHold modes.

In Loiter mode, it will try to stop at the horizontal boundaries, but declare a breach if exceeds the boundary.

In other modes, it will execute the FENCE_ACTION below if the altitude or boundary is reached.

FENCE_ACTION

Copter

Rover

0

Report Only

1

RTL/LAND

RTL/HOLD

2

LAND

HOLD

3

SmartRTL/RTL/LAND

SmartRTL/RTL/HOLD

4

BRAKE/LAND

SmartRTL/HOLD

5

SmartRTL or LAND

not applicable

Note

RTL/HOLD,etc. means it will attempt RTL first, but if it can’t switch to that mode (ie for RTL, GPS lock is lost), it will attempt to switch to the next,in this case HOLD.

If Object Avoidance is setup, RTL actions will attempt to avoid any fences as it returns.

At the moment the fence is breached a backup fence is erected 20m further out (or up). If the vehicle breaches this backup fence (for example if the vehicle is not set up correctly or the operator takes control but is unable to bring the copter back towards home), the vehicle will execute the FENCE_ACTION again (and another backup fence an additional 20m further out will be created if this is breached again).

If the vehicle eventually proceeds 100m outside the configured fence distance, despite the backup fences, the vehicle will switch into LAND mode (HOLD for Rover). The idea being that it’s clearly impossible to get the vehicle home so best to just bring it down/stop it. The pilot can still retake control of course with the flight mode switches. Like with the earlier fences, another fence is erected 20m out which will again switch the vehicle to LAND (HOLD for Rover), if it continues away from home.

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 the fence, low (under 1800) will disable the fence.

Automatic Altitude Breach Avoidance

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

[wiki site=”copter”]

For Polygonal fences, Copter will stop increasing altitude at FENCE_ALT_MAX in Loiter, PosHold, and AltHold modes. [/site] [wiki site=”plane”]

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. [/site]

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

[wiki site=”copter”]

Copter GeoFence Tab

Copter and Traditional Heli, when connected to Mission Planner, present a CONFIG tab called GeoFence which provides another way to access these parameters in those vehicles.

../_images/Fence_MPSetup.png

[/site]

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.

[wiki site=”plane”]

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.

[/site]