Code cleanup

This commit is contained in:
Timothy Scott 2019-12-05 17:24:08 +01:00 committed by Julian Oes
parent 77cf081925
commit 11bbc8ae34
9 changed files with 25 additions and 23 deletions

View File

@ -137,7 +137,7 @@ private:
uORB::PublicationMulti<input_rc_s> _rc_pub{ORB_ID(input_rc)};
Battery _battery;
Battery _battery{1, nullptr};
int32_t _rssi;
battery_state _bstate;

View File

@ -101,7 +101,7 @@ private:
orb_advert_t _battery_topic;
orb_advert_t _esc_topic;
Battery _battery;
Battery _battery{1, nullptr};
bool _armed;
float _last_throttle;
@ -114,7 +114,7 @@ private:
};
DfBebopBusWrapper::DfBebopBusWrapper() :
BebopBus(BEBOP_BUS_DEVICE_PATH), _battery_topic(nullptr), _esc_topic(nullptr), _battery(), _armed(false),
BebopBus(BEBOP_BUS_DEVICE_PATH), _battery_topic(nullptr), _esc_topic(nullptr), _battery(1, nullptr), _armed(false),
_last_throttle(0.0f),
_battery_orb_class_instance(-1)
{}

View File

@ -69,7 +69,7 @@ public:
private:
int _publish(const struct ltc2946_sensor_data &data);
Battery _battery{};
Battery _battery{1, nullptr};
int _actuator_ctrl_0_sub{-1};
int _vcontrol_mode_sub{-1};

View File

@ -46,7 +46,9 @@
VOXLPM::VOXLPM(const char *path, int bus, int address, VOXLPM_CH_TYPE ch_type) :
I2C("voxlpm", path, bus, address, 400000),
ScheduledWorkItem(MODULE_NAME, px4::device_bus_to_wq(I2C::get_device_id())),
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": sample"))
ModuleParams(nullptr),
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": sample")),
_battery(1, this)
{
_ch_type = ch_type;
@ -129,6 +131,13 @@ VOXLPM::Run()
int
VOXLPM::measure()
{
parameter_update_s update;
if (_parameter_sub.update(&update)) {
updateParams();
}
_voltage = 0.0f;
_amperage = 0.0f;

View File

@ -68,8 +68,10 @@
#include <battery/battery.h>
#include <uORB/PublicationMulti.hpp>
#include <uORB/Subscription.hpp>
#include <uORB/topics/battery_status.h>
#include <uORB/topics/power_monitor.h>
#include <uORB/topics/parameter_update.h>
/*
* Note that these are unshifted addresses.
@ -142,7 +144,7 @@ enum VOXLPM_CH_TYPE {
VOXLPM_CH_TYPE_P5VDC
};
class VOXLPM : public device::I2C, public px4::ScheduledWorkItem
class VOXLPM : public device::I2C, public px4::ScheduledWorkItem, public ModuleParams
{
public:
VOXLPM(const char *path, int bus, int address, VOXLPM_CH_TYPE ch_type);
@ -161,6 +163,7 @@ private:
perf_counter_t _sample_perf;
uORB::PublicationMulti<power_monitor_s> _pm_pub_topic{ORB_ID(power_monitor)};
uORB::Subscription _parameter_sub{ORB_ID(parameter_update)};
power_monitor_s _pm_status{};

View File

@ -63,7 +63,7 @@
class Battery : public ModuleParams
{
public:
Battery(int index = 1, ModuleParams *parent = nullptr);
Battery(int index, ModuleParams *parent);
/**
* Reset all battery stats and report invalid/nothing.
@ -200,19 +200,12 @@ protected:
if (!firstcall) {
if ((float) fabs((float) *old_val - (float) previous_old_val) > FLT_EPSILON
&& (float) fabs((float) *old_val - (float) *new_val) > FLT_EPSILON) {
// TODO fix this error message. I was getting hardfaults while using this message, but they stopped
// after removing this message. I was unable to determine why I was getting them.
PX4_WARN("Detected change of deprecated parameter %s. Please use the new parameter %s instead. "
"The new value of the deprecated parameter will be copied to the new parameter.",
param_name(old_param), param_name(new_param));
param_set_no_notification(new_param, old_val);
param_get(new_param, new_val);
return true;
} else if ((float) fabs((float) *new_val - (float) previous_new_val) > FLT_EPSILON
&& (float) fabs((float) *old_val - (float) *new_val) > FLT_EPSILON) {
PX4_INFO("Copying new value for %s to deprecated parameter %s.",
param_name(new_param), param_name(old_param));
param_set_no_notification(old_param, new_val);
param_get(old_param, old_val);
return true;
@ -220,9 +213,6 @@ protected:
} else {
if ((float) fabs((float) *old_val - (float) *new_val) > FLT_EPSILON) {
PX4_WARN("At boot, deprecated parameter %s is different from its replacement %s."
" The new value will be overwritten by the old one. This should happen only once.",
param_name(old_param), param_name(new_param));
param_set_no_notification(new_param, old_val);
param_get(new_param, new_val);
return true;

View File

@ -58,10 +58,6 @@ AnalogBattery::updateBatteryStatusRawADC(hrt_abstime timestamp, int32_t voltage_
selected_source, priority, throttle_normalized, armed, _params.source == 0);
}
/**
* Whether the ADC channel for the voltage of this battery is valid.
* Corresponds to BOARD_BRICK_VALID_LIST
*/
bool AnalogBattery::is_valid()
{
#ifdef BOARD_BRICK_VALID_LIST

View File

@ -39,7 +39,7 @@
class AnalogBattery : public Battery
{
public:
AnalogBattery(int index = 1, ModuleParams *parent = nullptr);
AnalogBattery(int index, ModuleParams *parent);
/**
* Update current battery status message.

View File

@ -238,10 +238,14 @@ private:
hrt_abstime _last_sitl_timestamp{0};
hrt_abstime _last_battery_timestamp{0};
class : public Battery
class SimulatorBattery : public Battery
{
public:
SimulatorBattery() : Battery(1, nullptr) {}
virtual void updateParams() override
{
Battery::updateParams();
_params.v_empty = 3.5f;
_params.v_charged = 4.05f;
_params.n_cells = 4;