Geofence autoenable when there is no fence

I created a new plane for some SITL testing and loaded a previously saved param file that contained FENCE_AUTOENABLE = true. I set up a mission, but no fence.
When the plane successfully completed takeoff I got the “Geofence enabled, autoenabled” message - but there was no fence. So as a pilot I might be under the mistaken impression that there is a geofence in place - when in fact there is not. I could imagine that this might be disastrous if this was a real plane.
Perhaps fence autoenable ought to check that there is a fence?

This is with a local build from master (last pulled 2022-March-30)

Which version? Did you use master branch? if yes, can you open a github issue?

Yes it was, sure I can do that.

I’ve created a PR with my proposed fix. Sorry @amilcarlucas I’ve messed up the PR with a bunch of unrelated changes. I’ll delete it and try again.

Excellent. PRs are a lot better than open issues. Thanks for helping out!!

I think I got it - one PR, one commit, one file changed. Please review:

I’ve noticed that there is a similar problem with RC fence enable - you can “enable” the fence using the switch, even if there is no fence. A related problem is that RC tells the GCS that the switch has gone high or low, but doesn’t notify it that the fence is enabled/disabled.
and also the fact that a MavLink command to enable the fence will also apparently work, even if there is no fence on the plane.
I’ve done an improved version of this PR that fixes these two issues two.

Hi @amilcarlucas , I’ve tested this PR now and submitted it for review. I updated the PR to include pre-arm checks and also GCS warnings if fence is enabled using FENCE_ENABLE, Auto-enable, RC channel switch or mavlink message when there is no fence.

I think it makes it much safer. Please take another look at my PR. Thank you!

I’ve updated the PR to fix the autotest. Now the autotest expects a fail to arm if there is no fence and I also added arm/disarm checks after adding each different type of fence.