21#include "auto_apms_util/exceptions.hpp"
22#include "auto_apms_util/yaml.hpp"
33 static const std::string PARAM_NAME_CLASS;
34 static const std::string PARAM_NAME_ROS2TOPIC;
35 static const std::string PARAM_NAME_DESCRIPTION;
36 static const std::string PARAM_NAME_PORT_ALIAS;
37 static const std::string PARAM_NAME_PORT_DEFAULT;
38 static const std::string PARAM_NAME_WAIT_TIMEOUT;
39 static const std::string PARAM_NAME_REQUEST_TIMEOUT;
40 static const std::string PARAM_NAME_ALLOW_UNREACHABLE;
41 static const std::string PARAM_NAME_LOGGER_LEVEL;
42 static const std::string PARAM_NAME_HIDDEN_PORTS;
43 static const std::string PARAM_NAME_EXTRA;
78 std::
string topic =
"(input:topic)";
114 std::chrono::duration<double>
wait_timeout = std::chrono::duration<double>(3);
146 inline static Node encode(
const Options & rhs)
148 Node node(NodeType::Map);
149 node[Options::PARAM_NAME_CLASS] = rhs.class_name;
150 node[Options::PARAM_NAME_DESCRIPTION] = rhs.description;
151 node[Options::PARAM_NAME_ROS2TOPIC] = rhs.topic;
152 node[Options::PARAM_NAME_PORT_ALIAS] = rhs.port_alias;
153 node[Options::PARAM_NAME_PORT_DEFAULT] = rhs.port_default;
154 node[Options::PARAM_NAME_HIDDEN_PORTS] = rhs.hidden_ports;
155 node[Options::PARAM_NAME_WAIT_TIMEOUT] = rhs.wait_timeout.count();
156 node[Options::PARAM_NAME_REQUEST_TIMEOUT] = rhs.request_timeout.count();
157 node[Options::PARAM_NAME_ALLOW_UNREACHABLE] = rhs.allow_unreachable;
158 node[Options::PARAM_NAME_LOGGER_LEVEL] = rhs.logger_level;
159 node[Options::PARAM_NAME_EXTRA] = rhs.extra;
162 inline static bool decode(
const Node & node, Options & rhs)
165 throw auto_apms_util::exceptions::YAMLFormatError(
166 "YAML::Node for auto_apms_behavior_tree::core::NodeRegistrationOptions must be map but is type " +
167 std::to_string(node.Type()) +
" (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
169 for (YAML::const_iterator it = node.begin(); it != node.end(); ++it) {
170 const std::string key = it->first.as<std::string>();
171 const Node val = it->second;
173 if (key == Options::PARAM_NAME_EXTRA) {
179 if (key == Options::PARAM_NAME_PORT_ALIAS) {
181 throw auto_apms_util::exceptions::YAMLFormatError(
182 "Value for key '" + key +
"' must be a map but is type " + std::to_string(val.Type()) +
183 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
185 rhs.port_alias = val.as<std::map<std::string, std::string>>();
189 if (key == Options::PARAM_NAME_PORT_DEFAULT) {
191 throw auto_apms_util::exceptions::YAMLFormatError(
192 "Value for key '" + key +
"' must be a map but is type " + std::to_string(val.Type()) +
193 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
195 rhs.port_default = val.as<std::map<std::string, std::string>>();
199 if (key == Options::PARAM_NAME_HIDDEN_PORTS) {
200 if (!val.IsSequence()) {
201 throw auto_apms_util::exceptions::YAMLFormatError(
202 "Value for key '" + key +
"' must be a sequence but is type " + std::to_string(val.Type()) +
203 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
205 rhs.hidden_ports = val.as<std::vector<std::string>>();
209 if (key == Options::PARAM_NAME_CLASS) {
210 if (!val.IsScalar()) {
211 throw auto_apms_util::exceptions::YAMLFormatError(
212 "Value for key '" + key +
"' must be scalar but is type " + std::to_string(val.Type()) +
213 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
215 rhs.class_name = val.as<std::string>();
218 if (key == Options::PARAM_NAME_DESCRIPTION) {
219 if (!val.IsScalar()) {
220 throw auto_apms_util::exceptions::YAMLFormatError(
221 "Value for key '" + key +
"' must be scalar but is type " + std::to_string(val.Type()) +
222 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
224 rhs.description = val.as<std::string>();
227 if (key == Options::PARAM_NAME_ROS2TOPIC) {
228 if (!val.IsScalar()) {
229 throw auto_apms_util::exceptions::YAMLFormatError(
230 "Value for key '" + key +
"' must be scalar but is type " + std::to_string(val.Type()) +
231 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
233 rhs.topic = val.as<std::string>();
236 if (key == Options::PARAM_NAME_WAIT_TIMEOUT) {
237 if (!val.IsScalar()) {
238 throw auto_apms_util::exceptions::YAMLFormatError(
239 "Value for key '" + key +
"' must be scalar but is type " + std::to_string(val.Type()) +
240 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
242 rhs.wait_timeout = std::chrono::duration<double>(val.as<
double>());
245 if (key == Options::PARAM_NAME_REQUEST_TIMEOUT) {
246 if (!val.IsScalar()) {
247 throw auto_apms_util::exceptions::YAMLFormatError(
248 "Value for key '" + key +
"' must be scalar but is type " + std::to_string(val.Type()) +
249 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
251 rhs.request_timeout = std::chrono::duration<double>(val.as<
double>());
254 if (key == Options::PARAM_NAME_ALLOW_UNREACHABLE) {
255 if (!val.IsScalar()) {
256 throw auto_apms_util::exceptions::YAMLFormatError(
257 "Value for key '" + key +
"' must be scalar but is type " + std::to_string(val.Type()) +
258 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
260 rhs.allow_unreachable = val.as<
bool>();
263 if (key == Options::PARAM_NAME_LOGGER_LEVEL) {
264 if (!val.IsScalar()) {
265 throw auto_apms_util::exceptions::YAMLFormatError(
266 "Value for key '" + key +
"' must be scalar but is type " + std::to_string(val.Type()) +
267 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
269 rhs.logger_level = val.as<std::string>();
274 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.
Core API for AutoAPMS's behavior tree implementation.
Powerful tooling for incorporating behavior trees for task development.
Parameters for loading and registering a behavior tree node class from a shared library using e....
std::chrono::duration< double > wait_timeout
std::string description
Short description of the behavior tree node's purpose and use-case.
bool valid() const
Verify that the options are valid (e.g. all required values are set).
NodeRegistrationOptions()=default
Create the default node registration options.
std::string topic
Name of the ROS 2 communication interface to connect with.
std::chrono::duration< double > request_timeout
Period [s] (measured from sending a goal request) after the node aborts waiting for a server response...
std::map< std::string, std::string > port_default
Provides the possibility to define custom default values for the ports implemented by class_name.
std::vector< std::string > hidden_ports
List of port names to hide in the node model for visualization tools like Groot2.
std::map< std::string, std::string > port_alias
Provides the possibility to rename ports implemented by class_name.
std::string class_name
Fully qualified name of the behavior tree node plugin class.
std::string logger_level
Minimum ROS 2 logging severity level for this particular node. Empty means to inherit the parent logg...