Skip to content

Commit

Permalink
AP_Math: prevent FPE in SITL when limitting accel vectors
Browse files Browse the repository at this point in the history
the  cross-product code can produce something slightly negative.  Stop passing that into safe_sqrt; it isn't *that* safe on SITL!

Co-authored-by: Leonard Hall <leonardthall@gmail.com>
  • Loading branch information
peterbarker and lthall committed Jan 6, 2025
1 parent f523c88 commit 034639d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion libraries/AP_Math/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ bool limit_accel_xy(const Vector2f& vel, Vector2f& accel, float accel_max)
if (accel_cross.limit_length(accel_max)) {
accel_dir = 0.0;
} else {
float accel_max_dir = safe_sqrt(sq(accel_max) - accel_cross.length_squared());
float accel_max_dir = safe_sqrt(MAX(0, sq(accel_max) - accel_cross.length_squared()));
accel_dir = constrain_float(accel_dir, -accel_max_dir, accel_max_dir);
}
accel = accel_cross + vel_input_unit * accel_dir;
Expand Down

0 comments on commit 034639d

Please sign in to comment.