diff --git a/libraries/AP_RangeFinder/RangeFinder.cpp b/libraries/AP_RangeFinder/RangeFinder.cpp index 5ce6a9f8e7..a0a012b91c 100644 --- a/libraries/AP_RangeFinder/RangeFinder.cpp +++ b/libraries/AP_RangeFinder/RangeFinder.cpp @@ -570,15 +570,22 @@ bool RangeFinder::has_orientation(enum Rotation orientation) const // find first range finder instance with the specified orientation AP_RangeFinder_Backend *RangeFinder::find_instance(enum Rotation orientation) const { + // first try for a rangefinder that is in range for (uint8_t i=0; iorientation() == orientation && + backend->status() == RangeFinder_Good) { + return backend; } - if (backend->orientation() != orientation) { - continue; + } + // if none in range then return first with correct orientation + for (uint8_t i=0; iorientation() == orientation) { + return backend; } - return backend; } return nullptr; }