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. 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 |
|
PLANE |
COPTER |
ROVER |
---|---|---|---|---|
|
0 |
X |
X |
|
|
1 |
X |
X |
X |
|
2 |
X |
X |
X |
|
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 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.
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_
:
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.
MAVLink support¶
ArduPilot will report the fence status via the MAVLink GCS protocol. The key status packet is called FENCE_STATUS, and is defined in “ardupilotmega.xml”. A typical FENCE_STATUS packet looks like this:
2011-12-20 16:36:35.60: FENCE_STATUS breach_status : 1, breach_count : 15, breach_type : 1, breach_time : 1706506
The breach_status field is 0 if inside the fence, and 1 if outside. The breach_count is how many fence breaches you have had on this flight. The breach_type is the type of the last breach (see the FENCE_BREACH enum in ardupilotmega.xml). The breach_time is the time in milliseconds of the breach since APM was booted.
The MAV_SYS_STATUS_GEOFENCE bit of the MAV_SYS_STATUS_SENSOR portion of the SYS_STATUS message indicates whether or not the geo-fence is breached. As of this writing only the MAVProxy GCS recognizes this status bit and reports the status of the geo-fence. In the future the Mission Planner, APM Planner, and other GCS applications should get support for announcing geo-fence status during the flight.
The MAV_CMD_DO_FENCE_ENABLE MAVLink command message allows a GCS to enable or disable a fence interactively. As of this writing only MAVProxy supports this message using the “fence enable” or “fence disable” commands. In the future Mission Planner, APM Planner, and other GCS applications may get support for interactively enabling and disabling the geo-fence without needing to use a manual transmitter.