make lean calc more robust

This commit is contained in:
Joe Ardent 2023-02-21 14:10:49 -08:00
parent 8cd901dadc
commit 851f2fb650

View file

@ -64,8 +64,10 @@ pub(super) fn cyber_lean(
let v2_r = v_squared / radius;
let tan_theta = (v2_r / gravity).clamp(-FRAC_PI_3, FRAC_PI_3);
if v2_r.is_normal() {
if tan_theta.is_finite() && !tan_theta.is_subnormal() {
lean.lean = tan_theta.atan().clamp(-FRAC_PI_4, FRAC_PI_4);
} else {
lean.lean = 0.0;
}
}