21#include "auto_apms_util/exceptions.hpp"
22#include "auto_apms_util/yaml.hpp"
33struct convert<auto_apms_behavior_tree::core::NodeRegistrationOptions>
35 using Options = auto_apms_behavior_tree::core::NodeRegistrationOptions;
36 static Node encode(
const Options & rhs);
37 static bool decode(
const Node & node, Options & lhs);
51 static const std::string PARAM_NAME_CLASS;
52 static const std::string PARAM_NAME_PORT;
53 static const std::string PARAM_NAME_WAIT_TIMEOUT;
54 static const std::string PARAM_NAME_REQUEST_TIMEOUT;
55 static const std::string PARAM_NAME_ALLOW_UNREACHABLE;
56 static const std::string PARAM_NAME_LOGGER_LEVEL;
82 std::
string port =
"(input:port)";
84 std::chrono::duration<
double>
wait_timeout = std::chrono::duration<
double>(3);
109inline Node convert<auto_apms_behavior_tree::core::NodeRegistrationOptions>::encode(
const Options & rhs)
111 Node node(NodeType::Map);
112 node[Options::PARAM_NAME_CLASS] = rhs.class_name;
113 node[Options::PARAM_NAME_PORT] = rhs.port;
114 node[Options::PARAM_NAME_WAIT_TIMEOUT] = rhs.wait_timeout.count();
115 node[Options::PARAM_NAME_REQUEST_TIMEOUT] = rhs.request_timeout.count();
116 node[Options::PARAM_NAME_ALLOW_UNREACHABLE] = rhs.allow_unreachable;
117 node[Options::PARAM_NAME_LOGGER_LEVEL] = rhs.logger_level;
120inline bool convert<auto_apms_behavior_tree::core::NodeRegistrationOptions>::decode(
const Node & node, Options & rhs)
123 throw auto_apms_util::exceptions::YAMLFormatError(
124 "YAML::Node for auto_apms_behavior_tree::core::NodeRegistrationOptions must be map but is type " +
125 std::to_string(node.Type()) +
" (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
127 for (
auto it = node.begin(); it != node.end(); ++it) {
128 const std::string key = it->first.as<std::string>();
129 const Node & val = it->second;
131 throw auto_apms_util::exceptions::YAMLFormatError(
132 "Value for key '" + key +
"' must be scalar but is type " + std::to_string(val.Type()) +
133 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
135 if (key == Options::PARAM_NAME_CLASS) {
136 rhs.class_name = val.as<std::string>();
139 if (key == Options::PARAM_NAME_PORT) {
140 rhs.port = val.as<std::string>();
143 if (key == Options::PARAM_NAME_WAIT_TIMEOUT) {
144 rhs.wait_timeout = std::chrono::duration<double>(val.as<
double>());
147 if (key == Options::PARAM_NAME_REQUEST_TIMEOUT) {
148 rhs.request_timeout = std::chrono::duration<double>(val.as<
double>());
151 if (key == Options::PARAM_NAME_ALLOW_UNREACHABLE) {
152 rhs.allow_unreachable = val.as<
bool>();
155 if (key == Options::PARAM_NAME_LOGGER_LEVEL) {
156 rhs.logger_level = val.as<std::string>();
160 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.
Parameters for loading and registering a behavior tree node class from a shared library using e....
std::string port
Default port name of the corresponding ROS 2 communication interface.
std::chrono::duration< double > wait_timeout
Period [s] (measured from tree construction) after the server is considered unreachable.
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::chrono::duration< double > request_timeout
Period [s] (measured from sending a goal request) after the node aborts waiting for a server response...
std::string class_name
Fully qualified name of the behavior tree node plugin class.
std::string logger_level
Minimum severity level enabled for logging using the ROS 2 Logger API.