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
78class TreeBuilder;
79
85{
86protected:
87 using NodeElement::NodeElement;
88
89public:
90 using RegistrationOptions = NodeRegistrationOptions;
91 using PortInfos = std::map<std::string, BT::PortInfo>;
92
93 virtual std::string getRegistrationName() const override = 0;
94
100};
101
107{
108protected:
109 using NodeModelType::NodeModelType;
110
111public:
112 /* Not supported methods for LeafNodeModelType instances */
113
114 LeafNodeModelType insertNode() = delete;
115 LeafNodeModelType insertSubTreeNode() = delete;
116 LeafNodeModelType insertTree() = delete;
117 LeafNodeModelType insertTreeFromDocument() = delete;
118 LeafNodeModelType insertTreeFromString() = delete;
119 LeafNodeModelType insertTreeFromFile() = delete;
120 LeafNodeModelType insertTreeFromResource() = delete;
121 LeafNodeModelType & removeFirstChild() = delete;
122 LeafNodeModelType & removeChildren() = delete;
123};
124
125} // namespace core
126
153namespace model
154{
155
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
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
Handle for a single node of a TreeDocument.
NodeElement(TreeDocument *doc_ptr, XMLElement *ele_ptr)
Protected constructor intended for internal use only.
std::map< std::string, std::string > PortValues
Mapping of port names and its respective value encoded as string.
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
Parameters for loading and registering a behavior tree node class from a shared library using e....