Softivation

Geofence polygon is wide, but the drone turns back early

If the drone switches to RTL early even though the geofence polygon is wide, the cause is the circle bit left enabled in FENCE_TYPE. The message to look for and the permanent fix for the setting.

Furkan IŞIKAY 6 min read

You drew the polygon over the map, its edges run well outside the flight area, you uploaded it, and it was accepted. A minute and a half after takeoff, the autopilot writes RTL to the mode and the drone heads home.

You hadn't even come close to the polygon's edge. What turned the drone around is a second fence that stayed enabled alongside the area you drew.

Drawing the polygon doesn't turn off the circle

In ArduPilot the fence setting is not a single choice. The altitude ceiling, the home-centered circle, the polygon, and the altitude floor are separate fences, and each one that is enabled applies on its own.

Uploading the polygon doesn't turn off the circle. The circle stays enabled and stays at whatever radius it has. It makes no difference if the polygon is a kilometer further out; the two fences are measured independently of each other.

The message tells you which fence was triggered

ArduPilot writes which fence was triggered at the moment of the breach. The phrase that appears in the ground control station's message window is the diagnosis itself.

If you see Circle fence breached, what triggered it is not the polygon but the home-centered circle. If you see Polygon fence breached, you really have gone outside the area you drew. The two look similar on the same screen, but the parameter you need to look at is different.

If you couldn't catch the message, don't guess. Download the flight log, open the message lines, and look at the last line before the mode change.

The fence setting carries four fences in a single number

FENCE_TYPE doesn't behave like a list box. It carries four separate fences in a single number, and each bit that is on applies its own fence:

BitValueFenceWhat it applies
bit 01Max Altthe FENCE_ALT_MAX altitude
bit 12Circlethe home-centered FENCE_RADIUS circle
bit 24Polygonthe inclusion/exclusion areas you uploaded
bit 38Min Altthe FENCE_ALT_MIN floor

FENCE_TYPE = 7 turns on three bits at once: Max Alt + Circle + Polygon. Uploading the polygon doesn't turn off bit 1; the circle stays at whatever value FENCE_RADIUS has.

The circular fence radius default in the source code is 300 meters. It is defined as AC_FENCE_CIRCLE_RADIUS_DEFAULT in libraries/AC_Fence/AC_Fence.cpp. On your vehicle this value may have been changed earlier. Don't go from memory; read it from the parameter screen.

The same polygon, with the circle on and off

In ArduCopter 4.7.0, if you upload a 1200 × 1200 meter inclusion polygon, leave FENCE_RADIUS at 150 meters, and fly the vehicle east, the difference looks like the figure when FENCE_TYPE is the only variable.

Flying east with the same polygon, two FENCE_TYPE values

With FENCE_TYPE 7, the vehicle crosses the circle boundary at 153 meters and returns home with RTL. With FENCE_TYPE 4, the fence doesn't react until 574 meters with the same polygon.
What to look at: the point where the dashed line meets the red curve. Even though the polygon is 1200 × 1200 m, the return starts at the 150 m circle boundary.

At the default value of 7, the vehicle prints the Circle fence breached message at 153 meters and the mode switches to RTL. When you set FENCE_TYPE to 4, there is no reaction until 574 meters with the same polygon.

At the moment of the breach, the message lines appear in this order:

Output
Arming motors
EKF3 IMU0 MAG0 in-flight yaw alignment complete
Circle fence breached
Manual recovery started
Fence breach cleared
Disarming motors

The Manual recovery started line in between can be misleading: in the source code, this message is printed when the flight mode changes while the breach is ongoing, and it makes no difference whether the mode change was automatic.

Turn off the circle bit

If you want only the area you drew to apply, drop the circle bit. Keeping the altitude ceiling is generally a good idea, so 5 is a sensible starting point for FENCE_TYPE: 1 (Max Alt) + 4 (Polygon).

MAVProxy / Mission Planner console
# disable first, then write, enable last
param set FENCE_ENABLE 0
param set FENCE_TYPE 5
param set FENCE_ACTION 1
param set FENCE_ENABLE 1

# read back after writing
param show FENCE_TYPE
param show FENCE_RADIUS

Order matters: changing the type while the fence is enabled can cause the autopilot to measure with the old mask in the next loop. Turn it off, write the value, turn it on.

After writing, read the value back. Mission Planner's parameter screen paints the box with the new value after sending the write request. That doesn't mean the autopilot accepted it.

Example: you uploaded the corner coordinates of the TEKNOFEST mission area as a polygon. Your takeoff point is on one edge of the area, and the farthest mission point is farther from home than the circle radius. As long as the circle bit stays on, the vehicle turns back halfway on its way to that point even though it is inside the polygon. Before going on the mission, read FENCE_TYPE back and confirm the circle bit really is off. If you are going to keep the circle on, make sure FENCE_RADIUS covers the farthest mission point.

Error Messages and Their Meanings

The strings below appear verbatim in the ArduCopter 4.7.0 source.

Circle fence breached

The home-centered circular fence has just been breached. Bit 1 is on in FENCE_TYPE and the vehicle went outside FENCE_RADIUS. It has nothing to do with the polygon.

Fence breach cleared

All breached fences have been cleared and the vehicle is back in the permitted area. This line alone doesn't mean the flight has been fixed. Look at which fence was triggered before it.

Fences enabled, but none selected

It appears before ARM and shows on screen with the PreArm: prefix. It means FENCE_ENABLE was set to 1 but FENCE_TYPE was left at 0.

Fence requires position

The circular or polygon fence can't be measured until the horizontal position solution is ready. This line doesn't say the fence setting is broken; it says the EKF hasn't produced a position yet. You may see it on the first ARM attempt, and it passes on its own once the satellite solution settles. It shows on screen with the Arm: prefix.

Read more

This article closes out a single symptom. In the lesson, we go step by step through the fence's decision order, which message comes from which source line, how the permitted area narrows when multiple inclusion areas are drawn, and cases from the field.

The lesson is in the latest additions section of the Mission Planner Course from Scratch. For other courses, see the Softivation course list.

Was this article helpful?

Free resourcePixhawk and ArduPilot error message glossaryThe 4 messages in this article and similar ones are in the glossary: what they mean, why they appear, what to check first.

Learn this topic from start to finish

Season plan: all six courses for 9 months, ₺790 a month. ₺390 a month for high school and university students, ₺351 the first month with your member code. You can stop in any month you like. Start the Season plan · I'm a student