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.
This commit is contained in:
Julian Oes
2025-06-24 13:47:09 +12:00
committed by Ramon Roche
parent bfbd9bfe27
commit e46e4dc80e
+5 -1
View File
@@ -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);
}
}
}
}