From 6cdd188158bc4ec2d5bfa3c941c2b4608a1f169d Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Sun, 6 Nov 2016 15:00:43 -0500 Subject: [PATCH] geofence max horz/vertical better messages --- src/modules/navigator/geofence.cpp | 18 ++++++++++-------- src/modules/navigator/geofence_params.c | 1 + 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/modules/navigator/geofence.cpp b/src/modules/navigator/geofence.cpp index 482081089fb7..5fff22bae19f 100644 --- a/src/modules/navigator/geofence.cpp +++ b/src/modules/navigator/geofence.cpp @@ -131,10 +131,12 @@ bool Geofence::inside(const struct mission_item_s &mission_item) bool Geofence::inside(double lat, double lon, float altitude) { + bool inside_fence = true; + float max_horizontal_distance = _param_max_hor_distance.get(); float max_vertical_distance = _param_max_ver_distance.get(); - if (max_horizontal_distance > 1 || max_vertical_distance > 1) { + if (max_horizontal_distance > 1.0f || max_vertical_distance > 1.0f) { if (_home_pos_set) { float dist_xy = -1.0f; float dist_z = -1.0f; @@ -142,31 +144,31 @@ bool Geofence::inside(double lat, double lon, float altitude) _home_pos.lat, _home_pos.lon, _home_pos.alt, &dist_xy, &dist_z); - if (max_vertical_distance > 0 && (dist_z > max_vertical_distance)) { + if (max_vertical_distance > 1.0f && (dist_z > max_vertical_distance)) { if (hrt_elapsed_time(&_last_vertical_range_warning) > GEOFENCE_RANGE_WARNING_LIMIT) { mavlink_log_critical(_navigator->get_mavlink_log_pub(), - "Geofence exceeded max vertical distance by %.1f m", + "Maximum altitude above home exceeded by %.1f m", (double)(dist_z - max_vertical_distance)); _last_vertical_range_warning = hrt_absolute_time(); } - return false; + inside_fence = false; } - if (max_horizontal_distance > 0 && (dist_xy > max_horizontal_distance)) { + if (max_horizontal_distance > 1.0f && (dist_xy > max_horizontal_distance)) { if (hrt_elapsed_time(&_last_horizontal_range_warning) > GEOFENCE_RANGE_WARNING_LIMIT) { mavlink_log_critical(_navigator->get_mavlink_log_pub(), - "Geofence exceeded max horizontal distance by %.1f m", + "Maximum distance from home exceeded by %.1f m", (double)(dist_xy - max_horizontal_distance)); _last_horizontal_range_warning = hrt_absolute_time(); } - return false; + inside_fence = false; } } } - bool inside_fence = inside_polygon(lat, lon, altitude); + inside_fence |= inside_polygon(lat, lon, altitude); if (inside_fence) { _outside_counter = 0; diff --git a/src/modules/navigator/geofence_params.c b/src/modules/navigator/geofence_params.c index 246d1878e5f0..cc8da03ff1d6 100644 --- a/src/modules/navigator/geofence_params.c +++ b/src/modules/navigator/geofence_params.c @@ -58,6 +58,7 @@ * @value 1 Warning * @value 2 Loiter * @value 3 Return to Land + * @value 4 Flight terminate * @group Geofence */ PARAM_DEFINE_INT32(GF_ACTION, 1);