From 56eb9bcc18a2df3d078a5cfd4be6fa8fa3b4dccd Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Wed, 7 May 2025 20:58:12 +1200 Subject: [PATCH] mavsdk_tests: workaround race condition PX4 needs a bit of time to process an uploaded mission before it is ready to accept the mission mode. Therefore, we need to wait a bit. Alternatively, we could wait on the mission progress arriving properly, but this sleep is simple enough for now. --- test/mavsdk_tests/autopilot_tester.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/mavsdk_tests/autopilot_tester.cpp b/test/mavsdk_tests/autopilot_tester.cpp index 64aaf05614..fc7efa3477 100644 --- a/test/mavsdk_tests/autopilot_tester.cpp +++ b/test/mavsdk_tests/autopilot_tester.cpp @@ -245,6 +245,8 @@ void AutopilotTester::prepare_square_mission(MissionOptions mission_options) _mission->set_return_to_launch_after_mission(mission_options.rtl_at_end); REQUIRE(_mission->upload_mission(mission_plan) == Mission::Result::Success); + // PX4 needs time to realize that it now has a mission available, so we need to wait a bit here. + sleep_for(std::chrono::seconds(1)); } void AutopilotTester::prepare_straight_mission(MissionOptions mission_options) @@ -261,6 +263,8 @@ void AutopilotTester::prepare_straight_mission(MissionOptions mission_options) _mission->set_return_to_launch_after_mission(mission_options.rtl_at_end); REQUIRE(_mission->upload_mission(mission_plan) == Mission::Result::Success); + // PX4 needs time to realize that it now has a mission available, so we need to wait a bit here. + sleep_for(std::chrono::seconds(1)); } void AutopilotTester::execute_mission() @@ -390,6 +394,8 @@ void AutopilotTester::load_qgc_mission_raw_and_move_here(const std::string &plan move_mission_raw_here(import_result.second.mission_items); REQUIRE(_mission_raw->upload_mission(import_result.second.mission_items) == MissionRaw::Result::Success); + // PX4 needs time to realize that it now has a mission available, so we need to wait a bit here. + sleep_for(std::chrono::seconds(1)); } void AutopilotTester::execute_mission_raw()