15#include "auto_apms_mission/mission_configuration.hpp"
19#include "ament_index_cpp/get_resource.hpp"
20#include "auto_apms_util/exceptions.hpp"
21#include "auto_apms_util/resource.hpp"
22#include "auto_apms_util/string.hpp"
26const std::string MissionConfiguration::YAML_KEY_BRINGUP =
"BRINGUP";
27const std::string MissionConfiguration::YAML_KEY_MISSION =
"MISSION";
28const std::string MissionConfiguration::YAML_KEY_CONTINGENCY =
"CONTINGENCY";
29const std::string MissionConfiguration::YAML_KEY_EMERGENCY =
"EMERGENCY";
30const std::string MissionConfiguration::YAML_KEY_SHUTDOWN =
"SHUTDOWN";
35 std::string package_name =
"";
36 std::string file_name;
37 switch (tokens.size()) {
39 file_name = tokens[0];
42 package_name = tokens[0];
43 file_name = tokens[1];
46 throw auto_apms_util::exceptions::ResourceIdentityFormatError(
47 "Mission configuration resource identity string '" + identity +
48 "' has wrong format. Must be '<package_name>::<file_name>'.");
51 std::set<std::string> search_packages;
52 if (!package_name.empty()) {
53 search_packages.insert(package_name);
59 std::vector<std::string> matching_file_paths;
60 for (
const auto & p : search_packages) {
62 std::string base_path;
63 if (ament_index_cpp::get_resource(_AUTO_APMS_MISSION__RESOURCE_TYPE_NAME__MISSION_CONFIG, p, content, &base_path)) {
65 for (
const std::string & line : lines) {
66 if (std::filesystem::path(line).stem() == std::filesystem::path(file_name).stem()) {
67 matching_file_paths.push_back(base_path +
"/" + line);
73 if (matching_file_paths.empty()) {
74 throw auto_apms_util::exceptions::ResourceError(
75 "No mission configuration resource was found using identity '" + identity +
"'.");
77 if (matching_file_paths.size() > 1) {
78 throw auto_apms_util::exceptions::ResourceError(
79 "There are multiple mission configuration resources with file name '" + file_name +
"'.");
81 return fromFile(matching_file_paths[0]);
std::vector< std::string > splitString(const std::string &str, const std::string &delimiter, bool remove_empty=true)
Split a string into multiple tokens using a specific delimiter string (Delimiter may consist of multi...
std::set< std::string > getPackagesWithResourceType(const std::string &resource_type, const std::set< std::string > &exclude_packages={})
Get a list of all package names that register a certain type of ament_index resources.
Mission design utilities incorporating behavior trees to model the complexity of arbitrary operations...
Configuration parameters for standard mission supported by AutoAPMS.