Skip to content

Commit bbf2927

Browse files
committed
mission: find last takeoff when resuming instead of first one
1 parent 4860e7e commit bbf2927

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

px4_ros2_cpp/include/px4_ros2/mission/actions/default_actions.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class OnResume : public ActionInterface
136136
const std::function<void()> & on_completed) override;
137137

138138
private:
139-
void resumeFromLanded(
139+
void resumeFromUnexpectedLanding(
140140
const std::shared_ptr<ActionHandler> & handler,
141141
const std::function<void()> & on_completed, int current_mission_index);
142142
void navigateToPreviousWaypoint(

px4_ros2_cpp/src/mission/actions/default_actions.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void OnResume::run(
3434
"Resume: current action supports resuming from landed, continuing directly");
3535
on_completed();
3636
} else {
37-
resumeFromLanded(handler, on_completed, current_mission_index);
37+
resumeFromUnexpectedLanding(handler, on_completed, current_mission_index);
3838
}
3939
} else {
4040
// This happens when the mission is resumed in-air
@@ -43,7 +43,7 @@ void OnResume::run(
4343
}
4444
}
4545

46-
void OnResume::resumeFromLanded(
46+
void OnResume::resumeFromUnexpectedLanding(
4747
const std::shared_ptr<ActionHandler> & handler,
4848
const std::function<void()> & on_completed, int current_mission_index)
4949
{
@@ -69,13 +69,13 @@ void OnResume::resumeFromLanded(
6969
}
7070
}
7171

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)
7373
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];
7576
if (const auto * action_item = std::get_if<ActionItem>(&item)) {
7677
if (action_item->name == "takeoff") {
7778
takeoff_action_item = action_item;
78-
break;
7979
}
8080
}
8181
}

0 commit comments

Comments
 (0)