refactor Battery: replace BlockParam* with Param* classes

This commit is contained in:
Beat Küng
2018-03-22 08:19:08 +01:00
parent e32d8ea8b6
commit 7937f9e82c
3 changed files with 22 additions and 39 deletions
+1 -14
View File
@@ -43,25 +43,12 @@
#include <mathlib/mathlib.h>
Battery::Battery() :
SuperBlock(nullptr, "BAT"),
_v_empty(this, "V_EMPTY"),
_v_charged(this, "V_CHARGED"),
_n_cells(this, "N_CELLS"),
_capacity(this, "CAPACITY"),
_v_load_drop(this, "V_LOAD_DROP"),
_r_internal(this, "R_INTERNAL"),
_low_thr(this, "LOW_THR"),
_crit_thr(this, "CRIT_THR"),
_emergency_thr(this, "EMERGEN_THR"),
ModuleParams(nullptr),
_warning(battery_status_s::BATTERY_WARNING_NONE),
_last_timestamp(0)
{
}
Battery::~Battery()
{
}
void
Battery::reset(battery_status_s *battery_status)
{
+13 -20
View File
@@ -41,25 +41,16 @@
#pragma once
#include <controllib/blocks.hpp>
#include <controllib/block/BlockParam.hpp>
#include <uORB/topics/battery_status.h>
#include <drivers/drv_hrt.h>
#include <px4_module_params.h>
class Battery : public control::SuperBlock
class Battery : public ModuleParams
{
public:
/**
* Constructor
*/
Battery();
/**
* Destructor
*/
~Battery();
/**
* Reset all battery stats and report invalid/nothing.
*/
@@ -103,15 +94,17 @@ private:
void determineWarning(bool connected);
void computeScale();
control::BlockParamFloat _v_empty;
control::BlockParamFloat _v_charged;
control::BlockParamInt _n_cells;
control::BlockParamFloat _capacity;
control::BlockParamFloat _v_load_drop;
control::BlockParamFloat _r_internal;
control::BlockParamFloat _low_thr;
control::BlockParamFloat _crit_thr;
control::BlockParamFloat _emergency_thr;
DEFINE_PARAMETERS(
(ParamFloat<px4::params::BAT_V_EMPTY>) _v_empty,
(ParamFloat<px4::params::BAT_V_CHARGED>) _v_charged,
(ParamInt<px4::params::BAT_N_CELLS>) _n_cells,
(ParamFloat<px4::params::BAT_CAPACITY>) _capacity,
(ParamFloat<px4::params::BAT_V_LOAD_DROP>) _v_load_drop,
(ParamFloat<px4::params::BAT_R_INTERNAL>) _r_internal,
(ParamFloat<px4::params::BAT_LOW_THR>) _low_thr,
(ParamFloat<px4::params::BAT_CRIT_THR>) _crit_thr,
(ParamFloat<px4::params::BAT_EMERGEN_THR>) _emergency_thr
)
bool _battery_initialized = false;
float _voltage_filtered_v = -1.f;