GPS Boundary detection

One part of the Aussie Outback challenge rules dictate that the aircraft/GCS must have GPS boundary detection and if the aircraft wanders outside of this boundary then it must go into the spiral of death.

As part of my slow but sure attempt at entering the competition I have created a simple but effective solution to this part of the rules using a Ray casting algorithm and running this on a Netduino in C# (easy to convert to Arduino).

Here is the code to test if the current location falls within a polygon:

public static bool LocationInsideBoundry(Position point, Position[] boundry)

{

bool insideBoundry = false;

try

{

int j = boundry.Length - 1;

for (int i = 0; i < boundry.Length; i++)

{

if (boundry[i].Longitude < point.Longitude && boundry[j].Longitude >= point.Longitude ||

boundry[j].Longitude < point.Longitude && boundry[i].Longitude >= point.Longitude)

{

if (boundry[i].Latitude +

(point.Longitude - boundry[i].Longitude) / (boundry[j].Longitude - boundry[i].Longitude) * (boundry[j].Latitude - boundry[i].Latitude) < point.Latitude)

{

insideBoundry = !insideBoundry;

}

}

j = i;

}

}

catch (Exception)

{

return false;

}

return insideBoundry;

}

Pretty simple stuff and works a treat.

Here is a simple app in .net that shows if the current location is inside the boundary – drag the map around with the right mouse button add some points and if the location is inside the boundary then the group box background will be green – outside then red.

Hopefully it will be of some use.

Cheers
Justin

Views: 145

Comment by Troy on October 18, 2010 at 12:58pm
Thanks Justin.
I am working on an drone sail boat that will find different routs to a way point depending on wind direction. The boat needs to know if it is still in the lake (if not go a different way). I had bookmarked the Ray casting algorithm as a way to do this but hadn't written any code yet.
Cut and paste is a fast way to get code done. Thanks again.

Comment

Join DIY Drones

1

2

3

4

5

6

7

8

9

10

Contests

Season Two of the Trust Time Trial (T3) Contest has now begun. The fourth round is an accuracy round for multicopters, which requires contestants to fly a cube. The deadline is April 14th.

A list of all T3 contests is here

1299 members

48 members

693 members

51 members

249 members