Skip to content

Commit 286cb3d

Browse files
authored
Merge pull request #2560 from mavlink/pr-fix-import
mission_raw: fix mission import for mission commands
2 parents 73f458c + 22b9d1b commit 286cb3d

File tree

4 files changed

+96
-13
lines changed

4 files changed

+96
-13
lines changed

src/mavsdk/plugins/mission_raw/mission_import.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ MissionImport::import_mission(const Json::Value& root, Autopilot autopilot)
133133
0.0f,
134134
0.0f,
135135
0.0f,
136-
static_cast<int32_t>(std::round(home[0].asDouble() * 1e7)),
137-
static_cast<int32_t>(std::round(home[1].asDouble() * 1e7)),
136+
set_int32(home[0], MAV_FRAME_GLOBAL_INT),
137+
set_int32(home[1], MAV_FRAME_GLOBAL_INT),
138138
home[2].asFloat(),
139139
MAV_MISSION_TYPE_MISSION});
140140
}
@@ -225,8 +225,8 @@ MissionImport::import_rally_points(const Json::Value& root)
225225
item.command = MAV_CMD_NAV_RALLY_POINT;
226226
item.frame = MAV_FRAME_GLOBAL_RELATIVE_ALT;
227227
item.mission_type = MAV_MISSION_TYPE_RALLY;
228-
item.x = set_int32(point[0]);
229-
item.y = set_int32(point[1]);
228+
item.x = set_int32(point[0], item.frame);
229+
item.y = set_int32(point[1], item.frame);
230230
item.z = set_float(point[2]);
231231

232232
rally_items.push_back(item);
@@ -281,10 +281,10 @@ MissionImport::import_simple_mission_item(const Json::Value& json_item)
281281
item.param4 = set_float(json_item["params"][i]);
282282
break;
283283
case 4:
284-
item.x = set_int32(json_item["params"][i]);
284+
item.x = set_int32(json_item["params"][i], item.frame);
285285
break;
286286
case 5:
287-
item.y = set_int32(json_item["params"][i]);
287+
item.y = set_int32(json_item["params"][i], item.frame);
288288
break;
289289
case 6:
290290
item.z = set_float(json_item["params"][i]);
@@ -363,8 +363,8 @@ MissionImport::import_polygon_geofences(const Json::Value& polygons)
363363
MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION;
364364
item.frame = MAV_FRAME_GLOBAL;
365365
item.param1 = set_float(points.size());
366-
item.x = set_int32(point[0]);
367-
item.y = set_int32(point[1]);
366+
item.x = set_int32(point[0], item.frame);
367+
item.y = set_int32(point[1], item.frame);
368368
item.mission_type = MAV_MISSION_TYPE_FENCE;
369369

370370
polygon_geofences.push_back(item);
@@ -390,8 +390,8 @@ MissionImport::import_circular_geofences(const Json::Value& circles)
390390
inclusion ? MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION : MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION;
391391
item.frame = MAV_FRAME_GLOBAL;
392392
item.param1 = set_float(radius);
393-
item.x = set_int32(center[0]);
394-
item.y = set_int32(center[1]);
393+
item.x = set_int32(center[0], item.frame);
394+
item.y = set_int32(center[1], item.frame);
395395
item.mission_type = MAV_MISSION_TYPE_FENCE;
396396

397397
circular_geofences.push_back(item);
@@ -405,9 +405,14 @@ float MissionImport::set_float(const Json::Value& val)
405405
return val.isNull() ? NAN : val.asFloat();
406406
}
407407

408-
int32_t MissionImport::set_int32(const Json::Value& val)
408+
int32_t MissionImport::set_int32(const Json::Value& val, uint32_t frame)
409409
{
410-
return static_cast<int32_t>(val.isNull() ? 0 : (std::round(val.asDouble() * 1e7)));
410+
// Don't apply 10^7 conversion for MAV_FRAME_MISSION
411+
if (frame == MAV_FRAME_MISSION) {
412+
return static_cast<int32_t>(val.isNull() ? 0 : val.asFloat());
413+
} else {
414+
return static_cast<int32_t>(val.isNull() ? 0 : (std::round(val.asDouble() * 1e7)));
415+
}
411416
}
412417

413418
} // namespace mavsdk

src/mavsdk/plugins/mission_raw/mission_import.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MissionImport {
3232
static std::vector<MissionRaw::MissionItem>
3333
import_circular_geofences(const Json::Value& json_item);
3434
static float set_float(const Json::Value& val);
35-
static int32_t set_int32(const Json::Value& val);
35+
static int32_t set_int32(const Json::Value& val, uint32_t frame);
3636
};
3737

3838
} // namespace mavsdk

src/mavsdk/plugins/mission_raw/mission_import_test.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,3 +441,33 @@ TEST(MissionRaw, ImportSamplePlanWithArduPilot)
441441

442442
EXPECT_EQ(reference_items, result_pair.second.mission_items);
443443
}
444+
445+
TEST(MissionRaw, ImportSamplePlanWithDigicamControl)
446+
{
447+
auto digicam_control_items = std::vector<MissionRaw::MissionItem>{
448+
{0,
449+
MAV_FRAME_MISSION,
450+
MAV_CMD_DO_DIGICAM_CONTROL,
451+
1, // current
452+
1, // autocontinue
453+
1,
454+
0,
455+
0,
456+
0,
457+
1,
458+
0,
459+
0,
460+
MAV_MISSION_TYPE_MISSION}};
461+
462+
std::ifstream file{path_prefix("qgroundcontrol_sample_with_digicam_control.plan")};
463+
ASSERT_TRUE(file);
464+
465+
std::stringstream buf;
466+
buf << file.rdbuf();
467+
file.close();
468+
469+
const auto result_pair = MissionImport::parse_json(buf.str(), Autopilot::Px4);
470+
ASSERT_EQ(result_pair.first, MissionRaw::Result::Success);
471+
472+
EXPECT_EQ(digicam_control_items, result_pair.second.mission_items);
473+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"fileType": "Plan",
3+
"geoFence": {
4+
"circles": [],
5+
"polygons": [],
6+
"version": 2
7+
},
8+
"groundStation": "LiniaGenerator",
9+
"mission": {
10+
"cruiseSpeed": 10.0,
11+
"firmwareType": 3,
12+
"globalPlanAltitudeMode": 1,
13+
"hoverSpeed": 10.0,
14+
"items": [
15+
{
16+
"autoContinue": true,
17+
"command": 203,
18+
"doJumpId": 7,
19+
"frame": 2,
20+
"params": [
21+
1,
22+
0,
23+
0,
24+
0,
25+
1,
26+
0,
27+
0
28+
],
29+
"type": "SimpleItem",
30+
"amslaltAboveTerrain": null,
31+
"altitudeMode": null,
32+
"altitude": null
33+
}
34+
],
35+
"vehicleType": 2,
36+
"plannedHomePosition": [
37+
0.0,
38+
0.0,
39+
0.0
40+
],
41+
"version": 2
42+
},
43+
"rallyPoints": {
44+
"points": [],
45+
"version": 2
46+
},
47+
"version": 1
48+
}

0 commit comments

Comments
 (0)