Skip to content

Commit

Permalink
AP_TECS: Add /0 protection
Browse files Browse the repository at this point in the history
  • Loading branch information
priseborough authored and magicrub committed Apr 1, 2024
1 parent 79b091e commit 3a2c3d2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions libraries/AP_TECS/AP_TECS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,10 @@ void AP_TECS::_update_height_demand(void)
_hgt_dem_rate_ltd = _hgt_dem_rate_ltd - _sink_rate_limit * _DT;
_sink_fraction = 1.0f;
} else {
if (is_negative(hgt_dem - _hgt_dem_rate_ltd)) {
_sink_fraction = (hgt_dem - _hgt_dem_rate_ltd) / (-_sink_rate_limit * _DT);
const float numerator = hgt_dem - _hgt_dem_rate_ltd;
const float denominator = - _sink_rate_limit * _DT;
if (is_negative(numerator) && is_negative(denominator)) {
_sink_fraction = numerator / denominator;
} else {
_sink_fraction = 0.0f;
}
Expand Down

0 comments on commit 3a2c3d2

Please sign in to comment.