Skip to content

Commit

Permalink
battery: switch to PublicationMulti for battery_status
Browse files Browse the repository at this point in the history
  • Loading branch information
MaEtUgR committed Aug 26, 2020
1 parent dc1870d commit 233c2c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
9 changes: 2 additions & 7 deletions src/lib/battery/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ Battery::Battery(int index, ModuleParams *parent, const int sample_interval_us)
updateParams();
}

Battery::~Battery()
{
orb_unadvertise(_battery_status_pub);
}

void
Battery::reset()
{
Expand Down Expand Up @@ -179,15 +174,15 @@ Battery::updateBatteryStatus(hrt_abstime timestamp, float voltage_v, float curre
const bool should_publish = (source == _params.source);

if (should_publish) {
_battery_status_pub.publish(_battery_status);
publish();
}
}

void
Battery::publish()
{
int dummy; // We're not interested in the instance ID we get
orb_publish_auto(ORB_ID(battery_status), &_battery_status_pub, &_battery_status, &dummy);
_battery_status_pub.publish(_battery_status);
}

void
Expand Down
8 changes: 4 additions & 4 deletions src/lib/battery/battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#pragma once

#include <uORB/uORB.h>
#include <uORB/PublicationMulti.hpp>
#include <uORB/topics/battery_status.h>
#include <drivers/drv_hrt.h>
#include <px4_platform_common/module_params.h>
Expand All @@ -63,8 +64,7 @@ class Battery : public ModuleParams
{
public:
Battery(int index, ModuleParams *parent, const int sample_interval_us);

~Battery();
~Battery() = default;

/**
* Reset all battery stats and report invalid/nothing.
Expand Down Expand Up @@ -202,6 +202,8 @@ class Battery : public ModuleParams
void determineWarning(bool connected);
void computeScale();

uORB::PublicationMulti<battery_status_s> _battery_status_pub{ORB_ID(battery_status)};

bool _battery_initialized = false;
AlphaFilter<float> _voltage_filter_v;
AlphaFilter<float> _current_filter_a;
Expand All @@ -213,6 +215,4 @@ class Battery : public ModuleParams
float _scale = 1.f;
uint8_t _warning;
hrt_abstime _last_timestamp;

orb_advert_t _battery_status_pub{nullptr};
};

0 comments on commit 233c2c9

Please sign in to comment.