AutoAPMS
Streamlining behaviors in ROS 2
Loading...
Searching...
No Matches
tree_resource.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// 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#pragma once
16
17#include <set>
18#include <string>
19#include <vector>
20
21#include "auto_apms_behavior_tree_core/behavior.hpp"
22#include "auto_apms_util/yaml.hpp"
23
25{
26
33{
41 TreeResourceIdentity(const std::string & identity);
42
50 TreeResourceIdentity(const char * identity);
51
58
60 std::string file_stem;
62 std::string tree_name;
63};
64
155class TreeResource : public BehaviorResourceTemplate<TreeResourceIdentity>
156{
157 friend class TreeDocument;
158 friend class TreeBuilder;
159
160public:
167 TreeResource(const TreeResourceIdentity & search_identity);
168
177 TreeResource(const std::string & search_identity);
178
187 TreeResource(const char * search_identity);
188
201 static TreeResource findByTreeName(const std::string & tree_name, const std::string & package_name = "");
202
216 static TreeResource findByFileStem(const std::string & file_stem, const std::string & package_name = "");
217
230 bool hasRootTreeName() const;
231
245 std::string getRootTreeName() const;
246
253 TreeResourceIdentity createIdentityForTree(const std::string & tree_name = "") const;
254
255private:
256 std::string doc_root_tree_name_;
257};
258
259} // namespace auto_apms_behavior_tree::core
260
262namespace YAML
263{
264template <>
266{
268 static Node encode(const Identity & rhs)
269 {
270 Node node;
271 node = rhs.str();
272 return node;
273 }
274 static bool decode(const Node & node, Identity & rhs)
275 {
276 if (!node.IsScalar()) return false;
277 rhs = Identity(node.Scalar());
278 return true;
279 }
280};
281} // namespace YAML
TreeResourceIdentity createIdentityForTree(const std::string &tree_name="") const
Create a valid identity string for a specific behavior tree of this resource.
std::string getRootTreeName() const
Get the name of the root tree of this behavior tree resource.
static TreeResource findByTreeName(const std::string &tree_name, const std::string &package_name="")
Find an installed behavior tree resource using a specific behavior tree name.
static TreeResource findByFileStem(const std::string &file_stem, const std::string &package_name="")
Find an installed behavior tree resource using a specific behavior tree XML file stem.
TreeResource(const TreeResourceIdentity &search_identity)
Assemble a behavior tree resource using a TreeResourceIdentity.
bool hasRootTreeName() const
Determine if this behavior tree resource specifies a root tree.
Core API for AutoAPMS's behavior tree implementation.
Definition behavior.hpp:32
Powerful tooling for incorporating behavior trees for task development.
Definition behavior.hpp:32
BehaviorResourceIdentity(const std::string &identity)
Constructor of a behavior resource identity object.
Definition behavior.cpp:28
std::string str() const
Create the corresponding identity string.
Definition behavior.cpp:83
Struct that encapsulates the identity string for a registered behavior tree.
std::string tree_name
Name of a specific tree inside the resource's tree document.
std::string file_stem
Name of the file (without extension) that contains the resource's tree document.
TreeResourceIdentity()=default
Constructor of an empty behavior tree resource identity object.
TreeResourceIdentity(const std::string &identity)
Constructor of a tree resource identity object.