Developer

ArduCopter now has experimental geo-fencing support, thanks to Andrew Tridgell's superb geo-fencing code for ArduPlane.

3689454889?profile=original

 

If you haven't heard of the geo-fencing features of ArduPlane, you are probably an ArduCopter user! Since December 2011, ArduPlane piltos have had the ability to build a virtual fence around an area and prohibit the aircraft from exit from the fence.

The details are in the GeoFencing wiki page.

 

So, now, this amazing feature is available for early-stage testing in ArduCopter. 

 

Why do I want geo-fencing?

All four of my quad crashes follow the same scenario: pilot error causes the quad to go a bit far. Attempts to bring it back make the situation worse. The quad gets caught by wind or moves too fast and starts getting away from the pilot and out -of-sight. Eventually, you have to force a crash by killing the motors while you can still see the quad.


Runaway Copter - no more

The images above show a software-in-the-loop simulation of Tridge's geo-fencing in action. The quad starts in the center of a large sports field, with a fence defined in a 50m radius around the center. A minimum altitude of 20m and a maximum altitude of 100m are set for the quad. 

In the simulation, the quad's throttle is turned up to 75% and left at that level. Then pitch is set to a very aggressive 20-deg forward angle. 

After liftoff, and once past the minimum altitude of the fence (20m), the fence is turned on by a switch on CH7 (preset in code).

The quad shoots straight up and right past the max altitude, because it has a lot of upward momentum. The fence triggers and switches the quad to guided mode to pull it back to the center (which is halfway altitude 100m-20m = 80m, and the point in the center of the fenced area). Because the throttle is still very high, the guided mode is able to stop it from climbing but can't quite pull it down. Easing off the throttle to about 45% makes the quad a bit more "tame". 

The quad then spends the next five hours screaming at 25m/s speeds towards the walls, while hovering just under the ceiling (at an average of 98m) and bouncing back and forth. The shape that is created makes the fence visible. 


Bottom line: Your quad cannot get away.


Get the code - Testing the geo-fence on ArduCopter (Experienced Coders)

As an experimental feature, you will need to be able to compile and upload code to the board without the Mission Planner (ie using Arduino IDE or command line). You will also need to (possibly) tweak some parameters to your liking.


Get the code using one of the following options:

  • GIT - git checkout -b geofence_arducopter --track origin/geofence_arducopter 
or
Compile and install!

Get the code - Testing the geo-fence on ArduCopter (for Adventurous Beginners)


A bit easier, you will still need to know how to upload code to the board



Use the geo-fencing in a flight

To test the geo-fencing for ArduCopter, it is easiest to use the default parameters. You can build a fence as with ArduPlane using Mission Planner to define the coordinates of the fence (any size closed polygon). 

The other default parameters are defined in APM_Config.h with this code at the end of the file:

#define GEOFENCE_ENABLED ENABLED

#define FENCE_CHANNEL 7

#define RESET_SWITCH_CHAN 8

#define FENCE_ACTION FENCE_ACTION_GUIDED

#define FENCE_MINALT 20

#define FENCE_MAXALT 100 // meters


You can either tweak these in the code, or send them as MAVlink parameters I believe (not tested)


Automatic Fence

The new ArduCopter geo-fencing has one addition on the original ArduPlane code - the auto-fence! With automatic fencing, the code will create a 100m fence around your current location

If you have enabled geofencing (in the code) but have not defined the fence coordinates, the code will build a fence for you. You will need to have a GPS lock (reboot the board once you get a GPS lock) for this to work.


The FENCE_MAXALT is used to define the ceiling AND the diameter of the fence. So with FENCE_MAXALT at 100 meters, the default fence will be 100m wide, 100m tall. It is defined as an 18-sided polygon, with the center at the location you started (just like RTL, I believe) and the points defined at 20-degree intervals from 50m due north of your position, clockwise around your quad in a full circle (decaoctagon, more accurately). It looks like this:


3689454812?profile=original

You can tweak these parameters at startup, through Mission Planner or another MAVLink GCS. You can also use Mission Planner to define the geo-fencing points, just like in ArduPlane (have not tried this yet). See the ArduPlane geo-fencing instructions for more detail


Many many thanks to Andrew Tridgell for the superb geo-fencing idea and code.

Go forth, test and enjoy. Please give me feedback for the testing and development. 

Andreas




E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones

Comments

  • Exactly the same question I was going to ask. :)
  • Hi, has Geofencing support made it into the ArduCopter code base or is the patch still required?
  • This would definitely help me avoid a repeat of this!

    3692468049?profile=original

    I see the latest version (1.1.98) of the APM planner now includes a Geofencing section along with a link to the comprehensive Wiki docs.  However when I try to activate it I get the message 'This feature is not enabled in your firmware' which I'm taking to mean this is still officially only an Arduplane option.

    Any word on when this will make it into the official Arducopter firmware?

    Thanks for all the hard work!

    Jon

  • Did this make it into ArduCopter 2.6?

  • I'm grounding myself until geofencing-for-arducopter is released. 8 flights so far with my Avroto enabled Y6 and each scenario ended up resulting with the exact results described in "Why do I want geo-fencing?" This copter is too powerful and expensive to test without ample space and this awesome feature.

  • Great feature. Really looking forward to see this implemented in the ArduCopter releases.

  • Developer

    Tridge, Thank you, but I did very little on top of your superb code - you deserve all the credit.

    Do you think the automatic fence might be a useful feature to develop and test further, perhaps also for ArduPlane?

  • Developer

    Congratulations on some great work Andreas!

  • Developer

    Grips: That was true with the geofence on ArduPlane. But I have added an auto-fencing feature for ArduCopter that creates a fence on the fly, around your location. It's still experimental, but would remove the need for setting it up in advance and allow you to change locations. For the experiment above, I did not set the fence coordinates. I simply took off and turned fencing on. The fence was automatic.

  • Moderator

    The difference is that RTL works on the fly where the home location is set. The geo-fencing would need to be pre-programmed with your laptop or xbee's for your flying site. Say you go to your field and its packed with a soccer game or something of that nature, you would have to go home and re-program your fencing. Both are quite useful and I'm pumped to try it out! Great work!

    If anything, a new standard should be for a 7ch radio rather than a 6. Seems like it is getting more common for 7ch these days.

This reply was deleted.