mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-18 00:10:35 +08:00
battery: pass source in by constructor
This commit is contained in:
@@ -49,8 +49,8 @@ static constexpr int DEFAULT_V_CHANNEL[1] = {0};
|
||||
static constexpr int DEFAULT_I_CHANNEL[1] = {0};
|
||||
#endif
|
||||
|
||||
AnalogBattery::AnalogBattery(int index, ModuleParams *parent, const int sample_interval_us) :
|
||||
Battery(index, parent, sample_interval_us)
|
||||
AnalogBattery::AnalogBattery(int index, ModuleParams *parent, const int sample_interval_us, const uint8_t source) :
|
||||
Battery(index, parent, sample_interval_us, source)
|
||||
{
|
||||
char param_name[17];
|
||||
|
||||
@@ -71,7 +71,7 @@ AnalogBattery::AnalogBattery(int index, ModuleParams *parent, const int sample_i
|
||||
|
||||
void
|
||||
AnalogBattery::updateBatteryStatusADC(hrt_abstime timestamp, float voltage_raw, float current_raw,
|
||||
int source, int priority)
|
||||
int priority)
|
||||
{
|
||||
float voltage_v = voltage_raw * _analog_params.v_div;
|
||||
float current_a = (current_raw - _analog_params.v_offs_cur) * _analog_params.a_per_v;
|
||||
@@ -81,7 +81,7 @@ AnalogBattery::updateBatteryStatusADC(hrt_abstime timestamp, float voltage_raw,
|
||||
|
||||
|
||||
Battery::updateBatteryStatus(timestamp, voltage_v, current_a, connected,
|
||||
source, priority);
|
||||
priority);
|
||||
}
|
||||
|
||||
bool AnalogBattery::is_valid()
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
class AnalogBattery : public Battery
|
||||
{
|
||||
public:
|
||||
AnalogBattery(int index, ModuleParams *parent, const int sample_interval_us);
|
||||
AnalogBattery(int index, ModuleParams *parent, const int sample_interval_us, const uint8_t source);
|
||||
|
||||
/**
|
||||
* Update current battery status message.
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
* @param priority: The brick number -1. The term priority refers to the Vn connection on the LTC4417
|
||||
*/
|
||||
void updateBatteryStatusADC(hrt_abstime timestamp, float voltage_raw, float current_raw,
|
||||
int source, int priority);
|
||||
int priority);
|
||||
|
||||
/**
|
||||
* Whether the ADC channel for the voltage of this battery is valid.
|
||||
|
||||
@@ -137,9 +137,9 @@ private:
|
||||
BatteryStatus::BatteryStatus() :
|
||||
ModuleParams(nullptr),
|
||||
ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::hp_default),
|
||||
_battery1(1, this, SAMPLE_INTERVAL_US),
|
||||
_battery1(1, this, SAMPLE_INTERVAL_US, battery_status_s::BATTERY_SOURCE_POWER_MODULE),
|
||||
#if BOARD_NUMBER_BRICKS > 1
|
||||
_battery2(2, this, SAMPLE_INTERVAL_US),
|
||||
_battery2(2, this, SAMPLE_INTERVAL_US, battery_status_s::BATTERY_SOURCE_POWER_MODULE),
|
||||
#endif
|
||||
_loop_perf(perf_alloc(PC_ELAPSED, MODULE_NAME))
|
||||
{
|
||||
@@ -222,7 +222,6 @@ BatteryStatus::adc_poll()
|
||||
hrt_absolute_time(),
|
||||
bat_voltage_adc_readings[b],
|
||||
bat_current_adc_readings[b],
|
||||
battery_status_s::BATTERY_SOURCE_POWER_MODULE,
|
||||
b
|
||||
);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ using namespace time_literals;
|
||||
EscBattery::EscBattery() :
|
||||
ModuleParams(nullptr),
|
||||
WorkItem(MODULE_NAME, px4::wq_configurations::lp_default),
|
||||
_battery(1, this, ESC_BATTERY_INTERVAL_US)
|
||||
_battery(1, this, ESC_BATTERY_INTERVAL_US, battery_status_s::BATTERY_SOURCE_ESCS)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -107,7 +107,6 @@ EscBattery::Run()
|
||||
average_voltage_v,
|
||||
total_current_a,
|
||||
connected,
|
||||
battery_status_s::BATTERY_SOURCE_ESCS,
|
||||
priority);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
BatterySimulator::BatterySimulator() :
|
||||
ModuleParams(nullptr),
|
||||
ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::hp_default),
|
||||
_battery(1, this, BATTERY_SIMLATOR_SAMPLE_INTERVAL_US)
|
||||
_battery(1, this, BATTERY_SIMLATOR_SAMPLE_INTERVAL_US, battery_status_s::BATTERY_SOURCE_POWER_MODULE)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ void BatterySimulator::Run()
|
||||
float vbatt = math::gradual(_battery_percentage, 0.f, 1.f, _battery.empty_cell_voltage(), _battery.full_cell_voltage());
|
||||
vbatt *= _battery.cell_count();
|
||||
|
||||
_battery.updateBatteryStatus(now_us, vbatt, ibatt, true, battery_status_s::BATTERY_SOURCE_POWER_MODULE, 0);
|
||||
_battery.updateBatteryStatus(now_us, vbatt, ibatt, true, 0);
|
||||
|
||||
perf_end(_loop_perf);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user