15#include "auto_apms_behavior_tree/build_handler.hpp"
16#include "auto_apms_behavior_tree_core/tree/tree_resource.hpp"
31 TreeFromResourceBuildHandler(rclcpp::Node::SharedPtr ros_node_ptr, NodeLoader::SharedPtr tree_node_loader_ptr)
32 :
TreeBuildHandler(
"tree_from_resource", ros_node_ptr, tree_node_loader_ptr),
33 resource_doc_(TreeDocument::BTCPP_FORMAT_DEFAULT_VERSION, tree_node_loader_ptr)
38 const std::string & build_request,
const std::string & entrypoint,
39 const NodeManifest & )
override final
41 TreeResource::Identity resource_identity(build_request);
42 TreeResource resource(resource_identity);
45 resource_doc_.reset().mergeResource(resource,
false);
47 if (
const BT::Result res = resource_doc_.verify(); !res) {
48 RCLCPP_WARN(
logger_,
"Tree verification failed: %s", res.error().c_str());
53 std::string name = entrypoint;
54 if (entrypoint.empty()) {
60 "Cannot determine root tree from tree resource identity '%s': You must either provide an identity that "
61 "includes a tree name or specify the entrypoint argument with a non empty string.",
62 resource_identity.
str().c_str());
66 resource_doc_.setRootTreeName(name);
76 resource_doc_.
reset();
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.
Standard build handler for building a behavior tree from an installed resource.
Handle for a single behavior tree of a TreeDocument.
Document Object Model (DOM) for the behavior tree XML schema. This class offers a programmatic approa...
TreeElement getRootTree()
Get the corresponding behavior tree element for the root tree of this document.
TreeDocument & mergeTreeDocument(const XMLDocument &other, bool adopt_root_tree=false)
Merge another tree document with this one.
TreeDocument & reset()
Clear this document and reset it to its initial state.
std::string getRootTreeName() const
Get the name of the root tree of this behavior tree resource.
bool hasRootTreeName() const
Determine if this behavior tree resource specifies a root tree.
#define AUTO_APMS_BEHAVIOR_TREE_REGISTER_BUILD_HANDLER(type)
Macro for registering a behavior tree build handler plugin which may be loaded at runtime to build a ...
Powerful tooling for incorporating behavior trees for task development.
std::string str() const
Create the corresponding identity string.