Skip to content

Commit ebc7e13

Browse files
tatsuytridge
authored andcommitted
AP_BattMonitor: dynamically update node ID on hot-swap when battery ID matches to resume telemetry
1 parent 43d1c94 commit ebc7e13

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

libraries/AP_BattMonitor/AP_BattMonitor_DroneCAN.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,16 @@ AP_BattMonitor_DroneCAN* AP_BattMonitor_DroneCAN::get_dronecan_backend(AP_DroneC
7474
continue;
7575
}
7676
AP_BattMonitor_DroneCAN* driver = (AP_BattMonitor_DroneCAN*)batt.drivers[i];
77-
if (driver->_ap_dronecan == ap_dronecan && driver->_node_id == node_id && match_battery_id(i, battery_id)) {
78-
return driver;
77+
if (driver->_ap_dronecan == ap_dronecan && match_battery_id(i, battery_id)) {
78+
if (driver->_node_id == node_id) {
79+
return driver;
80+
} else if (!driver->_interim_state.healthy && driver->option_is_set(AP_BattMonitor_Params::Options::AllowDynamicNodeUpdate)) {
81+
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Battery %u: Node change from %d to %d for Id %d",
82+
(unsigned)i+1, driver->_node_id, node_id, battery_id);
83+
driver->_node_id = node_id;
84+
driver->init();
85+
return driver;
86+
}
7987
}
8088
}
8189
// find empty uavcan driver

libraries/AP_BattMonitor/AP_BattMonitor_Params.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ const AP_Param::GroupInfo AP_BattMonitor_Params::var_info[] = {
156156
// @Param: OPTIONS
157157
// @DisplayName: Battery monitor options
158158
// @Description: This sets options to change the behaviour of the battery monitor
159-
// @Bitmask: 0:Ignore DroneCAN SoC, 1:MPPT reports input voltage and current, 2:MPPT Powered off when disarmed, 3:MPPT Powered on when armed, 4:MPPT Powered off at boot, 5:MPPT Powered on at boot, 6:Send resistance compensated voltage to GCS, 7:Allow DroneCAN InfoAux to be from a different CAN node, 8:Battery is for internal autopilot use only, 9:Sum monitor measures minimum voltage instead of average
159+
// @Bitmask: 0:Ignore DroneCAN SoC, 1:MPPT reports input voltage and current, 2:MPPT Powered off when disarmed, 3:MPPT Powered on when armed, 4:MPPT Powered off at boot, 5:MPPT Powered on at boot, 6:Send resistance compensated voltage to GCS, 7:Allow DroneCAN InfoAux to be from a different CAN node, 8:Battery is for internal autopilot use only, 9:Sum monitor measures minimum voltage instead of average, 10:Allow DroneCAN dynamic node update on hot-swap
160160
// @User: Advanced
161161
AP_GROUPINFO("OPTIONS", 21, AP_BattMonitor_Params, _options, 0),
162162
#endif // AP_BATTERY_OPTIONS_PARAM_ENABLED

libraries/AP_BattMonitor/AP_BattMonitor_Params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class AP_BattMonitor_Params {
6161
AllowSplitAuxInfo = (1U<<7), // allow different node to provide aux info for DroneCAN
6262
InternalUseOnly = (1U<<8), // for use internally to ArduPilot, not to be (eg.) sent via MAVLink BATTERY_STATUS
6363
Minimum_Voltage = (1U<<9), // sum monitor measures minimum voltage rather than average
64+
AllowDynamicNodeUpdate = (1U<<10), // allow dynamic update of DroneCAN node ID during hot-swap when telemetry is lost
6465
};
6566

6667
BattMonitor_LowVoltage_Source failsafe_voltage_source(void) const { return (enum BattMonitor_LowVoltage_Source)_failsafe_voltage_source.get(); }

0 commit comments

Comments
 (0)