SMACC2
Loading...
Searching...
No Matches
cp_kml_mission_loader.hpp
Go to the documentation of this file.
1// Copyright 2026 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*****************************************************************************************************************
16 *
17 * Authors: Brett Aldrich
18 *
19 ******************************************************************************************************************/
20
21#pragma once
22
23#include <mutex>
24#include <smacc2/smacc.hpp>
25#include <string>
26#include <vector>
27
29
30namespace cl_px4_mr
31{
32
34{
35 bool ok = false;
36 std::string error;
37 size_t pointCount = 0;
38};
39
40// Holds the mission backbone: an ordered list of WGS84 waypoints read from a
41// KML file. Scope (this build): the FIRST LineString found in the document, by
42// geometry type - Placemark names, Folders and counts are ignored. Polygons,
43// altitude semantics and the general KML parse contract are deferred.
44//
45// The loader is reference-agnostic: it stores lat/lon/alt only. Projection to
46// the local NED frame belongs to the consumer (CpVehicleLocalPosition::projectToNed).
48{
49public:
51 virtual ~CpKmlMissionLoader();
52
53 void onInitialize() override;
54
55 // Parse the file; on success the parsed points replace the stored mission.
56 // On failure the stored mission is left untouched.
57 KmlLoadResult loadFile(const std::string & absolutePath);
58
59 // Replace the stored mission directly (used for compiled-in fallbacks).
60 void setMission(std::vector<GeoPoint> points, const std::string & source);
61
62 bool hasMission() const;
63 std::vector<GeoPoint> getMission() const; // copy under mutex
64 std::string getSource() const; // file path, or "fallback:<label>"
65 void clear();
66
67 // Pure parser (testable without ROS). Returns the first LineString's
68 // coordinates; on error returns empty and fills `error`.
69 static std::vector<GeoPoint> parseKmlString(const std::string & xml, std::string & error);
70
71private:
72 mutable std::mutex mutex_;
73 std::vector<GeoPoint> mission_;
74 std::string source_;
75};
76
77} // namespace cl_px4_mr
std::vector< GeoPoint > getMission() const
void setMission(std::vector< GeoPoint > points, const std::string &source)
KmlLoadResult loadFile(const std::string &absolutePath)
static std::vector< GeoPoint > parseKmlString(const std::string &xml, std::string &error)