battery: update parameters on change

Signed-off-by: RomanBapst <bapstroman@gmail.com>
This commit is contained in:
RomanBapst 2023-10-06 17:35:43 +03:00
parent aa87b2ef4d
commit 839ba751cc
2 changed files with 13 additions and 0 deletions

View File

@ -113,6 +113,14 @@ void Battery::updateCurrent(const float current_a)
void Battery::updateBatteryStatus(const hrt_abstime &timestamp)
{
if (_parameter_update_sub.updated()) {
// Read from topic to clear updated flag
parameter_update_s parameter_update;
_parameter_update_sub.copy(&parameter_update);
updateParams();
}
if (!_battery_initialized) {
_voltage_filter_v.reset(_voltage_v);
_current_filter_a.reset(_current_a);

View File

@ -58,6 +58,10 @@
#include <uORB/topics/battery_status.h>
#include <uORB/topics/vehicle_status.h>
#include <uORB/topics/vehicle_thrust_setpoint.h>
#include <uORB/SubscriptionInterval.hpp>
#include <uORB/topics/parameter_update.h>
using namespace time_literals;
/**
* BatteryBase is a base class for any type of battery.
@ -156,6 +160,7 @@ private:
uORB::Subscription _vehicle_thrust_setpoint_0_sub{ORB_ID(vehicle_thrust_setpoint)};
uORB::Subscription _vehicle_status_sub{ORB_ID(vehicle_status)};
uORB::PublicationMulti<battery_status_s> _battery_status_pub{ORB_ID(battery_status)};
uORB::SubscriptionInterval _parameter_update_sub{ORB_ID(parameter_update), 1_s};
bool _external_state_of_charge{false}; ///< inticates that the soc is injected and not updated by this library