AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
build_handler.cpp
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// https://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#include "auto_apms_behavior_tree/build_handler/build_handler.hpp"
16
17#include "auto_apms_behavior_tree/exceptions.hpp"
18
20{
21
23 const std::string & name, rclcpp::Node::SharedPtr ros_node_ptr, NodeLoader::SharedPtr tree_node_loader_ptr)
24: logger_(ros_node_ptr->get_logger().get_child(name)),
25 ros_node_wptr_(ros_node_ptr),
26 tree_node_loader_ptr(tree_node_loader_ptr)
27{
28}
29
30TreeBuildHandler::TreeBuildHandler(rclcpp::Node::SharedPtr ros_node_ptr, NodeLoader::SharedPtr tree_node_loader_ptr)
31: TreeBuildHandler("tree_build_handler", ros_node_ptr, tree_node_loader_ptr)
32{
33}
34
36 const std::string & /*build_request*/, const NodeManifest & /*node_manifest*/, const std::string & /*root_tree_name*/)
37{
38 return true;
39}
40
41rclcpp::Node::SharedPtr TreeBuildHandler::getRosNodePtr() const
42{
43 if (ros_node_wptr_.expired()) {
44 throw std::runtime_error("TreeBuildHandler: Weak pointer to rclcpp::Node expired.");
45 }
46 return ros_node_wptr_.lock();
47}
48
49TreeBuildHandler::NodeLoader::SharedPtr TreeBuildHandler::getNodeLoaderPtr() const { return tree_node_loader_ptr; }
50
51} // 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.
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.
virtual bool setBuildRequest(const std::string &build_request, const NodeManifest &node_manifest, const std::string &root_tree_name)
Specify the behavior tree build request encoded in a string.
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.
Useful tooling for incorporating behavior trees for task development.
Definition builder.hpp:30