15#include "auto_apms_behavior_tree/build_handler.hpp"
16#include "auto_apms_behavior_tree_core/tree/tree_resource.hpp"
24 TreeFromResourceBuildHandler(rclcpp::Node::SharedPtr ros_node_ptr, NodeLoader::SharedPtr tree_node_loader_ptr)
25 :
TreeBuildHandler(
"tree_from_resource", ros_node_ptr, tree_node_loader_ptr),
26 resource_doc_(TreeDocument::BTCPP_FORMAT_DEFAULT_VERSION, tree_node_loader_ptr)
31 const std::string & build_request,
const NodeManifest & ,
32 const std::string & root_tree_name)
override final
34 TreeResource::Identity resource_identity(build_request);
35 TreeResource resource(resource_identity);
38 resource_doc_.reset().mergeResource(resource,
false);
40 if (
const BT::Result res = resource_doc_.verify(); !res) {
41 RCLCPP_WARN(
logger_,
"Tree verification failed: %s", res.error().c_str());
46 std::string name = root_tree_name;
47 if (root_tree_name.empty()) {
48 if (resource.hasRootTreeName()) {
49 name = resource.getRootTreeName();
53 "Cannot determine root tree from tree resource identity '%s': You must either provide an identity that "
54 "includes a tree name or specify the root_tree_name argument with a non empty string.",
55 resource_identity.str().c_str());
59 resource_doc_.setRootTreeName(name);
66 doc.mergeTreeDocument(resource_doc_,
true);
69 resource_doc_.reset();
72 return doc.getRootTree();
76 core::TreeDocument resource_doc_;
Base class for plugins that implement patterns for creating behavior trees using a standardized inter...
TreeBuildHandler(const std::string &name, rclcpp::Node::SharedPtr ros_node_ptr, NodeLoader::SharedPtr tree_node_loader_ptr)
Constructor allowing to give the build handler a specific name.
const rclcpp::Logger logger_
ROS 2 logger initialized with the name of the build handler.
Handle for a single behavior tree of a TreeDocument.
#define AUTO_APMS_BEHAVIOR_TREE_DECLARE_BUILD_HANDLER(type)
Macro for registering a behavior tree build handler plugin which may be loaded at runtime to build a ...
Useful tooling for incorporating behavior trees for task development.