diff --git a/libraries/AP_RangeFinder/AP_RangeFinder_analog.cpp b/libraries/AP_RangeFinder/AP_RangeFinder_analog.cpp index 5eb6a984a9..89acfb3dad 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder_analog.cpp +++ b/libraries/AP_RangeFinder/AP_RangeFinder_analog.cpp @@ -72,7 +72,11 @@ void AP_RangeFinder_analog::update_voltage(void) source->set_pin(ranger._pin[state.instance]); source->set_stop_pin((uint8_t)ranger._stop_pin[state.instance]); source->set_settle_time((uint16_t)ranger._settle_time_ms[state.instance]); - state.voltage_mv = source->voltage_average_ratiometric() * 1000U; + if (ranger._ratiometric[state.instance]) { + state.voltage_mv = source->voltage_average_ratiometric() * 1000U; + } else { + state.voltage_mv = source->voltage_average() * 1000U; + } } /* diff --git a/libraries/AP_RangeFinder/RangeFinder.cpp b/libraries/AP_RangeFinder/RangeFinder.cpp index 293c4bb417..ddcd9519ed 100644 --- a/libraries/AP_RangeFinder/RangeFinder.cpp +++ b/libraries/AP_RangeFinder/RangeFinder.cpp @@ -76,7 +76,13 @@ const AP_Param::GroupInfo RangeFinder::var_info[] PROGMEM = { // @Increment: 1 AP_GROUPINFO("_SETTLE_MS", 8, RangeFinder, _settle_time_ms[0], 0), - // 9..12 left for future expansion + // @Param: _RMETRIC + // @DisplayName: Ratiometric + // @Description: This parameter sets whether an analog rangefinder is ratiometric. Most analog sonars are ratiometric, meaning that their output voltage is influenced by the supply voltage. Some analog rangefinders (such as the SF/02) have their own internal voltage regulators so they are not ratiometric + // @Values: 0:No,1:Yes + AP_GROUPINFO("_RMETRIC", 9, RangeFinder, _ratiometric[0], 1), + + // 10..12 left for future expansion #if RANGEFINDER_MAX_INSTANCES > 1 // @Param: 2_PIN @@ -129,6 +135,12 @@ const AP_Param::GroupInfo RangeFinder::var_info[] PROGMEM = { // @Units: milliseconds // @Increment: 1 AP_GROUPINFO("2_SETTLE_MS", 20, RangeFinder, _settle_time_ms[1], 0), + + // @Param: 2_RMETRIC + // @DisplayName: Ratiometric + // @Description: This parameter sets whether an analog rangefinder is ratiometric. Most analog sonars are ratiometric, meaning that their output voltage is influenced by the supply voltage. Some analog rangefinders (such as the SF/02) have their own internal voltage regulators so they are not ratiometric + // @Values: 0:No,1:Yes + AP_GROUPINFO("2_RMETRIC", 21, RangeFinder, _ratiometric[1], 1), #endif AP_GROUPEND diff --git a/libraries/AP_RangeFinder/RangeFinder.h b/libraries/AP_RangeFinder/RangeFinder.h index 870b6e11f1..8a7c4b0f18 100644 --- a/libraries/AP_RangeFinder/RangeFinder.h +++ b/libraries/AP_RangeFinder/RangeFinder.h @@ -68,6 +68,7 @@ public: // parameters for each instance AP_Int8 _type[RANGEFINDER_MAX_INSTANCES]; AP_Int8 _pin[RANGEFINDER_MAX_INSTANCES]; + AP_Int8 _ratiometric[RANGEFINDER_MAX_INSTANCES]; AP_Int8 _stop_pin[RANGEFINDER_MAX_INSTANCES]; AP_Int16 _settle_time_ms[RANGEFINDER_MAX_INSTANCES]; AP_Float _scaling[RANGEFINDER_MAX_INSTANCES];