Geo-Fencing for ArduCopter - Keep your copter "fenced in"

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

 

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:


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




Views: 9195

Comment by Andrew Radford on April 29, 2012 at 2:39am

Does this make RTL effectively obsolete then? It seems to do all RTL does and more


Developer
Comment by Andreas M. Antonopoulos on April 29, 2012 at 2:48am

Ch7 is used to turn the geofencing on. It is configurable in the code and therefore could be set to another channel, but the default is CH7. In the simulation I did, and also according to the wiki description from Andrew, it should be turned off for takeoff and landing. Otherwise you can't land, it will "bounce" of the virtual floor at 20m alt. It does not auto-takeoff unless you supply throttle though I would avoid turning it on on the ground as well. 

The code works (very simplified):

- Check if we're outside the fence

- If we are, switch to guided mode with your waypoint set to the center, mid-altitude. 

- then go to LOITER 

So the code is not substituting any of those functions, only adding an automatic "trigger" in the form of a fence. But what it triggers are the same modes that you could trigger with a mode-switch or channel switch.

Hope this makes sense. The wiki for ArduPlane geofencing explains in a lot more detail. I will be writing an update for ArduCopter once I can confirm some of the details in live flight testing.


Developer
Comment by Andreas M. Antonopoulos on April 29, 2012 at 2:56am

Andrew: I dont think this makes RTL obsolete. Consider a longer range mission that is point-to-point. In that case you might want to use RTL for a failsafe or something, but a fence would not make sense. 

Then again. most copter flights are short duration and local. So I think fencing is a kick-ass feature for copters as it doesn't really limit you that much, but it offers a safety net that is always on and automatic. 

I think of fencing like training wheels on a bike. Maybe an experienced pilot (clearly not me - I built this *because* I need training wheels) can tell us when each mode would be best used (RTL vs geofence)

Comment by Rob_Lefebvre on April 29, 2012 at 5:30am

This is definitely better than RTL in some instances.  For example, I plan to teach my son to fly the helicopter this summer, and the geofence is way better than having me grabbing the transmitter and hitting RTL.


Moderator
Comment by Grips on April 29, 2012 at 5:51am

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.


Developer
Comment by Andreas M. Antonopoulos on April 29, 2012 at 2:21pm

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.


Developer
Comment by Andrew Tridgell on April 29, 2012 at 3:12pm

Congratulations on some great work Andreas!


Developer
Comment by Andreas M. Antonopoulos on April 29, 2012 at 3:16pm

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?

Comment by Paul Emous on June 5, 2012 at 5:05am

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

Comment by Ron Perry on June 22, 2012 at 1:41pm

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.

Comment

You need to be a member of DIY Drones to add comments!

Join DIY Drones

© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service