AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
tree_resource_builder.cpp
Go to the documentation of this file.
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
18
20{
21
22class TreeResourceBuilder : public TreeBuilderBase
23{
24public:
26
27 bool setRequest(const std::string& request) override final
28 {
29 try
30 {
31 resource_ptr_ = std::make_unique<TreeResource>(TreeResource::fromString(request));
32 }
33 catch (const exceptions::ResourceIdentityFormatError& e)
34 {
35 RCLCPP_ERROR(getLogger(), "%s", e.what());
36 return false;
37 }
39 {
40 RCLCPP_ERROR(getLogger(), "%s", e.what());
41 return false;
42 }
43 return true;
44 }
45
46 void configureBuilder(TreeBuilder& builder) override final
47 {
48 if (!resource_ptr_)
49 throw exceptions::TreeBuildError("TreeResourceBuilder - resource_ptr_ is nullptr.");
50 builder.addTreeFromResource(*resource_ptr_, getNodePtr());
51 }
52
53private:
54 std::unique_ptr<TreeResource> resource_ptr_;
55};
56
57} // namespace auto_apms_behavior_tree
58
59AUTO_APMS_BEHAVIOR_TREE_REGISTER_BUILDER(auto_apms_behavior_tree::TreeResourceBuilder)
TreeBuilderBase(rclcpp::Node::SharedPtr node_ptr)
#define AUTO_APMS_BEHAVIOR_TREE_REGISTER_BUILDER(type)
Macro for registering a behavior tree builder plugin which may be loaded at runtime to create a behav...
Definition builder.hpp:30
static TreeResource fromString(const std::string &identity)
Find a behavior tree resource using an identity string.