43 #include <mathlib/mathlib.h> 45 #include <px4_platform_common/defines.h> 48 ModuleParams(nullptr),
57 memset(battery_status, 0,
sizeof(*battery_status));
60 battery_status->
scale = 1.f;
61 battery_status->
cell_count = _param_bat_n_cells.get();
63 battery_status->
warning = battery_status_s::BATTERY_WARNING_NONE;
69 bool connected,
bool selected_source,
int priority,
70 float throttle_normalized,
73 reset(battery_status);
82 if (_battery_initialized) {
87 _battery_initialized =
true;
107 if (!_battery_initialized) {
114 if (PX4_ISFINITE(filtered_next)) {
122 if (!_battery_initialized) {
129 if (PX4_ISFINITE(filtered_next)) {
136 if (!_battery_initialized) {
142 if (PX4_ISFINITE(filtered_next)) {
151 if (current_a < 0.
f) {
173 float cell_voltage = voltage_v / _param_bat_n_cells.get();
176 if (_param_bat_r_internal.get() >= 0.f) {
177 cell_voltage += _param_bat_r_internal.get() * current_a;
181 cell_voltage += throttle * _param_bat_v_load_drop.get();
187 if (_param_bat_capacity.get() > 0.f) {
189 if (!_battery_initialized) {
213 if (
_remaining < _param_bat_emergen_thr.get() || (
_warning == battery_status_s::BATTERY_WARNING_EMERGENCY)) {
214 _warning = battery_status_s::BATTERY_WARNING_EMERGENCY;
216 }
else if (
_remaining < _param_bat_crit_thr.get() || (
_warning == battery_status_s::BATTERY_WARNING_CRITICAL)) {
217 _warning = battery_status_s::BATTERY_WARNING_CRITICAL;
219 }
else if (
_remaining < _param_bat_low_thr.get() || (
_warning == battery_status_s::BATTERY_WARNING_LOW)) {
220 _warning = battery_status_s::BATTERY_WARNING_LOW;
228 const float voltage_range = (_param_bat_v_charged.get() - _param_bat_v_empty.get());
233 _scale = _param_bat_v_charged.get() / bat_v;
float _current_filtered_a
void filterThrottle(float throttle)
void reset(battery_status_s *battery_status)
Reset all battery stats and report invalid/nothing.
hrt_abstime _last_timestamp
float _discharged_mah_loop
void sumDischarged(hrt_abstime timestamp, float current_a)
Library calls for battery functionality.
float _remaining_voltage
normalized battery charge level remaining based on voltage
const T gradual(const T &value, const T &x_low, const T &x_high, const T &y_low, const T &y_high)
void filterVoltage(float voltage_v)
void estimateRemaining(float voltage_v, float current_a, float throttle, bool armed)
static struct actuator_armed_s armed
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
void determineWarning(bool connected)
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
void updateBatteryStatus(hrt_abstime timestamp, float voltage_v, float current_a, bool connected, bool selected_source, int priority, float throttle_normalized, bool armed, battery_status_s *status)
Update current battery status message.
float _remaining
normalized battery charge level, selected based on config param
constexpr _Tp max(_Tp a, _Tp b)
float _voltage_filtered_v
void filterCurrent(float current_a)