battery: fetch throttle value inside of class

This commit is contained in:
Matthias Grob
2021-12-07 21:06:51 +01:00
parent ddc6b6bc9c
commit b965923c08
17 changed files with 38 additions and 81 deletions
+12 -5
View File
@@ -97,19 +97,17 @@ Battery::Battery(int index, ModuleParams *parent, const int sample_interval_us)
}
void Battery::updateBatteryStatus(const hrt_abstime &timestamp, float voltage_v, float current_a, bool connected,
int source, int priority, float throttle_normalized)
int source, int priority)
{
if (!_battery_initialized) {
_voltage_filter_v.reset(voltage_v);
_current_filter_a.reset(current_a);
_throttle_filter.reset(throttle_normalized);
}
_voltage_filter_v.update(voltage_v);
_current_filter_a.update(current_a);
_throttle_filter.update(throttle_normalized);
sumDischarged(timestamp, current_a);
estimateStateOfCharge(_voltage_filter_v.getState(), _current_filter_a.getState(), _throttle_filter.getState());
estimateStateOfCharge(_voltage_filter_v.getState(), _current_filter_a.getState());
computeScale();
if (connected && _battery_initialized) {
@@ -169,7 +167,7 @@ void Battery::sumDischarged(const hrt_abstime &timestamp, float current_a)
_last_timestamp = timestamp;
}
void Battery::estimateStateOfCharge(const float voltage_v, const float current_a, const float throttle)
void Battery::estimateStateOfCharge(const float voltage_v, const float current_a)
{
// remaining battery capacity based on voltage
float cell_voltage = voltage_v / _params.n_cells;
@@ -179,6 +177,15 @@ void Battery::estimateStateOfCharge(const float voltage_v, const float current_a
cell_voltage += _params.r_internal * current_a;
} else {
actuator_controls_s actuator_controls{};
_actuator_controls_0_sub.copy(&actuator_controls);
const float throttle = actuator_controls.control[actuator_controls_s::INDEX_THROTTLE];
_throttle_filter.update(throttle);
if (!_battery_initialized) {
_throttle_filter.reset(throttle);
}
// assume linear relation between throttle and voltage drop
cell_voltage += throttle * _params.v_load_drop;
}
+5 -3
View File
@@ -54,6 +54,8 @@
#include <lib/parameters/param.h>
#include <lib/mathlib/math/filter/AlphaFilter.hpp>
#include <uORB/PublicationMulti.hpp>
#include <uORB/Subscription.hpp>
#include <uORB/topics/actuator_controls.h>
#include <uORB/topics/battery_status.h>
/**
@@ -91,10 +93,9 @@ public:
* @param timestamp: Time at which the ADC was read (use hrt_absolute_time())
* @param source: Source type in relation to BAT%d_SOURCE param.
* @param priority: The brick number -1. The term priority refers to the Vn connection on the LTC4417
* @param throttle_normalized: Throttle of the vehicle, between 0 and 1
*/
void updateBatteryStatus(const hrt_abstime &timestamp, float voltage_v, float current_a, bool connected,
int source, int priority, float throttle_normalized);
int source, int priority);
protected:
struct {
@@ -130,11 +131,12 @@ protected:
private:
void sumDischarged(const hrt_abstime &timestamp, float current_a);
void estimateStateOfCharge(const float voltage_v, const float current_a, const float throttle);
void estimateStateOfCharge(const float voltage_v, const float current_a);
uint8_t determineWarning(float state_of_charge);
void computeScale();
float computeRemainingTime(float current_a);
uORB::Subscription _actuator_controls_0_sub{ORB_ID(actuator_controls_0)};
uORB::PublicationMulti<battery_status_s> _battery_status_pub{ORB_ID(battery_status)};
bool _battery_initialized{false};