From e7dd21a0bb299d4fb965a87039fb30c46d574bf7 Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Thu, 9 Feb 2017 19:26:57 +0900 Subject: [PATCH] AP_RangeFinder: remove primary, add orientation --- libraries/AP_RangeFinder/RangeFinder.cpp | 154 ++++++++++++++++++++--- libraries/AP_RangeFinder/RangeFinder.h | 55 ++++---- 2 files changed, 162 insertions(+), 47 deletions(-) diff --git a/libraries/AP_RangeFinder/RangeFinder.cpp b/libraries/AP_RangeFinder/RangeFinder.cpp index 39fb66cc63..8c5ef28a6f 100644 --- a/libraries/AP_RangeFinder/RangeFinder.cpp +++ b/libraries/AP_RangeFinder/RangeFinder.cpp @@ -152,6 +152,13 @@ const AP_Param::GroupInfo RangeFinder::var_info[] = { // @User: Advanced AP_GROUPINFO("_POS", 49, RangeFinder, _pos_offset[0], 0.0f), + // @Param: _ORIENT + // @DisplayName: Rangefinder orientation + // @Description: Orientation of rangefinder + // @Values: 0:Forward, 1:Forward-Right, 2:Right, 3:Back-Right, 4:Back, 5:Back-Left, 6:Left, 7:Forward-Left, 24:Up, 25:Down + // @User: Advanced + AP_GROUPINFO("_ORIENT", 53, RangeFinder, _orientation[0], ROTATION_PITCH_270), + #if RANGEFINDER_MAX_INSTANCES > 1 // @Param: 2_TYPE // @DisplayName: Second Rangefinder type @@ -264,6 +271,12 @@ const AP_Param::GroupInfo RangeFinder::var_info[] = { // @User: Advanced AP_GROUPINFO("2_POS", 50, RangeFinder, _pos_offset[1], 0.0f), + // @Param: 2_ORIENT + // @DisplayName: Rangefinder 2 orientation + // @Description: Orientation of 2nd rangefinder + // @Values: 0:Forward, 1:Forward-Right, 2:Right, 3:Back-Right, 4:Back, 5:Back-Left, 6:Left, 7:Forward-Left, 24:Up, 25:Down + // @User: Advanced + AP_GROUPINFO("2_ORIENT", 54, RangeFinder, _orientation[1], ROTATION_PITCH_270), #endif #if RANGEFINDER_MAX_INSTANCES > 2 @@ -379,6 +392,12 @@ const AP_Param::GroupInfo RangeFinder::var_info[] = { // @User: Advanced AP_GROUPINFO("3_POS", 51, RangeFinder, _pos_offset[2], 0.0f), + // @Param: 3_ORIENT + // @DisplayName: Rangefinder 3 orientation + // @Description: Orientation of 3rd rangefinder + // @Values: 0:Forward, 1:Forward-Right, 2:Right, 3:Back-Right, 4:Back, 5:Back-Left, 6:Left, 7:Forward-Left, 24:Up, 25:Down + // @User: Advanced + AP_GROUPINFO("3_ORIENT", 55, RangeFinder, _orientation[2], ROTATION_PITCH_270), #endif #if RANGEFINDER_MAX_INSTANCES > 3 @@ -493,19 +512,30 @@ const AP_Param::GroupInfo RangeFinder::var_info[] = { // @Units: m // @User: Advanced AP_GROUPINFO("4_POS", 52, RangeFinder, _pos_offset[3], 0.0f), + + // @Param: 4_ORIENT + // @DisplayName: Rangefinder 4 orientation + // @Description: Orientation of 4th range finder + // @Values: 0:Forward, 1:Forward-Right, 2:Right, 3:Back-Right, 4:Back, 5:Back-Left, 6:Left, 7:Forward-Left, 24:Up, 25:Down + // @User: Advanced + AP_GROUPINFO("4_ORIENT", 56, RangeFinder, _orientation[3], ROTATION_PITCH_270), #endif AP_GROUPEND }; -RangeFinder::RangeFinder(AP_SerialManager &_serial_manager) : - primary_instance(0), +RangeFinder::RangeFinder(AP_SerialManager &_serial_manager, enum Rotation orientation_default) : num_instances(0), estimated_terrain_height(0), serial_manager(_serial_manager) { AP_Param::setup_object_defaults(this, var_info); + // set orientation defaults + for (uint8_t i=0; i=0; i--) { - if (drivers[i] != nullptr && (state[i].status == RangeFinder_Good)) { - primary_instance = i; - } - } } bool RangeFinder::_add_backend(AP_RangeFinder_Backend *backend) @@ -688,13 +711,87 @@ RangeFinder::RangeFinder_Status RangeFinder::status(uint8_t instance) const return state[instance].status; } -void RangeFinder::handle_msg(mavlink_message_t *msg) { - uint8_t i; - for (i=0; ihandle_msg(msg); - } - } + } + } +} + +// return true if we have a range finder with the specified orientation +bool RangeFinder::has_orientation(enum Rotation orientation) const +{ + uint8_t i; + return find_instance(orientation, i); +} + +// find first range finder instance with the specified orientation +bool RangeFinder::find_instance(enum Rotation orientation, uint8_t &instance) const +{ + for (uint8_t i=0; i