mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-01 11:06:04 +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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -87,21 +87,18 @@ public:
|
||||
*/
|
||||
float full_cell_voltage() { return _params.v_charged; }
|
||||
|
||||
int source() { return _params.source; }
|
||||
|
||||
/**
|
||||
* Update current battery status message.
|
||||
*
|
||||
* @param voltage_raw: Battery voltage, in Volts
|
||||
* @param current_raw: Battery current, in Amps
|
||||
* @param timestamp: Time at which the ADC was read (use hrt_absolute_time())
|
||||
* @param selected_source: This battery is on the brick that the selected source for selected_source
|
||||
* @param source: Source type in relation to BAT%d_SOURCE param.
|
||||
* @param priority: The brick number -1. The term priority refers to the Vn connection on the LTC4417
|
||||
* @param throttle_normalized: Throttle of the vehicle, between 0 and 1
|
||||
* @param should_publish If True, this function published a battery_status uORB message.
|
||||
*/
|
||||
void updateBatteryStatus(hrt_abstime timestamp, float voltage_v, float current_a, bool connected,
|
||||
bool selected_source, int priority, float throttle_normalized, bool should_publish);
|
||||
int source, int priority, float throttle_normalized);
|
||||
|
||||
/**
|
||||
* Publishes the uORB battery_status message with the most recently-updated data.
|
||||
|
||||
Reference in New Issue
Block a user