This feature is ideal for beginners who are learning to fly as you if you fly too far away your UAV will turn around and come back home. If you fly too low or too high, Ardupilot Mega will take over and make sure you do not crash.
Read more for some more info on how to use this new feature
Use for R/C training
One of the main uses of geo-fencing is to teach yourself (or someone else) to fly radio controlled planes. When you have a properly configured geo-fence it is very hard to crash, and you can try maneuvers that would normally be too likely to end in a crash, trusting the APM to 'bounce' the plane off the geo-fence before the flight ends in disaster.
Geo-fencing can be combined with any Ardupilot Mega flight mode. So for a raw beginner, you would combine it with one of the stabilised flight modes (such as STABILIZE or FBWA). Once the pilot has gained some confidence you could combine it with MANUAL mode, which gives direct control of the plane and allows for the most interesting aerobatic maneuvers. When used in this way the APM stays out of your way completely, just passing the controls to the servos directly, and only takes control if you go outside the fenced area or outside the defined altitude range.
Setting up geo-fencing
To setup geo-fencing in ArduPlane you need to configure six things:
- the boundary of the fence, as a set GPS points
- the action to take on fence breach
- the location of the return point
- the minimum and maximum altitude of the fenced area
- what RC channel on your transmitter you will use to enable geo-fencing
- how you want to take back control after a fence breach
There are a few rules that you must follow when setting up your fence boundary:
- the return point must be inside the fence boundary
- the fence boundary must be fully enclosed. This means it must have at least 4 points, and the last point must be the same as the first point
- the boundary can have at most 18 points
Please remember when making your fence boundary that your plane will have some momentum when it hits the fence, and will take time to turn back to the return point. For a plane like the SkyWalker we recommend an additional safety margin of around 30 meters inside the true boundary of where you want to fly. The same goes for the minimum altitude - you need to make it high enough that the APM has time to recover from a fast dive. How much margin you need depends on the flight characteristics of your plane.
Apart from the fence boundary, the following MAVLink parameters control geo-fencing behaviour:
- FENCE_ACTION - the action to take on fence breach. This defaults to zero which disables geo-fencing. Set it to 1 to enable geo-fencing and fly to the return point on fence breach.
- FENCE_MINALT - the minimum altitude in meters. If this is zero then you will not have a minimum altitude.
- FENCE_MAXALT - the maximum altitude in meters. If this is zero then you will not have a maximum altitude.
- FENCE_CHANNEL - the RC input channel to watch for enabling the geo-fence. This defaults to zero, which disables geo-fencing. You should set it to a spare RC input channel that is connected to a two position switch on your transmitter. Fencing will be enabled when this channel goes above a PWM value of 1750. If your transmitter supports it it is also a good idea to enable audible feedback when this channel is enabled (a beep every few seconds), so you can tell if the fencing is enabled without looking down.
- FENCE_TOTAL - the number of points in your fence (the return point plus the enclosed boundary). This should be set for you by the planner when you create the fence.
- changing modes using the APM mode switch on your transmitter
- disabling and re-enabling geo-fencing using the FENCE_CHANNEL channel
- set the RST_SWITCH_CH MAVLink parameter to another two-position channel that is attached to a spring loaded switch. The RST_SWITCH_CH parameter defaults to zero which disables it. If you set it to a channel then you can use this channel switch to take back control after a fence breach.
Setting up the fence boundary
To setup a fence boundary you should use the 'Flight Planner' screen in the APM Planner.
Start by right-clicking the location you want for the return point and choosing 'Set return location'. The return point should be somewhere in the middle of your flight area, and in easy visual range of where you will be standing when you fly.
After you've set the return point you should right click on the first point on the boundary of the fence you want. Choose 'Draw Polygon -> Add polygon point'. You are then in polygon mode, and you should left-click to add each point in the boundary of your fence. The planner will automatically complete the polygon by connecting the last point to the first one.
You can then right-click and choose geo-fencing upload to send your fence boundary to the APM. The planner will ask you for the minimum and maximum altitude of your fence before uploading. You can also save your fence to a file for later loading.
Altitude of the return point
If you set FENCE_MINALT and FENCE_MAXALT to other than zero (and have FENCE_MAXALT greater than FENCE_MINALT) then the return point altitude will be half way between FENCE_MINALT and FENCE_MAXALT.
If you don't setup FENCE_MINALT and FENCE_MAXALT (ie. leave them at zero) then the return point altitude will be given by the ALT_HOLD_RTL parameter, which is also used for RTL mode. Note that ALT_HOLD_RTL is in centimeters, whereas FENCE_MINALT and FENCE_MAXALT are in meters.
If your flying club and local flying rules don't set a maximum altitude then we recommend you use a maximum altitude of at most 122 meters (which is around 400 feet). Beyond that altitude it becomes quite difficult to keep good eye contact with your model.
With FENCE_MINALT set at 30 meters (to allow for some dive momentum) and FENCE_MAXALT set to 122 meters, the return point will be 76 meters, which is quite a good altitude to leave the plane loitering while you are getting ready to have another go.