Browse Source

AP_RangeFinder: added SONAR_RMETRIC option

this allows correct support for non-ratiometric rangefinders such as
the SF/02
master
Andrew Tridgell 11 years ago
parent
commit
6f33ca4988
  1. 6
      libraries/AP_RangeFinder/AP_RangeFinder_analog.cpp
  2. 14
      libraries/AP_RangeFinder/RangeFinder.cpp
  3. 1
      libraries/AP_RangeFinder/RangeFinder.h

6
libraries/AP_RangeFinder/AP_RangeFinder_analog.cpp

@ -72,7 +72,11 @@ void AP_RangeFinder_analog::update_voltage(void) @@ -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;
}
}
/*

14
libraries/AP_RangeFinder/RangeFinder.cpp

@ -76,7 +76,13 @@ const AP_Param::GroupInfo RangeFinder::var_info[] PROGMEM = { @@ -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 = { @@ -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

1
libraries/AP_RangeFinder/RangeFinder.h

@ -68,6 +68,7 @@ public: @@ -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];

Loading…
Cancel
Save