AutoAPMS
Streamlining behaviors in ROS 2
Loading...
Searching...
No Matches
node_model_type.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/node/node_registration_options.hpp"
20#include "auto_apms_behavior_tree_core/tree/tree_document.hpp"
21#include "behaviortree_cpp/basic_types.h"
22
24
25#define AUTO_APMS_BEHAVIOR_TREE_CORE_DEFINE_NON_LEAF_THISREF_METHODS(ClassType) \
26 ClassType & removeFirstChild( \
27 const std::string & registration_name = "", const std::string & instance_name = "", bool deep_search = false) \
28 { \
29 NodeElement::removeFirstChild(registration_name, instance_name, deep_search); \
30 return *this; \
31 } \
32 template <class T> \
33 typename std::enable_if_t<std::is_base_of_v<NodeModelType, T>, ClassType &> removeFirstChild( \
34 const std::string & instance_name = "", bool deep_search = false) \
35 { \
36 NodeElement::removeFirstChild<T>(instance_name, deep_search); \
37 return *this; \
38 } \
39 ClassType & removeChildren() \
40 { \
41 NodeElement::removeChildren(); \
42 return *this; \
43 }
44
45#define AUTO_APMS_BEHAVIOR_TREE_CORE_DEFINE_LEAF_THISREF_METHODS(ClassType) \
46 ClassType & setPorts(const auto_apms_behavior_tree::core::TreeDocument::NodeElement::PortValues & port_values) \
47 { \
48 NodeElement::setPorts(port_values); \
49 return *this; \
50 } \
51 ClassType & resetPorts() \
52 { \
53 NodeElement::resetPorts(); \
54 return *this; \
55 } \
56 ClassType & setConditionalScript(BT::PreCond type, const auto_apms_behavior_tree::core::Script & script) \
57 { \
58 NodeElement::setConditionalScript(type, script); \
59 return *this; \
60 } \
61 ClassType & setConditionalScript(BT::PostCond type, const auto_apms_behavior_tree::core::Script & script) \
62 { \
63 NodeElement::setConditionalScript(type, script); \
64 return *this; \
65 } \
66 ClassType & setName(const std::string & instance_name) \
67 { \
68 NodeElement::setName(instance_name); \
69 return *this; \
70 }
71
73
75{
76namespace core
77{
78
79class TreeBuilder;
80
86{
87protected:
88 using NodeElement::NodeElement;
89
90public:
91 using RegistrationOptions = NodeRegistrationOptions;
92 using PortInfos = std::map<std::string, BT::PortInfo>;
93
94 virtual std::string getRegistrationName() const override = 0;
95
101};
102
108{
109protected:
110 using NodeModelType::NodeModelType;
111
112public:
113 /* Not supported methods for LeafNodeModelType instances */
114
115 LeafNodeModelType insertNode() = delete;
116 LeafNodeModelType insertSubTreeNode() = delete;
117 LeafNodeModelType insertTree() = delete;
118 LeafNodeModelType insertTreeFromDocument() = delete;
119 LeafNodeModelType insertTreeFromString() = delete;
120 LeafNodeModelType insertTreeFromFile() = delete;
121 LeafNodeModelType insertTreeFromResource() = delete;
122 LeafNodeModelType & removeFirstChild() = delete;
123 LeafNodeModelType & removeChildren() = delete;
124 bool hasChildren() const = delete;
125 NodeElement getFirstNode() const = delete;
126 ChildIterator begin() const = delete;
127 ChildIterator end() const = delete;
128 std::vector<NodeElement> deepApplyConst() = delete;
129 std::vector<NodeElement> deepApply() = delete;
130};
131
132} // namespace core
133
160namespace model
161{
162
169{
171
172private:
173 using LeafNodeModelType::LeafNodeModelType;
174
175public:
177 static std::string name();
178
180 static BT::NodeType type();
181
186 std::string getRegistrationName() const override final;
187
188 AUTO_APMS_BEHAVIOR_TREE_CORE_DEFINE_LEAF_THISREF_METHODS(SubTree)
189
190
196 SubTree & setBlackboardRemapping(const std::map<std::string, std::string> & remapping);
197
202 std::map<std::string, std::string> getBlackboardRemapping() const;
203
209 SubTree & set_auto_remap(bool val = false);
210
215 bool get_auto_remap() const;
216};
217
218} // namespace model
219} // namespace auto_apms_behavior_tree
Abstract base for automatically generated model classes of behavior tree nodes that are not allowed t...
Abstract base for all automatically generated behavior tree node model classes to be used in interact...
NodeElement toNodeElement()
Convert to a lower level NodeElement object.
Class for configuring and instantiating behavior trees.
Definition builder.hpp:55
Forward iterator for traversing the first-level children of a node.
Handle for a single node of a TreeDocument.
NodeElement(TreeDocument *doc_ptr, XMLElement *ele_ptr)
Protected constructor intended for internal use only.
Subtree behavior tree node model.
static BT::NodeType type()
Type of the behavior tree node.
bool get_auto_remap() const
Get automatic blackboard remapping.
SubTree & setBlackboardRemapping(const std::map< std::string, std::string > &remapping)
Configure which blackboard entries of the subtree node's parent tree should be also available for the...
std::string getRegistrationName() const override final
Get the type specific name under which all subtree nodes are registered with the behavior tree factor...
std::map< std::string, std::string > getBlackboardRemapping() const
Get the currently configured blackboard remapping.
SubTree & set_auto_remap(bool val=false)
Set automatic blackboard remapping.
static std::string name()
Static method that provides the hard coded registration name of subtree nodes.
Core API for AutoAPMS's behavior tree implementation.
Definition behavior.hpp:32
Models for all available behavior tree nodes.
Powerful tooling for incorporating behavior trees for task development.
Definition behavior.hpp:32
Parameters for loading and registering a behavior tree node class from a shared library using e....