@@ -34,7 +34,7 @@ void OnResume::run(
34
34
" Resume: current action supports resuming from landed, continuing directly" );
35
35
on_completed ();
36
36
} else {
37
- resumeFromLanded (handler, on_completed, current_mission_index);
37
+ resumeFromUnexpectedLanding (handler, on_completed, current_mission_index);
38
38
}
39
39
} else {
40
40
// This happens when the mission is resumed in-air
@@ -43,7 +43,7 @@ void OnResume::run(
43
43
}
44
44
}
45
45
46
- void OnResume::resumeFromLanded (
46
+ void OnResume::resumeFromUnexpectedLanding (
47
47
const std::shared_ptr<ActionHandler> & handler,
48
48
const std::function<void ()> & on_completed, int current_mission_index)
49
49
{
@@ -69,13 +69,13 @@ void OnResume::resumeFromLanded(
69
69
}
70
70
}
71
71
72
- // Find takeoff action and run it
72
+ // Find takeoff action and run it (if there are multiple, take the one closest to the current index)
73
73
const ActionItem * takeoff_action_item{nullptr };
74
- for (const auto & item : mission.items ()) {
74
+ for (int i = 0 ; i < current_mission_index && mission.indexValid (i); ++i) {
75
+ const auto & item = mission.items ()[i];
75
76
if (const auto * action_item = std::get_if<ActionItem>(&item)) {
76
77
if (action_item->name == " takeoff" ) {
77
78
takeoff_action_item = action_item;
78
- break ;
79
79
}
80
80
}
81
81
}
0 commit comments