AutoAPMS
Streamlining behaviors in ROS 2
Loading...
Searching...
No Matches
build_handler.hpp
1// Copyright 2024 Robin Müller
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <map>
18
19#include "auto_apms_behavior_tree_core/definitions.hpp"
20#include "auto_apms_behavior_tree_core/node/node_registration_loader.hpp"
21#include "auto_apms_behavior_tree_core/tree/tree_document.hpp"
22#include "rclcpp/macros.hpp"
23#include "rclcpp/node.hpp"
24
25// Include all built in node models and helpers for convenience
26#include "auto_apms_behavior_tree/behavior_tree_nodes.hpp"
27#include "auto_apms_behavior_tree/util/node.hpp"
28
29// Include exceptions if derived build handlers need to throw a TreeBuildHandlerError
30#include "auto_apms_behavior_tree/exceptions.hpp"
31
33{
34
48{
49 std::string root_tree_name;
50 std::map<std::string, std::string> inital_blackboard;
51
56
61 TreeBasedEntryPoint(const std::string & encoded_str);
62};
63
170{
171public:
172 RCLCPP_SMART_PTR_ALIASES_ONLY(TreeBuildHandler)
173
174 /* Convenience aliases for deriving classes */
175
176 using NodeLoader = core::NodeRegistrationLoader;
177 using NodeManifest = core::NodeManifest;
178 using TreeResource = core::TreeResource;
179 using TreeDocument = core::TreeDocument;
180 using TreeBlackboard = auto_apms_behavior_tree::TreeBlackboard;
181
190 const std::string & name, rclcpp::Node::SharedPtr ros_node_ptr, NodeLoader::SharedPtr tree_node_loader_ptr);
191
210 TreeBuildHandler(rclcpp::Node::SharedPtr ros_node_ptr, NodeLoader::SharedPtr tree_node_loader_ptr);
211
212 virtual ~TreeBuildHandler() = default;
213
232 virtual bool setBuildRequest(
233 const std::string & build_request, const std::string & entry_point, const NodeManifest & node_manifest);
234
247 virtual TreeDocument::TreeElement buildTree(TreeDocument & doc, TreeBlackboard & bb) = 0;
248
253 rclcpp::Node::SharedPtr getRosNodePtr() const;
254
259 NodeLoader::SharedPtr getNodeLoaderPtr() const;
260
261protected:
263 const rclcpp::Logger logger_;
264
265private:
266 rclcpp::Node::WeakPtr ros_node_wptr_;
267 NodeLoader::SharedPtr tree_node_loader_ptr;
268};
269
270} // namespace auto_apms_behavior_tree
NodeLoader::SharedPtr getNodeLoaderPtr() const
Get a shared pointer to the class loader instance used for loading the required behavior tree nodes.
virtual bool setBuildRequest(const std::string &build_request, const std::string &entry_point, const NodeManifest &node_manifest)
Specify the behavior tree build request encoded in a string.
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.
rclcpp::Node::SharedPtr getRosNodePtr() const
Get a shared pointer to the parent rclcpp::Node of this build handler.
virtual TreeDocument::TreeElement buildTree(TreeDocument &doc, TreeBlackboard &bb)=0
Build the behavior tree specified before.
Data structure for information about which behavior tree node plugin to load and how to configure the...
A pluginlib::ClassLoader specifically for loading installed behavior tree node plugins.
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...
Class containing behavior tree resource data.
Powerful tooling for incorporating behavior trees for task development.
Definition behavior.hpp:32
TreeBasedEntryPoint()=default
Default constructor.