From b1742b4e19243653abf5a3424840b1374fce9fdb Mon Sep 17 00:00:00 2001 From: Peter Hall <33176108+IamPete1@users.noreply.github.com> Date: Tue, 11 Feb 2020 17:03:38 +0000 Subject: [PATCH] GCS_Mavlink: constrain battery current to avoid wrap --- libraries/GCS_MAVLink/GCS_Common.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/GCS_MAVLink/GCS_Common.cpp b/libraries/GCS_MAVLink/GCS_Common.cpp index 086bd08626..beae773d0a 100644 --- a/libraries/GCS_MAVLink/GCS_Common.cpp +++ b/libraries/GCS_MAVLink/GCS_Common.cpp @@ -217,7 +217,7 @@ void GCS_MAVLINK::send_battery_status(const uint8_t instance) const float current, consumed_mah, consumed_wh; if (battery.current_amps(current, instance)) { - current *= 100; + current = constrain_float(current * 100,-INT16_MAX,INT16_MAX); } else { current = -1; } @@ -2031,7 +2031,7 @@ void GCS_MAVLINK::send_battery2() if (battery.num_instances() > 1) { float current; if (battery.current_amps(current, 1)) { - current *= 100; // 10*mA + current = constrain_float(current * 100,-INT16_MAX,INT16_MAX); // 10*mA } else { current = -1; } @@ -4167,7 +4167,7 @@ void GCS_MAVLINK::send_sys_status() if (battery.healthy() && battery.current_amps(battery_current)) { battery_remaining = battery.capacity_remaining_pct(); - battery_current *= 100; + battery_current = constrain_float(battery_current * 100,-INT16_MAX,INT16_MAX); } else { battery_current = -1; battery_remaining = -1;