battery: allow for external state of charge injection

This commit is contained in:
Matthias Grob 2022-09-22 10:32:12 +02:00
parent babe93c3bf
commit 9e776741d9
2 changed files with 17 additions and 4 deletions

View File

@ -119,7 +119,13 @@ void Battery::updateBatteryStatus(const hrt_abstime &timestamp)
} }
sumDischarged(timestamp, _current_a); sumDischarged(timestamp, _current_a);
estimateStateOfCharge(_voltage_filter_v.getState(), _current_filter_a.getState()); _state_of_charge_volt_based =
calculateStateOfChargeVoltageBased(_voltage_filter_v.getState(), _current_filter_a.getState());
if (!_external_state_of_charge) {
estimateStateOfCharge();
}
computeScale(); computeScale();
if (_connected && _battery_initialized) { if (_connected && _battery_initialized) {
@ -192,7 +198,7 @@ void Battery::sumDischarged(const hrt_abstime &timestamp, float current_a)
_last_timestamp = timestamp; _last_timestamp = timestamp;
} }
void Battery::estimateStateOfCharge(const float voltage_v, const float current_a) float Battery::calculateStateOfChargeVoltageBased(const float voltage_v, const float current_a)
{ {
// remaining battery capacity based on voltage // remaining battery capacity based on voltage
float cell_voltage = voltage_v / _params.n_cells; float cell_voltage = voltage_v / _params.n_cells;
@ -215,8 +221,11 @@ void Battery::estimateStateOfCharge(const float voltage_v, const float current_a
cell_voltage += throttle * _params.v_load_drop; cell_voltage += throttle * _params.v_load_drop;
} }
_state_of_charge_volt_based = math::interpolate(cell_voltage, _params.v_empty, _params.v_charged, 0.f, 1.f); return math::interpolate(cell_voltage, _params.v_empty, _params.v_charged, 0.f, 1.f);
}
void Battery::estimateStateOfCharge()
{
// choose which quantity we're using for final reporting // choose which quantity we're using for final reporting
if (_params.capacity > 0.f && _battery_initialized) { if (_params.capacity > 0.f && _battery_initialized) {
// if battery capacity is known, fuse voltage measurement with used capacity // if battery capacity is known, fuse voltage measurement with used capacity

View File

@ -88,6 +88,7 @@ public:
void setPriority(const uint8_t priority) { _priority = priority; } void setPriority(const uint8_t priority) { _priority = priority; }
void setConnected(const bool connected) { _connected = connected; } void setConnected(const bool connected) { _connected = connected; }
void setStateOfCharge(const float soc) { _state_of_charge = soc; _external_state_of_charge = true; }
void updateVoltage(const float voltage_v); void updateVoltage(const float voltage_v);
void updateCurrent(const float current_a); void updateCurrent(const float current_a);
@ -144,7 +145,8 @@ protected:
private: private:
void sumDischarged(const hrt_abstime &timestamp, float current_a); void sumDischarged(const hrt_abstime &timestamp, float current_a);
void estimateStateOfCharge(const float voltage_v, const float current_a); float calculateStateOfChargeVoltageBased(const float voltage_v, const float current_a);
void estimateStateOfCharge();
uint8_t determineWarning(float state_of_charge); uint8_t determineWarning(float state_of_charge);
void computeScale(); void computeScale();
float computeRemainingTime(float current_a); float computeRemainingTime(float current_a);
@ -153,6 +155,8 @@ private:
uORB::Subscription _vehicle_status_sub{ORB_ID(vehicle_status)}; uORB::Subscription _vehicle_status_sub{ORB_ID(vehicle_status)};
uORB::PublicationMulti<battery_status_s> _battery_status_pub{ORB_ID(battery_status)}; uORB::PublicationMulti<battery_status_s> _battery_status_pub{ORB_ID(battery_status)};
bool _external_state_of_charge{false}; ///< inticates that the soc is injected and not updated by this library
bool _connected{false}; bool _connected{false};
const uint8_t _source; const uint8_t _source;
uint8_t _priority{0}; uint8_t _priority{0};