From a5ec64fc9968b74e18ebcb4226347d695d5f9bda Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 8 Aug 2019 13:16:54 +1000 Subject: [PATCH] AC_Fence: tidy get_breach_distance The polygon fence will soon be able to supply a breach distance - prepare for that. --- libraries/AC_Fence/AC_Fence.cpp | 22 +++++++++------------- libraries/AC_Fence/AC_Fence.h | 3 ++- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/libraries/AC_Fence/AC_Fence.cpp b/libraries/AC_Fence/AC_Fence.cpp index c57f02ed07..695831452d 100644 --- a/libraries/AC_Fence/AC_Fence.cpp +++ b/libraries/AC_Fence/AC_Fence.cpp @@ -421,22 +421,18 @@ void AC_Fence::clear_breach(uint8_t fence_type) _breached_fences &= ~fence_type; } -/// get_breach_distance - returns distance in meters outside of the given fence +/// get_breach_distance - returns maximum distance in meters outside +/// of the given fences. fence_type is a bitmask here. float AC_Fence::get_breach_distance(uint8_t fence_type) const { - switch (fence_type) { - case AC_FENCE_TYPE_ALT_MAX: - return _alt_max_breach_distance; - break; - case AC_FENCE_TYPE_CIRCLE: - return _circle_breach_distance; - break; - case AC_FENCE_TYPE_ALT_MAX | AC_FENCE_TYPE_CIRCLE: - return MAX(_alt_max_breach_distance,_circle_breach_distance); + float max = 0.0f; + if (fence_type & AC_FENCE_TYPE_ALT_MAX) { + max = MAX(_alt_max_breach_distance, max); } - - // we don't recognise the fence type so just return 0 - return 0; + if (fence_type & AC_FENCE_TYPE_CIRCLE) { + max = MAX(_circle_breach_distance, max); + } + return max; } /// manual_recovery_start - caller indicates that pilot is re-taking manual control so fence should be disabled for 10 seconds diff --git a/libraries/AC_Fence/AC_Fence.h b/libraries/AC_Fence/AC_Fence.h index 199482f481..7f055e40ef 100644 --- a/libraries/AC_Fence/AC_Fence.h +++ b/libraries/AC_Fence/AC_Fence.h @@ -72,7 +72,8 @@ public: /// get_breach_count - returns number of times we have breached the fence uint16_t get_breach_count() const { return _breach_count; } - /// get_breach_distance - returns distance in meters outside of the given fence + /// get_breach_distance - returns maximum distance in meters outside + /// of the given fences. fence_type is a bitmask here. float get_breach_distance(uint8_t fence_type) const; /// get_action - getter for user requested action on limit breach