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
+8 -5
View File
@@ -45,6 +45,7 @@
#include <px4_config.h>
#include <px4_module.h>
#include <px4_module_params.h>
#include <px4_getopt.h>
#include <px4_posix.h>
#include <px4_tasks.h>
@@ -129,7 +130,7 @@ using namespace sensors;
*/
extern "C" __EXPORT int sensors_main(int argc, char *argv[]);
class Sensors : public ModuleBase<Sensors>
class Sensors : public ModuleBase<Sensors>, public ModuleParams
{
public:
Sensors(bool hil_enabled);
@@ -229,6 +230,7 @@ private:
};
Sensors::Sensors(bool hil_enabled) :
ModuleParams(nullptr),
_hil_enabled(hil_enabled),
_loop_perf(perf_alloc(PC_ELAPSED, "sensors")),
_rc_update(_parameters),
@@ -238,6 +240,10 @@ Sensors::Sensors(bool hil_enabled) :
_airspeed_validator.set_timeout(300000);
_airspeed_validator.set_equal_value_threshold(100);
for (int b = 0; b < BOARD_NUMBER_BRICKS; b++) {
_battery[b].setParent(this);
}
}
int
@@ -396,6 +402,7 @@ Sensors::parameter_update_poll(bool forced)
orb_copy(ORB_ID(parameter_update), _params_sub, &update);
parameters_update();
updateParams();
/* update airspeed scale */
int fd = px4_open(AIRSPEED0_DEVICE_PATH, 0);
@@ -413,10 +420,6 @@ Sensors::parameter_update_poll(bool forced)
px4_close(fd);
}
for (int b = 0; b < BOARD_NUMBER_BRICKS; b++) {
_battery[b].updateParams();
}
}
}
+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;