mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-01 02:55:07 +08:00
battery_status: do not publish if no voltage channel is defined
This is the case for boards with digital readout, like v5x, but still enable the battery_status module for external analog driver options. An alternative would be to not run battery_status depending on config.
This commit is contained in:
@@ -145,7 +145,10 @@
|
|||||||
# define BOARD_BATT_I_LIST {ADC_BATTERY_CURRENT_CHANNEL}
|
# define BOARD_BATT_I_LIST {ADC_BATTERY_CURRENT_CHANNEL}
|
||||||
# define BOARD_BRICK_VALID_LIST {BOARD_ADC_BRICK_VALID}
|
# define BOARD_BRICK_VALID_LIST {BOARD_ADC_BRICK_VALID}
|
||||||
#elif BOARD_NUMBER_BRICKS == 2
|
#elif BOARD_NUMBER_BRICKS == 2
|
||||||
# if !defined(BOARD_NUMBER_DIGITAL_BRICKS)
|
# if defined(BOARD_NUMBER_DIGITAL_BRICKS)
|
||||||
|
# define BOARD_BATT_V_LIST {-1, -1}
|
||||||
|
# define BOARD_BATT_I_LIST {-1, -1}
|
||||||
|
# else
|
||||||
# define BOARD_BATT_V_LIST {ADC_BATTERY1_VOLTAGE_CHANNEL, ADC_BATTERY2_VOLTAGE_CHANNEL}
|
# define BOARD_BATT_V_LIST {ADC_BATTERY1_VOLTAGE_CHANNEL, ADC_BATTERY2_VOLTAGE_CHANNEL}
|
||||||
# define BOARD_BATT_I_LIST {ADC_BATTERY1_CURRENT_CHANNEL, ADC_BATTERY2_CURRENT_CHANNEL}
|
# define BOARD_BATT_I_LIST {ADC_BATTERY1_CURRENT_CHANNEL, ADC_BATTERY2_CURRENT_CHANNEL}
|
||||||
# endif
|
# endif
|
||||||
|
|||||||
@@ -41,12 +41,11 @@
|
|||||||
static constexpr int DEFAULT_V_CHANNEL[BOARD_NUMBER_BRICKS] = BOARD_BATT_V_LIST;
|
static constexpr int DEFAULT_V_CHANNEL[BOARD_NUMBER_BRICKS] = BOARD_BATT_V_LIST;
|
||||||
static constexpr int DEFAULT_I_CHANNEL[BOARD_NUMBER_BRICKS] = BOARD_BATT_I_LIST;
|
static constexpr int DEFAULT_I_CHANNEL[BOARD_NUMBER_BRICKS] = BOARD_BATT_I_LIST;
|
||||||
#else
|
#else
|
||||||
static constexpr int DEFAULT_V_CHANNEL[BOARD_NUMBER_BRICKS] = {0};
|
#error "BOARD_BATT_V_LIST and BOARD_BATT_I_LIST need to be defined"
|
||||||
static constexpr int DEFAULT_I_CHANNEL[BOARD_NUMBER_BRICKS] = {0};
|
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
static constexpr int DEFAULT_V_CHANNEL[1] = {0};
|
static constexpr int DEFAULT_V_CHANNEL[1] = {-1};
|
||||||
static constexpr int DEFAULT_I_CHANNEL[1] = {0};
|
static constexpr int DEFAULT_I_CHANNEL[1] = {-1};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
AnalogBattery::AnalogBattery(int index, ModuleParams *parent, const int sample_interval_us, const uint8_t source,
|
AnalogBattery::AnalogBattery(int index, ModuleParams *parent, const int sample_interval_us, const uint8_t source,
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ BatteryStatus::adc_poll()
|
|||||||
/* Per Brick readings with default unread channels at 0 */
|
/* Per Brick readings with default unread channels at 0 */
|
||||||
float bat_current_adc_readings[BOARD_NUMBER_BRICKS] {};
|
float bat_current_adc_readings[BOARD_NUMBER_BRICKS] {};
|
||||||
float bat_voltage_adc_readings[BOARD_NUMBER_BRICKS] {};
|
float bat_voltage_adc_readings[BOARD_NUMBER_BRICKS] {};
|
||||||
|
bool has_bat_voltage_adc_channel[BOARD_NUMBER_BRICKS] {};
|
||||||
|
|
||||||
int selected_source = -1;
|
int selected_source = -1;
|
||||||
|
|
||||||
@@ -201,23 +202,27 @@ BatteryStatus::adc_poll()
|
|||||||
|
|
||||||
/* look for specific channels and process the raw voltage to measurement data */
|
/* look for specific channels and process the raw voltage to measurement data */
|
||||||
|
|
||||||
|
if (adc_report.channel_id[i] >= 0) {
|
||||||
if (adc_report.channel_id[i] == _analogBatteries[b]->get_voltage_channel()) {
|
if (adc_report.channel_id[i] == _analogBatteries[b]->get_voltage_channel()) {
|
||||||
/* Voltage in volts */
|
/* Voltage in volts */
|
||||||
bat_voltage_adc_readings[b] = adc_report.raw_data[i] *
|
bat_voltage_adc_readings[b] = adc_report.raw_data[i] *
|
||||||
adc_report.v_ref /
|
adc_report.v_ref /
|
||||||
adc_report.resolution;
|
adc_report.resolution;
|
||||||
|
has_bat_voltage_adc_channel[b] = true;
|
||||||
|
|
||||||
} else if (adc_report.channel_id[i] == _analogBatteries[b]->get_current_channel()) {
|
} else if (adc_report.channel_id[i] == _analogBatteries[b]->get_current_channel()) {
|
||||||
bat_current_adc_readings[b] = adc_report.raw_data[i] *
|
bat_current_adc_readings[b] = adc_report.raw_data[i] *
|
||||||
adc_report.v_ref /
|
adc_report.v_ref /
|
||||||
adc_report.resolution;
|
adc_report.resolution;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int b = 0; b < BOARD_NUMBER_BRICKS; b++) {
|
for (int b = 0; b < BOARD_NUMBER_BRICKS; b++) {
|
||||||
|
|
||||||
|
if (has_bat_voltage_adc_channel[b]) { // Do not publish if no voltage channel configured
|
||||||
_analogBatteries[b]->updateBatteryStatusADC(
|
_analogBatteries[b]->updateBatteryStatusADC(
|
||||||
hrt_absolute_time(),
|
hrt_absolute_time(),
|
||||||
bat_voltage_adc_readings[b],
|
bat_voltage_adc_readings[b],
|
||||||
@@ -225,6 +230,7 @@ BatteryStatus::adc_poll()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user