AutoAPMS
Resilient Robot Mission Management
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// 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 <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(const std::string & registration_name = "", const std::string & instance_name = "") \
27 { \
28 NodeElement::removeFirstChild(registration_name, instance_name); \
29 return *this; \
30 } \
31 template <class T> \
32 typename std::enable_if_t<std::is_base_of_v<NodeModelType, T>, ClassType &> removeFirstChild( \
33 const std::string & instance_name = "") \
34 { \
35 NodeElement::removeFirstChild<T>(instance_name); \
36 return *this; \
37 } \
38 ClassType & removeChildren() \
39 { \
40 NodeElement::removeChildren(); \
41 return *this; \
42 }
43
44#define AUTO_APMS_BEHAVIOR_TREE_CORE_DEFINE_LEAF_THISREF_METHODS(ClassType) \
45 ClassType & setPorts(const auto_apms_behavior_tree::core::TreeDocument::NodeElement::PortValues & port_values) \
46 { \
47 NodeElement::setPorts(port_values); \
48 return *this; \
49 } \
50 ClassType & resetPorts() \
51 { \
52 NodeElement::resetPorts(); \
53 return *this; \
54 } \
55 ClassType & setConditionalScript(BT::PreCond type, const auto_apms_behavior_tree::core::Script & script) \
56 { \
57 NodeElement::setConditionalScript(type, script); \
58 return *this; \
59 } \
60 ClassType & setConditionalScript(BT::PostCond type, const auto_apms_behavior_tree::core::Script & script) \
61 { \
62 NodeElement::setConditionalScript(type, script); \
63 return *this; \
64 } \
65 ClassType & setName(const std::string & instance_name) \
66 { \
67 NodeElement::setName(instance_name); \
68 return *this; \
69 }
70
72
74{
75namespace core
76{
77
79
80class TreeBuilder;
81
86class NodeModelType : public TreeDocument::NodeElement
87{
88protected:
89 using NodeElement::NodeElement;
90
91public:
92 using RegistrationOptions = NodeRegistrationOptions;
93 using PortInfos = std::map<std::string, BT::PortInfo>;
94
95 virtual std::string getRegistrationName() const override = 0;
96
101 NodeElement toNodeElement();
102};
103
108class LeafNodeModelType : public NodeModelType
109{
110protected:
111 using NodeModelType::NodeModelType;
112
113public:
114 /* Not supported methods for LeafNodeModelType instances */
115
116 LeafNodeModelType insertNode() = delete;
117 LeafNodeModelType insertSubTreeNode() = delete;
118 LeafNodeModelType insertTree() = delete;
119 LeafNodeModelType insertTreeFromDocument() = delete;
120 LeafNodeModelType insertTreeFromString() = delete;
121 LeafNodeModelType insertTreeFromFile() = delete;
122 LeafNodeModelType insertTreeFromResource() = delete;
123 LeafNodeModelType & removeFirstChild() = delete;
124 LeafNodeModelType & removeChildren() = delete;
125};
126
128
129} // namespace core
130
153namespace model
154{
155
161class SubTree : public core::LeafNodeModelType
162{
164
165private:
166 using LeafNodeModelType::LeafNodeModelType;
167
168public:
170 static std::string name();
171
173 static BT::NodeType type();
174
179 std::string getRegistrationName() const override final;
180
181 AUTO_APMS_BEHAVIOR_TREE_CORE_DEFINE_LEAF_THISREF_METHODS(SubTree)
182
183
189 SubTree & setBlackboardRemapping(const PortValues & remapping);
190
196 SubTree & set_auto_remap(bool val = false);
197
202 bool get_auto_remap() const;
203};
204
205} // namespace model
206} // namespace auto_apms_behavior_tree
Class for configuring and instantiating behavior trees.
Definition builder.hpp:55
Handle for a single node of a TreeDocument.
Subtree behavior tree node model.
SubTree & setBlackboardRemapping(const PortValues &remapping)
Configure which blackboard entries of the subtree node's parent tree should be also available for the...
static BT::NodeType type()
Type of the behavior tree node.
bool get_auto_remap() const
Get automatic blackboard remapping.
std::string getRegistrationName() const override final
Get the type specific name under which all subtree nodes are registered with the behavior tree factor...
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 builder.hpp:30
Models for all available behavior tree nodes.
Useful tooling for incorporating behavior trees for task development.
Definition builder.hpp:30