geofence: add simple vertical check

This commit is contained in:
Thomas Gubler
2014-01-04 15:17:07 +01:00
parent ec60a254d2
commit 31d1f436ad
3 changed files with 10 additions and 4 deletions

View File

@@ -72,12 +72,18 @@ bool Geofence::inside(const struct vehicle_global_position_s *vehicle)
{
double lat = vehicle->lat / 1e7d;
double lon = vehicle->lon / 1e7d;
float alt = vehicle->alt;
return inside(lat, lon);
return inside(lat, lon, vehicle->alt);
}
bool Geofence::inside(double lat, double lon)
bool Geofence::inside(double lat, double lon, float altitude)
{
/* Vertical check */
if (altitude > _altitude_max || altitude < _altitude_min)
return false;
/*Horizontal check */
/* Adaptation of algorithm originally presented as
* PNPOLY - Point Inclusion in Polygon Test
* W. Randolph Franklin (WRF) */

View File

@@ -64,7 +64,7 @@ public:
* @return true: craft is inside fence, false:craft is outside fence
*/
bool inside(const struct vehicle_global_position_s *craft);
bool inside(double lat, double lon);
bool inside(double lat, double lon, float altitude);
/**

View File

@@ -108,7 +108,7 @@ bool MissionFeasibilityChecker::checkGeofence(dm_item_t dm_current, size_t nMiss
return false;
}
if (!geofence.inside(missionitem.lat, missionitem.lon)) {
if (!geofence.inside(missionitem.lat, missionitem.lon, missionitem.altitude)) { //xxx: handle relative altitude
mavlink_log_info(_mavlink_fd, "#audio: Geofence violation waypoint %d", i);
return false;
}