GPS Boundary detection

3689375442?profile=original

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

E-mail me when people leave their comments –

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

Join diydrones

Comments

  • 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.
This reply was deleted.