Geofence ignoring FENCE_ALT_MIN

I converted my ZOHD Drift from iNav to Arduplane and re-maidened/autotuned it today.
I also tested the geofence functionality with the ultimate purpose of letting other people fly without them having to be afraid of crashing. Demonstrating that crashing is close to impossible is a huge confidence boost.

Drew and uploaded a polygon as an inclusion geofence, set a rally point, setup FENCE_ALT_MIN to 30m, FENCE_ALT_MAX to 120m and RC13_OPTION to 11 for enabling/disabling the fence.

The fence does work horizontally; if I try to fly from the inside to the outside of the fence I get a ‘Fence breached’ message and the associated action (RTL) is executed. Nice! So far so good.
I also tested if the lower altitude limit works, but no luck with that. With FENCE_ALT_MIN set to 30m I can descend to 5m altitude without breaching the fence.

Parameters:

FENCE_ACTION,1
FENCE_ALT_MAX,120
FENCE_ALT_MIN,30
FENCE_AUTOENABLE,0
FENCE_ENABLE,0
FENCE_MARGIN,2
FENCE_OPTIONS,1
FENCE_RADIUS,300
FENCE_RET_ALT,0
FENCE_RET_RALLY,1
FENCE_TOTAL,9
FENCE_TYPE,4
RC13_MAX,1900
RC13_MIN,1100
RC13_OPTION,11

Mission points:

QGC WPL 110
0	1	0	16	0	0	0	0	51.8004879	5.553224	-127.940000	1
1	0	0	5001	7.00000000	0.00000000	0.00000000	0.00000000	51.79545180	5.54504870	0.000000	1
2	0	0	5001	7.00000000	0.00000000	0.00000000	0.00000000	51.80271050	5.54867500	0.000000	1
3	0	0	5001	7.00000000	0.00000000	0.00000000	0.00000000	51.80240530	5.55712930	0.000000	1
4	0	0	5001	7.00000000	0.00000000	0.00000000	0.00000000	51.79821210	5.55652850	0.000000	1
5	0	0	5001	7.00000000	0.00000000	0.00000000	0.00000000	51.79732300	5.55498360	0.000000	1
6	0	0	5001	7.00000000	0.00000000	0.00000000	0.00000000	51.79553150	5.55290220	0.000000	1
7	0	0	5001	7.00000000	0.00000000	0.00000000	0.00000000	51.79501390	5.55062770	0.000000	1

I tried the same using the built-in simulation in Mission Planner, which shows the same behaviour; geofence works horizontally but it ignores FENCE_ALT_MIN and FENCE_ALT_MAX.

Arduplane 4.3.5, Mission Planner 1.3.80 running on Windows.

Stupid user error probably, but where?

Did You set FENCE_OPTIONS and FENCE_TYPE properly? AFAIK, the vertical fence needs to activated there.

Why is FENCE_ENABLE == 0 ???

2 Likes

FENCE_OPTIONS seems to only have a single option bit ‘Disable mode change following fence action until fence breach is cleared’?
https://ardupilot.org/plane/docs/parameters.html#fence-options-fence-options

FENCE_ENABLE=0 on the real vehicle because RC13_OPTION=11 is used to enable/disable the fence. In the horizontal plane that works.

In simulation I set FENCE_ENABLE=1 with the vehicle in the inclusion geofence to enable the geofence, which also works fine for horizontal breaches.

You should set FENCE_TYPE bit 0 and bit 3 also. Set FENCE_TYPE to 13.

Yes, that is it probably. Thanks!

I suggest:

FENCE_ENABLE = 1
FENCE_OPTIONS = 1
FENCE TYPE = 9 (no circle radius) or 11 (circular fence)

In MissionPlanner-builtin-simulation using Plane-latest with FENCE_ALT_MAX=120, FENCE_ALT_MIN=30 and FENCE_TYPE=13 (max alt/min alt/polygon) breaching the FENCE_ALT_MAX limit in guided mode triggers the geofence action (‘Fence breach MAXALT’ message folllowed by RTL)

However, going to 10 meters of altitude (thus, 20 meters below the FENCE_ALT_MIN limit) still does not trigger any action or message, and neither does going from 10 meters of altitude to 50 meters (thus crossing the boundary in reverse)

Disabling/re-enabling the fence by setting FENCE_ENABLE=0|1 and a few mode switches before breaching the fence again does not help. FENCE_TYPE=9 and even FENCE_TYPE=1 neither.

I have not tried a real plane yet. Will do that later this week if weather allows, but I doubt the outcome will be different.

I suggest:

FENCE_ENABLE = 1

What is the interaction between the FENCE_ENABLE parameter and RCx_OPTION=11?

AFAIK the RC switch only works if FENCE_ENABLE = 1

Hence it is not working for you.

On the real plane in the field the fence was working fine horizontally with RC13_OPTION=11 and FENCE_ENABLE=0. Next time I will try with FENCE_ENABLE=1

In simulation, where the lower altitude limit is not working yet, I am not using a transmitter nor RCx_OPTION=11. Just setting the FENCE_ENABLE parameter to 0 or 1 from Mission Planner.

The fence must be on during the entire flight or else it will not work.

Stop disabling it please

Probably I am still being stupid, but it is not working for me yet.

I created a screen capture of a SITL session in Mission Planner: plane geofence sim 2023 05 18 - YouTube
Popup windows disappeared in this capture, but I suspect you guys can dream those.

I know I am asking a lot, but it would be really helpful for me if someone could point out my error and/or create a SITL setup example where FENCE_ALT_MIN does work.