20#include "auto_apms_behavior_tree_core/tree/tree_resource.hpp"
21#include "auto_apms_util/exceptions.hpp"
22#include "auto_apms_util/yaml.hpp"
33struct convert<auto_apms_mission::MissionConfiguration>
35 using Config = auto_apms_mission::MissionConfiguration;
36 static Node encode(
const Config & rhs);
37 static bool decode(
const Node & node, Config & rhs);
49struct MissionConfiguration
53 static const std::string YAML_KEY_BRINGUP;
54 static const std::string YAML_KEY_MISSION;
55 static const std::string YAML_KEY_CONTINGENCY;
56 static const std::string YAML_KEY_EMERGENCY;
57 static const std::string YAML_KEY_SHUTDOWN;
59 MissionConfiguration() =
default;
63 static MissionConfiguration fromResourceIdentity(
const std::string identity);
65 std::vector<TreeResourceIdentity> bringup;
66 std::vector<TreeResourceIdentity> mission;
67 std::vector<std::pair<TreeResourceIdentity, TreeResourceIdentity>> contingency;
68 std::vector<std::pair<TreeResourceIdentity, TreeResourceIdentity>> emergency;
69 std::vector<TreeResourceIdentity> shutdown;
81inline Node convert<auto_apms_mission::MissionConfiguration>::encode(
const Config & rhs)
83 Node node(NodeType::Map);
84 node[Config::YAML_KEY_BRINGUP] = rhs.bringup;
85 node[Config::YAML_KEY_MISSION] = rhs.mission;
86 Node contingency_node = node[Config::YAML_KEY_CONTINGENCY];
87 for (
const auto & [key, val] : rhs.contingency) {
88 contingency_node[key.str()] = val;
90 Node emergency_node = node[Config::YAML_KEY_EMERGENCY];
91 for (
const auto & [key, val] : rhs.emergency) {
92 emergency_node[key.str()] = val;
94 node[Config::YAML_KEY_SHUTDOWN] = rhs.shutdown;
97inline bool convert<auto_apms_mission::MissionConfiguration>::decode(
const Node & node, Config & rhs)
100 throw auto_apms_util::exceptions::YAMLFormatError(
101 "YAML::Node for auto_apms_mission::MissionConfiguration must be map but is type " + std::to_string(node.Type()) +
102 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
104 for (
auto it = node.begin(); it != node.end(); ++it) {
105 const std::string key = it->first.as<std::string>();
106 const Node val = it->second;
108 if (key == Config::YAML_KEY_BRINGUP) {
109 if (val.IsNull())
continue;
110 if (!val.IsSequence()) {
111 throw auto_apms_util::exceptions::YAMLFormatError(
112 "Value for key '" + key +
"' must be a sequence but is type " + std::to_string(val.Type()) +
113 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
115 rhs.bringup = val.as<std::vector<Config::TreeResourceIdentity>>();
119 if (key == Config::YAML_KEY_MISSION) {
120 if (!val.IsSequence()) {
121 throw auto_apms_util::exceptions::YAMLFormatError(
122 "Value for key '" + key +
"' must be a sequence but is type " + std::to_string(val.Type()) +
123 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
125 rhs.mission = val.as<std::vector<Config::TreeResourceIdentity>>();
129 if (key == Config::YAML_KEY_CONTINGENCY) {
130 if (val.IsNull())
continue;
132 throw auto_apms_util::exceptions::YAMLFormatError(
133 "Value for key '" + key +
"' must be a map but is type " + std::to_string(val.Type()) +
134 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
136 for (YAML::const_iterator it2 = val.begin(); it2 != val.end(); ++it2) {
137 const std::string monitor_id = it2->first.as<std::string>();
138 if (!it2->second.IsScalar()) {
139 throw auto_apms_util::exceptions::YAMLFormatError(
140 "Value for key '" + monitor_id +
"' in the CONTINGENCY group must be scalar but is type " +
141 std::to_string(val.Type()) +
" (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
143 rhs.contingency.push_back(
144 {Config::TreeResourceIdentity(monitor_id), it2->second.as<Config::TreeResourceIdentity>()});
149 if (key == Config::YAML_KEY_EMERGENCY) {
150 if (val.IsNull())
continue;
152 throw auto_apms_util::exceptions::YAMLFormatError(
153 "Value for key '" + key +
"' must be a map but is type " + std::to_string(val.Type()) +
154 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
156 for (YAML::const_iterator it2 = val.begin(); it2 != val.end(); ++it2) {
157 const std::string monitor_id = it2->first.as<std::string>();
158 if (!it2->second.IsScalar()) {
159 throw auto_apms_util::exceptions::YAMLFormatError(
160 "Value for key '" + monitor_id +
"' in the EMERGENCY group must be scalar but is type " +
161 std::to_string(val.Type()) +
" (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
163 rhs.emergency.push_back(
164 {Config::TreeResourceIdentity(monitor_id), it2->second.as<Config::TreeResourceIdentity>()});
169 if (key == Config::YAML_KEY_SHUTDOWN) {
170 if (val.IsNull())
continue;
171 if (!val.IsSequence()) {
172 throw auto_apms_util::exceptions::YAMLFormatError(
173 "Value for key '" + key +
"' must be a sequence but is type " + std::to_string(val.Type()) +
174 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
176 rhs.shutdown = val.as<std::vector<Config::TreeResourceIdentity>>();
181 throw auto_apms_util::exceptions::YAMLFormatError(
"Unkown parameter name '" + key +
"'.");
#define AUTO_APMS_UTIL_DEFINE_YAML_CONVERSION_METHODS(ClassType)
Macro for defining YAML encode/decode methods for a class.
Mission design utilities incorporating behavior trees to model the complexity of arbitrary operations...
Struct that encapsulates the identity string for a declared behavior tree.
Configuration parameters for standard mission supported by AutoAPMS.