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;
75 std::vector<TreeResourceIdentity> bringup;
76 std::vector<TreeResourceIdentity> mission;
77 std::vector<std::pair<TreeResourceIdentity, TreeResourceIdentity>> contingency;
78 std::vector<std::pair<TreeResourceIdentity, TreeResourceIdentity>> emergency;
79 std::vector<TreeResourceIdentity> shutdown;
91inline Node convert<auto_apms_mission::MissionConfiguration>::encode(
const Config & rhs)
93 Node node(NodeType::Map);
94 node[Config::YAML_KEY_BRINGUP] = rhs.bringup;
95 node[Config::YAML_KEY_MISSION] = rhs.mission;
96 Node contingency_node = node[Config::YAML_KEY_CONTINGENCY];
97 for (
const auto & [key, val] : rhs.contingency) {
98 contingency_node[key.str()] = val;
100 Node emergency_node = node[Config::YAML_KEY_EMERGENCY];
101 for (
const auto & [key, val] : rhs.emergency) {
102 emergency_node[key.str()] = val;
104 node[Config::YAML_KEY_SHUTDOWN] = rhs.shutdown;
107inline bool convert<auto_apms_mission::MissionConfiguration>::decode(
const Node & node, Config & rhs)
110 throw auto_apms_util::exceptions::YAMLFormatError(
111 "YAML::Node for auto_apms_mission::MissionConfiguration must be map but is type " + std::to_string(node.Type()) +
112 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
114 for (
auto it = node.begin(); it != node.end(); ++it) {
115 const std::string key = it->first.as<std::string>();
116 const Node val = it->second;
118 if (key == Config::YAML_KEY_BRINGUP) {
119 if (val.IsNull())
continue;
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.bringup = val.as<std::vector<Config::TreeResourceIdentity>>();
129 if (key == Config::YAML_KEY_MISSION) {
130 if (!val.IsSequence()) {
131 throw auto_apms_util::exceptions::YAMLFormatError(
132 "Value for key '" + key +
"' must be a sequence but is type " + std::to_string(val.Type()) +
133 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
135 rhs.mission = val.as<std::vector<Config::TreeResourceIdentity>>();
139 if (key == Config::YAML_KEY_CONTINGENCY) {
140 if (val.IsNull())
continue;
142 throw auto_apms_util::exceptions::YAMLFormatError(
143 "Value for key '" + key +
"' must be a map but is type " + std::to_string(val.Type()) +
144 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
146 for (YAML::const_iterator it2 = val.begin(); it2 != val.end(); ++it2) {
147 const std::string monitor_id = it2->first.as<std::string>();
148 if (!it2->second.IsScalar()) {
149 throw auto_apms_util::exceptions::YAMLFormatError(
150 "Value for key '" + monitor_id +
"' in the CONTINGENCY group must be scalar but is type " +
151 std::to_string(val.Type()) +
" (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
153 rhs.contingency.push_back(
154 {Config::TreeResourceIdentity(monitor_id), it2->second.as<Config::TreeResourceIdentity>()});
159 if (key == Config::YAML_KEY_EMERGENCY) {
160 if (val.IsNull())
continue;
162 throw auto_apms_util::exceptions::YAMLFormatError(
163 "Value for key '" + key +
"' must be a map but is type " + std::to_string(val.Type()) +
164 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
166 for (YAML::const_iterator it2 = val.begin(); it2 != val.end(); ++it2) {
167 const std::string monitor_id = it2->first.as<std::string>();
168 if (!it2->second.IsScalar()) {
169 throw auto_apms_util::exceptions::YAMLFormatError(
170 "Value for key '" + monitor_id +
"' in the EMERGENCY group must be scalar but is type " +
171 std::to_string(val.Type()) +
" (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
173 rhs.emergency.push_back(
174 {Config::TreeResourceIdentity(monitor_id), it2->second.as<Config::TreeResourceIdentity>()});
179 if (key == Config::YAML_KEY_SHUTDOWN) {
180 if (val.IsNull())
continue;
181 if (!val.IsSequence()) {
182 throw auto_apms_util::exceptions::YAMLFormatError(
183 "Value for key '" + key +
"' must be a sequence but is type " + std::to_string(val.Type()) +
184 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
186 rhs.shutdown = val.as<std::vector<Config::TreeResourceIdentity>>();
191 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 missions supported by AutoAPMS.
static MissionConfiguration fromResourceIdentity(const std::string identity)
Create a mission configuration from an installed resource.