diff --git a/libraries/AP_RangeFinder/RangeFinder.cpp b/libraries/AP_RangeFinder/RangeFinder.cpp index d775f3445e..99689b36d8 100644 --- a/libraries/AP_RangeFinder/RangeFinder.cpp +++ b/libraries/AP_RangeFinder/RangeFinder.cpp @@ -544,15 +544,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; }