diff --git a/src/modules/mavlink/mavlink_messages.cpp b/src/modules/mavlink/mavlink_messages.cpp index a95517d1b368..4276ed17fff2 100644 --- a/src/modules/mavlink/mavlink_messages.cpp +++ b/src/modules/mavlink/mavlink_messages.cpp @@ -598,8 +598,13 @@ class MavlinkStreamSysStatus : public MavlinkStream int lowest_battery_index = 0; + //No battery is connected, select the first group + //Low battery judgment is performed only when the current battery is connected + //When the last cached battery is not connected or the current battery level is lower than the cached battery level, + //the current battery status is replaced with the cached value for (int i = 0; i < ORB_MULTI_MAX_INSTANCES; i++) { - if (battery_status[i].connected && (battery_status[i].remaining < battery_status[lowest_battery_index].remaining)) { + if (battery_status[i].connected && ((!battery_status[lowest_battery_index].connected) + || (battery_status[i].remaining < battery_status[lowest_battery_index].remaining))) { lowest_battery_index = i; } }