I was interested in using geofencing only to get an altitude deck. As in if for some reason, I'm flying too low, the autopilot would take over and bring the airplane back to a proper altitude. This lets me fly freely at any altitude, but if some reason I lose control (or video during FPV and the aircrafts descends too much before I have time to hit RTL), I have the peace of mind that Arduplane will take over.
This was however not easy to setup at all because geofencing is not really designed with that use case in mind in APM::Plane. As discussed in this bug: https://github.com/diydrones/ardupilot/issues/2984 , in arducopter you can simply set an altitude limit but not in Arduplane.
So, what you need to do is the following:
FENCE_CHANNEL,8 =-> change to your channel
FENCE_MAXALT,130 => you must set a max alt, or min alt will not work :(
FENCE_RET_RALLY,1 => very important, means that guided will go back to the nearest rally point, or if you have none, to your RTL/takeoff point.
You're not done though, now you have to upload a useless geofence area or nothing will work. As per http://plane.ardupilot.com/wiki/geofencing/ , I uploaded a geofence as big as the US, and put the geofence return point in the middle of the ocean.|
The end result is that the geofence return point is too far, so when guided mode kicks in, it looks for a rally point, I have none, and then falls back to the RTL/takeoff point, which is what I wanted.
Sadly, though, I was only able to setup that useless geofence area with mission planner.
apmplanner did not allow me to set a geofence, or at least http://plane.ardupilot.com/wiki/geofencing/ does not really show how to get apmplanner ot do it
you'd think Tower, the new android app, would let you setup a geofence, but I didn't find how to do it, and the documentation is sadly non existent ( https://github.com/DroidPlanner/Tower/wiki and https://3drobotics.com/kb/tower-best-practices/ do not count as documentation).
So there you go, this can be made to work, but apparently you have to use mission planner (which means Virtualbox for me since I'm on linux), and you need to setup a huge polygon, a gence return point that is very far away from where you'll ever fly, and make sure that you do set FENCE_MAXALT or FENCE_MINALT won't work (which seems to be a bug, as of AP 3.4).