22#include "auto_apms_behavior_tree_core/exceptions.hpp"
23#include "auto_apms_behavior_tree_core/node/node_registration_interface.hpp"
24#include "behaviortree_cpp/basic_types.h"
37 class T,
typename = std::enable_if_t<std::is_base_of_v<BT::TreeNode, T>>,
38 bool requires_ros_node_params =
39 std::is_constructible_v<T, const std::string &, const BT::NodeConfig &, RosNodeContext>>
40class NodeRegistrationTemplate :
public NodeRegistrationInterface
43 NodeRegistrationTemplate() =
default;
44 virtual ~NodeRegistrationTemplate() =
default;
46 bool requiresRosNodeContext()
const override {
return requires_ros_node_params; }
48 void registerWithBehaviorTreeFactory(
49 BT::BehaviorTreeFactory & factory,
const std::string & registration_name,
50 const RosNodeContext *
const context_ptr =
nullptr)
const override
52 BT::PortsList ports_list = BT::getProvidedPorts<T>();
55 context_ptr->modifyProvidedPortsListForRegistration(ports_list);
56 }
catch (
const std::exception & e) {
57 throw exceptions::NodeRegistrationError(
58 "[registerWithBehaviorTreeFactory] Error registering node '" + registration_name +
"': " + e.what());
62 if constexpr (requires_ros_node_params) {
64 throw std::invalid_argument(
65 "[registerWithBehaviorTreeFactory] Error registering node '" + registration_name +
66 "': You must pass a valid RosNodeContext object to be passed via argument "
69 factory.registerNodeType<T>(registration_name, ports_list, *context_ptr);
73 if (context_ptr->registration_options_.port_alias.size() > 0) {
74 throw exceptions::NodeRegistrationError(
75 "[registerWithBehaviorTreeFactory] Error registering node '" + registration_name +
76 "': Port aliasing is not supported by this node, but " + NodeRegistrationOptions::PARAM_NAME_PORT_ALIAS +
77 " was provided in the registration options, please remove the field "
78 "from the node manifest to avoid confusion.");
81 factory.registerNodeType<T>(registration_name, ports_list);
Core API for AutoAPMS's behavior tree implementation.