Skip to content
Snippets Groups Projects
Commit 7c019b7d authored by ChristophTobler's avatar ChristophTobler Committed by Lorenz Meier
Browse files

publish battery_status directly

This is temporary until there is a solution that works for adc and posix power modules
parent 856a523d
No related branches found
No related tags found
No related merge requests found
......@@ -42,9 +42,15 @@
#include <string>
#include <px4_config.h>
#include <systemlib/err.h>
#include <systemlib/battery.h>
#include <drivers/drv_hrt.h>
#include <ltc2946/LTC2946.hpp>
#include <uORB/uORB.h>
#include <uORB/topics/battery_status.h>
#include <uORB/topics/actuator_controls.h>
#include <uORB/topics/vehicle_control_mode.h>
extern "C" { __EXPORT int df_ltc2946_wrapper_main(int argc, char *argv[]); }
......@@ -64,15 +70,29 @@ public:
private:
int _publish(const struct ltc2946_sensor_data &data);
orb_advert_t _battery_pub{nullptr};
battery_status_s _battery_status{};
Battery _battery{};
int _actuator_ctrl_0_sub{-1};
int _vcontrol_mode_sub{-1};
};
DfLtc2946Wrapper::DfLtc2946Wrapper() :
LTC2946(LTC2946_DEVICE_PATH)
{
_battery.reset(&_battery_status);
// subscriptions
_actuator_ctrl_0_sub = orb_subscribe(ORB_ID(actuator_controls_0));
_vcontrol_mode_sub = orb_subscribe(ORB_ID(vehicle_control_mode));
}
DfLtc2946Wrapper::~DfLtc2946Wrapper()
{
orb_unsubscribe(_actuator_ctrl_0_sub);
orb_unsubscribe(_vcontrol_mode_sub);
}
int DfLtc2946Wrapper::start()
......@@ -113,7 +133,22 @@ int DfLtc2946Wrapper::stop()
int DfLtc2946Wrapper::_publish(const struct ltc2946_sensor_data &data)
{
// TODO
hrt_abstime t = hrt_absolute_time();
bool connected = data.battery_voltage_V > BOARD_ADC_OPEN_CIRCUIT_V;
actuator_controls_s ctrl;
orb_copy(ORB_ID(actuator_controls_0), _actuator_ctrl_0_sub, &ctrl);
vehicle_control_mode_s vcontrol_mode;
orb_copy(ORB_ID(vehicle_control_mode), _vcontrol_mode_sub, &vcontrol_mode);
_battery.updateBatteryStatus(t, data.battery_voltage_V, data.battery_current_A,
connected, true, 1,
ctrl.control[actuator_controls_s::INDEX_THROTTLE],
vcontrol_mode.flag_armed, &_battery_status);
int instance;
orb_publish_auto(ORB_ID(battery_status), &_battery_pub, &_battery_status, &instance, ORB_PRIO_DEFAULT);
return 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment