From 317a681caeac342190516a51df5bdbeadff4bd0d Mon Sep 17 00:00:00 2001 From: Balduin Date: Wed, 14 Oct 2026 13:20:58 +0200 Subject: [PATCH] fix(airspeed_selector): do not invalidate a sensor on the cycle it is detected (#29214) * fix(airspeed_selector): do not invalidate a sensor on the cycle it is detected A sensor that starts publishing after the selector's init (e.g. the SITL airspeed sim, which waits for a global position) was flagged stale on the first cycle after detection: its last-update timestamp was still zero, so the 1 s missing-data timeout fired before a single sample was read. With ASPD_FS_T_START at its default of -1 the validator never recovers, the selected source stays DISABLED and preflight reports "Airspeed invalid". Seed the timestamp when a new sensor index is detected so the timeout counts from detection. Also silence the DISABLED-to-sensor transition message, which otherwise reports a spurious "healthy, start using again". Assisted-by: Claude:claude-fable-5-1 Signed-off-by: Balduin * fix(airspeed_selector): only silence reporting when new sensor added * fix(airspeed_selector): remove newly dead line - this time is always set check_for_connected_airspeed_sensors - there it depends on: - primary index set - otherwise nothing really happens - i >= _number_of_airspeed_sensors: always true on init * test(mavsdk_tests): give the VTOL return with approaches 180 s to disarm The flight from the end of the approach check to disarm takes about 155 s of autopilot time, over the 150 s budget. The test only passed because poll_condition_with_timeout checks elapsed time once per 15 s of autopilot time and usually landed a check before the budget ran out; when the lockstep sim ran slightly faster than the speed factor the disarm fell inside a poll sleep and the test timed out at 158 s. Assisted-by: Claude:claude-fable-5-1 Signed-off-by: Balduin --------- Signed-off-by: Balduin --- src/modules/airspeed_selector/airspeed_selector_main.cpp | 8 +++++++- test/mavsdk_tests/test_vtol_rtl.cpp | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/modules/airspeed_selector/airspeed_selector_main.cpp b/src/modules/airspeed_selector/airspeed_selector_main.cpp index 1292e2204fb..16848e3adb2 100644 --- a/src/modules/airspeed_selector/airspeed_selector_main.cpp +++ b/src/modules/airspeed_selector/airspeed_selector_main.cpp @@ -316,7 +316,6 @@ AirspeedModule::init() if (_airspeed_subs[i].copy(&airspeed)) { _airspeed_device_id[i] = airspeed.device_id; - _time_last_airspeed_update[i] = _time_now_usec; } } @@ -364,6 +363,10 @@ AirspeedModule::check_for_connected_airspeed_sensors() break; } + if (i >= _number_of_airspeed_sensors) { + _time_last_airspeed_update[i] = _time_now_usec; // newly detected: start stale-data timeout now + } + detected_airspeed_sensors = i + 1; } @@ -850,6 +853,9 @@ void AirspeedModule::select_airspeed_and_publish() events::send(events::ID("airspeed_selector_estimation_valid"), events::Log::Info, "Airspeed estimation valid"); + } else if (_prev_airspeed_src == AirspeedSource::DISABLED && airspeed_sensor_added) { + // sensor detected after boot, nothing to report + } else { mavlink_log_critical(&_mavlink_log_pub, "Airspeed sensor healthy, start using again (%i, %i)\t", prev_airspeed_index, valid_airspeed_index); diff --git a/test/mavsdk_tests/test_vtol_rtl.cpp b/test/mavsdk_tests/test_vtol_rtl.cpp index 0c84c524f85..e02080c10bd 100644 --- a/test/mavsdk_tests/test_vtol_rtl.cpp +++ b/test/mavsdk_tests/test_vtol_rtl.cpp @@ -202,7 +202,7 @@ TEST_CASE("Return direct home with approaches", "[vtol]") tester.arm(); tester.execute_rtl_when_reaching_mission_sequence(4); tester.check_rtl_approaches(5., std::chrono::seconds(60)); - tester.wait_until_disarmed(std::chrono::seconds(150)); + tester.wait_until_disarmed(std::chrono::seconds(180)); tester.check_home_within(5.0f); }