Plane: Protect against a divide by 0 when calculating the forward throttle compensation

This commit is contained in:
Michael du Breuil 2020-05-31 18:25:08 -07:00 committed by Andrew Tridgell
parent ffaa60b9ed
commit 911570e9f3
1 changed files with 5 additions and 0 deletions

View File

@ -361,6 +361,11 @@ void Plane::throttle_voltage_comp()
// constrain read voltage to min and max params
batt_voltage_resting_estimate = constrain_float(batt_voltage_resting_estimate,g2.fwd_thr_batt_voltage_min,g2.fwd_thr_batt_voltage_max);
// don't apply compensation if the voltage is excessively low
if (batt_voltage_resting_estimate < 1) {
return;
}
// Scale the throttle up to compensate for voltage drop
// Ratio = 1 when voltage = voltage max, ratio increases as voltage drops
const float ratio = g2.fwd_thr_batt_voltage_max / batt_voltage_resting_estimate;