From e46e4dc80eb10154413c10413b0c215e6aa75971 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Tue, 24 Jun 2025 13:47:09 +1200 Subject: [PATCH] commander: prevent race condition after mission When a mission finishes with an RTL command, there's a race condition between: 1. RTL command setting user_mode_intention RTL 2. Mission completion logic forcing LOITER The auto-loiter transition was checking current nav_state (which is still AUTO_MISSION) instead of any pending user_mode_intention, causing it to override the RTL request. Fix: Only auto-transition to loiter if no mode change is already pending. --- src/modules/commander/Commander.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/commander/Commander.cpp b/src/modules/commander/Commander.cpp index 5e6a9082d4..643d45617f 100644 --- a/src/modules/commander/Commander.cpp +++ b/src/modules/commander/Commander.cpp @@ -2016,7 +2016,11 @@ void Commander::checkForMissionUpdate() } else if (_vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION) { // Transition to loiter when the mission is cleared and/or finished, and we are still in mission mode. - _user_mode_intention.change(vehicle_status_s::NAVIGATION_STATE_AUTO_LOITER); + + // However, only do so if there's no pending mode change, so there isn't already a pending change (like RTL). + if (_user_mode_intention.get() == vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION) { + _user_mode_intention.change(vehicle_status_s::NAVIGATION_STATE_AUTO_LOITER); + } } } }