From 1bc973cfa878d9bd8e0306ad382670593ed04078 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 22 Jun 2022 21:41:48 +1000 Subject: [PATCH] Plane: fixed int8_t wrap with FWD_BAT_VOLT_MAX this could cause crazy throttle values when the ratio pushes us over 127 --- ArduPlane/servos.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ArduPlane/servos.cpp b/ArduPlane/servos.cpp index 2e52219587..7e9c49b7f8 100644 --- a/ArduPlane/servos.cpp +++ b/ArduPlane/servos.cpp @@ -424,8 +424,8 @@ void Plane::throttle_voltage_comp(int8_t &min_throttle, int8_t &max_throttle) co const float ratio = g2.fwd_thr_batt_voltage_max / batt_voltage_resting_estimate; // Scale the throttle limits to prevent subsequent clipping - min_throttle = MAX((int8_t)(ratio * (float)min_throttle), -100); - max_throttle = MIN((int8_t)(ratio * (float)max_throttle), 100); + min_throttle = int8_t(MAX((ratio * (float)min_throttle), -100)); + max_throttle = int8_t(MIN((ratio * (float)max_throttle), 100)); SRV_Channels::set_output_scaled(SRV_Channel::k_throttle, constrain_float(SRV_Channels::get_output_scaled(SRV_Channel::k_throttle) * ratio, -100, 100));