diff --git a/src/modules/systemlib/battery.cpp b/src/modules/systemlib/battery.cpp index 6adea6cbfb..f5f45d78ad 100644 --- a/src/modules/systemlib/battery.cpp +++ b/src/modules/systemlib/battery.cpp @@ -48,6 +48,8 @@ Battery::Battery() : _param_n_cells(this, "N_CELLS"), _param_capacity(this, "CAPACITY"), _param_v_load_drop(this, "V_LOAD_DROP"), + _param_low_thr(this, "LOW_THR"), + _param_crit_thr(this, "CRIT_THR"), _voltage_filtered_v(0.0f), _throttle_filtered(0.0f), _discharged_mah(0.0f), @@ -162,13 +164,11 @@ Battery::estimateRemaining(float voltage_v, float throttle_normalized) void Battery::determineWarning() { - // TODO: Determine threshold or make params. - // Smallest values must come first - if (_remaining < 0.09f) { + if (_remaining < _param_crit_thr.get()) { _warning = battery_status_s::BATTERY_WARNING_CRITICAL; - } else if (_remaining < 0.18f) { + } else if (_remaining < _param_low_thr.get()) { _warning = battery_status_s::BATTERY_WARNING_LOW; } } diff --git a/src/modules/systemlib/battery.h b/src/modules/systemlib/battery.h index 6b909a275f..7a9e0759cf 100644 --- a/src/modules/systemlib/battery.h +++ b/src/modules/systemlib/battery.h @@ -101,6 +101,8 @@ private: control::BlockParamInt _param_n_cells; control::BlockParamFloat _param_capacity; control::BlockParamFloat _param_v_load_drop; + control::BlockParamFloat _param_low_thr; + control::BlockParamFloat _param_crit_thr; float _voltage_filtered_v; float _throttle_filtered; diff --git a/src/modules/systemlib/battery_params.c b/src/modules/systemlib/battery_params.c index 72d71c53b3..e816178166 100644 --- a/src/modules/systemlib/battery_params.c +++ b/src/modules/systemlib/battery_params.c @@ -66,6 +66,36 @@ PARAM_DEFINE_FLOAT(BAT_V_EMPTY, 3.4f); */ PARAM_DEFINE_FLOAT(BAT_V_CHARGED, 4.2f); +/** + * Low threshold + * + * Sets the threshold (between 0 and 1, which is equivalent to between 0 and 100%) + * when the battery will be reported as low. This has to be higher than the critical + * threshold. + * + * @group Battery Calibration + * @decimal 2 + * @min 0.15 + * @max 0.5 + * @increment 0.01 + */ +PARAM_DEFINE_FLOAT(BAT_LOW_THR, 0.18f); + +/** + * Critical threshold + * + * Sets the threshold (between 0 and 1, which is equivalent to between 0 and 100%) + * when the battery will be reported as critically low. This has to be lower than + * the low threshold. This threshold commonly will trigger RTL or landing. + * + * @group Battery Calibration + * @decimal 2 + * @min 0.05 + * @max 0.14 + * @increment 0.01 + */ +PARAM_DEFINE_FLOAT(BAT_CRIT_THR, 0.09f); + /** * Voltage drop per cell on 100% load *