From bea52104b7380ebfda4d7ea70bd7626321d783eb Mon Sep 17 00:00:00 2001 From: Jonas Perolini <74473718+JonasPerolini@users.noreply.github.com> Date: Thu, 26 Feb 2026 09:18:09 +0100 Subject: [PATCH] AirspeedValidator: fix course over ground computation for NED frame (#26304) * AirspeedValidator, fix course over ground computation for NED frame * fix potential out of bounds call --------- Co-authored-by: jonas --- src/modules/airspeed_selector/AirspeedValidator.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/airspeed_selector/AirspeedValidator.cpp b/src/modules/airspeed_selector/AirspeedValidator.cpp index bbd907ff52..22777f42f8 100644 --- a/src/modules/airspeed_selector/AirspeedValidator.cpp +++ b/src/modules/airspeed_selector/AirspeedValidator.cpp @@ -122,8 +122,9 @@ AirspeedValidator::update_CAS_scale_validated(bool gnss_valid, const matrix::Vec reset_CAS_scale_check(); } - const float course_over_ground_rad = matrix::wrap_2pi(atan2f(vI(0), vI(1))); - const int segment_index = int(SCALE_CHECK_SAMPLES * course_over_ground_rad / (2.f * M_PI_F)); + const float course_over_ground_rad = matrix::wrap_2pi(atan2f(vI(1), vI(0))); + const int segment_index = static_cast(SCALE_CHECK_SAMPLES * course_over_ground_rad / (2.f * M_PI_F)) + % SCALE_CHECK_SAMPLES; _scale_check_groundspeed(segment_index) = vI.norm(); _scale_check_TAS(segment_index) = airspeed_true_raw;