mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 01:03:34 +08:00
battery: check source param inside battery lib
This moves the handling of the BAT%d_SOURCE param inside of the battery library. Users of the library now pass the source instead of the flag whether to publish. The battery library then checks if the source is selected using the param and publishes accordingly. Since we removed the strange system_source flag, we now need to look at all batteries in commander. For current estimation - I think - it makes sense to sum them up.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2019-2020 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -121,8 +121,8 @@ Battery::reset()
|
||||
|
||||
void
|
||||
Battery::updateBatteryStatus(hrt_abstime timestamp, float voltage_v, float current_a,
|
||||
bool connected, bool selected_source, int priority,
|
||||
float throttle_normalized, bool should_publish)
|
||||
bool connected, int source, int priority,
|
||||
float throttle_normalized)
|
||||
{
|
||||
reset();
|
||||
_battery_status.timestamp = timestamp;
|
||||
@@ -148,7 +148,7 @@ Battery::updateBatteryStatus(hrt_abstime timestamp, float voltage_v, float curre
|
||||
_battery_status.warning = _warning;
|
||||
_battery_status.remaining = _remaining;
|
||||
_battery_status.connected = connected;
|
||||
_battery_status.system_source = selected_source;
|
||||
_battery_status.source = source;
|
||||
_battery_status.priority = priority;
|
||||
|
||||
static constexpr int uorb_max_cells = sizeof(_battery_status.voltage_cell_v) / sizeof(
|
||||
@@ -162,6 +162,8 @@ Battery::updateBatteryStatus(hrt_abstime timestamp, float voltage_v, float curre
|
||||
|
||||
_battery_status.timestamp = timestamp;
|
||||
|
||||
const bool should_publish = (source == _params.source);
|
||||
|
||||
if (should_publish) {
|
||||
publish();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user