|
|
|
@ -97,16 +97,26 @@ Battery::Battery(int index, ModuleParams *parent, const int sample_interval_us,
@@ -97,16 +97,26 @@ Battery::Battery(int index, ModuleParams *parent, const int sample_interval_us,
|
|
|
|
|
updateParams(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Battery::updateBatteryStatus(const hrt_abstime ×tamp, float voltage_v, float current_a) |
|
|
|
|
void Battery::updateVoltage(const float voltage_v) |
|
|
|
|
{ |
|
|
|
|
_voltage_v = voltage_v; |
|
|
|
|
_voltage_filter_v.update(voltage_v); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Battery::updateCurrent(const float current_a) |
|
|
|
|
{ |
|
|
|
|
_current_a = current_a; |
|
|
|
|
_current_filter_a.update(current_a); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Battery::updateBatteryStatus(const hrt_abstime ×tamp) |
|
|
|
|
{ |
|
|
|
|
if (!_battery_initialized) { |
|
|
|
|
_voltage_filter_v.reset(voltage_v); |
|
|
|
|
_current_filter_a.reset(current_a); |
|
|
|
|
_voltage_filter_v.reset(_voltage_v); |
|
|
|
|
_current_filter_a.reset(_current_a); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_voltage_filter_v.update(voltage_v); |
|
|
|
|
_current_filter_a.update(current_a); |
|
|
|
|
sumDischarged(timestamp, current_a); |
|
|
|
|
sumDischarged(timestamp, _current_a); |
|
|
|
|
estimateStateOfCharge(_voltage_filter_v.getState(), _current_filter_a.getState()); |
|
|
|
|
computeScale(); |
|
|
|
|
|
|
|
|
@ -122,15 +132,15 @@ void Battery::updateBatteryStatus(const hrt_abstime ×tamp, float voltage_v,
@@ -122,15 +132,15 @@ void Battery::updateBatteryStatus(const hrt_abstime ×tamp, float voltage_v,
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
battery_status_s battery_status{}; |
|
|
|
|
battery_status.voltage_v = voltage_v; |
|
|
|
|
battery_status.voltage_v = _voltage_v; |
|
|
|
|
battery_status.voltage_filtered_v = _voltage_filter_v.getState(); |
|
|
|
|
battery_status.current_a = current_a; |
|
|
|
|
battery_status.current_a = _current_a; |
|
|
|
|
battery_status.current_filtered_a = _current_filter_a.getState(); |
|
|
|
|
battery_status.current_average_a = _current_average_filter_a.getState(); |
|
|
|
|
battery_status.discharged_mah = _discharged_mah; |
|
|
|
|
battery_status.remaining = _state_of_charge; |
|
|
|
|
battery_status.scale = _scale; |
|
|
|
|
battery_status.time_remaining_s = computeRemainingTime(current_a); |
|
|
|
|
battery_status.time_remaining_s = computeRemainingTime(_current_a); |
|
|
|
|
battery_status.temperature = NAN; |
|
|
|
|
battery_status.cell_count = _params.n_cells; |
|
|
|
|
battery_status.connected = _connected; |
|
|
|
|