Skip to content

Commit

Permalink
mission_raw: fix sequence for ArduPilot
Browse files Browse the repository at this point in the history
We need to enter the home item before adding the sequence numbering.

Signed-off-by: Julian Oes <[email protected]>
  • Loading branch information
julianoes committed Feb 19, 2024
1 parent 30d2693 commit dc919d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/mavsdk/plugins/mission_raw/mission_import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ MissionImport::import_mission(const Json::Value& root, Autopilot autopilot)
mission_items[0].current = 1;
}

// Don't forget sequence number
unsigned sequence = 0;
for (auto& mission_item : mission_items) {
mission_item.seq = sequence++;
}

// Add home position at 0 for ArduPilot
if (autopilot == Autopilot::ArduPilot) {
const auto home = mission["plannedHomePosition"];
Expand Down Expand Up @@ -146,6 +140,12 @@ MissionImport::import_mission(const Json::Value& root, Autopilot autopilot)
}
}

// Don't forget sequence number
unsigned sequence = 0;
for (auto& mission_item : mission_items) {
mission_item.seq = sequence++;
}

// Returning an empty vector is ok here if there were really no mission items.
return {mission_items};
}
Expand Down
9 changes: 6 additions & 3 deletions src/mavsdk/plugins/mission_raw/mission_import_test.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <algorithm>
#include <atomic>
#include <cmath>
#include <fstream> // for `std::ifstream`
Expand Down Expand Up @@ -406,6 +407,11 @@ TEST(MissionRaw, ImportSamplePlanWithArduPilot)
{
auto reference_items = create_reference_items();

// We need to adjust the sequence plus one because we're about to add in home
// at 0.

std::for_each(reference_items.begin(), reference_items.end(), [](auto& item) { ++item.seq; });

auto home_item = MissionRaw::MissionItem{
0,
MAV_FRAME_GLOBAL_INT,
Expand All @@ -423,9 +429,6 @@ TEST(MissionRaw, ImportSamplePlanWithArduPilot)

reference_items.insert(reference_items.begin(), home_item);

// There is no need to increment the sequence for all items, the sequence
// still starts at 0 after home.

std::ifstream file{path_prefix("qgroundcontrol_sample.plan")};
ASSERT_TRUE(file);

Expand Down

0 comments on commit dc919d0

Please sign in to comment.