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;
90 std::
string port =
"(input:port)";
92 std::chrono::duration<
double>
wait_timeout = std::chrono::duration<
double>(3);
117inline Node convert<auto_apms_behavior_tree::core::NodeRegistrationOptions>::encode(
const Options & rhs)
119 Node node(NodeType::Map);
120 node[Options::PARAM_NAME_CLASS] = rhs.class_name;
121 node[Options::PARAM_NAME_PORT] = rhs.port;
122 node[Options::PARAM_NAME_WAIT_TIMEOUT] = rhs.wait_timeout.count();
123 node[Options::PARAM_NAME_REQUEST_TIMEOUT] = rhs.request_timeout.count();
124 node[Options::PARAM_NAME_ALLOW_UNREACHABLE] = rhs.allow_unreachable;
125 node[Options::PARAM_NAME_LOGGER_LEVEL] = rhs.logger_level;
128inline bool convert<auto_apms_behavior_tree::core::NodeRegistrationOptions>::decode(
const Node & node, Options & rhs)
131 throw auto_apms_util::exceptions::YAMLFormatError(
132 "YAML::Node for auto_apms_behavior_tree::core::NodeRegistrationOptions must be map but is type " +
133 std::to_string(node.Type()) +
" (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
135 for (
auto it = node.begin(); it != node.end(); ++it) {
136 const std::string key = it->first.as<std::string>();
137 const Node & val = it->second;
139 throw auto_apms_util::exceptions::YAMLFormatError(
140 "Value for key '" + key +
"' must be scalar but is type " + std::to_string(val.Type()) +
141 " (0: Undefined - 1: Null - 2: Scalar - 3: Sequence - 4: Map).");
143 if (key == Options::PARAM_NAME_CLASS) {
144 rhs.class_name = val.as<std::string>();
147 if (key == Options::PARAM_NAME_PORT) {
148 rhs.port = val.as<std::string>();
151 if (key == Options::PARAM_NAME_WAIT_TIMEOUT) {
152 rhs.wait_timeout = std::chrono::duration<double>(val.as<
double>());
155 if (key == Options::PARAM_NAME_REQUEST_TIMEOUT) {
156 rhs.request_timeout = std::chrono::duration<double>(val.as<
double>());
159 if (key == Options::PARAM_NAME_ALLOW_UNREACHABLE) {
160 rhs.allow_unreachable = val.as<
bool>();
163 if (key == Options::PARAM_NAME_LOGGER_LEVEL) {
164 rhs.logger_level = val.as<std::string>();
168 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.