BehaviorTree
Core Library to create and execute Behavior Trees
Loading...
Searching...
No Matches
control_node.h
1/* Copyright (C) 2015-2018 Michele Colledanchise - All Rights Reserved
2 * Copyright (C) 2018-2025 Davide Faconti, Eurecat - All Rights Reserved
3*
4* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
5* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
6* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8*
9* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
11* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12*/
13
14#pragma once
15
16#include "behaviortree_cpp/tree_node.h"
17
18#include <vector>
19
20namespace BT
21{
22/**
23 * @brief The ControlNode is the base class for nodes that can have multiple children.
24 *
25 * ControlNodes determine the order and conditions under which their children are
26 * ticked.
27 *
28 * Each derived class implements specific rules about if, when, and how many
29 * times children are ticked.
30 */
31class ControlNode : public TreeNode
32{
33protected:
34 std::vector<TreeNode*> children_nodes_;
35
36public:
37 ControlNode(const std::string& name, const NodeConfig& config);
38
39 ~ControlNode() override = default;
40
41 ControlNode(const ControlNode&) = delete;
42 ControlNode& operator=(const ControlNode&) = delete;
43 ControlNode(ControlNode&&) = delete;
44 ControlNode& operator=(ControlNode&&) = delete;
45
46 /// The method used to add nodes to the children vector
47 void addChild(TreeNode* child);
48
49 size_t childrenCount() const;
50
51 const std::vector<TreeNode*>& children() const;
52
53 const TreeNode* child(size_t index) const
54 {
55 return children().at(index);
56 }
57
58 virtual void halt() override;
59
60 /// same as resetChildren()
61 void haltChildren();
62
63 [[deprecated("deprecated: please use explicitly haltChildren() or haltChild(i)")]] void
64 haltChildren(size_t first);
65
66 void haltChild(size_t i);
67
68 virtual NodeType type() const override final
69 {
70 return NodeType::CONTROL;
71 }
72
73 /// Set the status of all children to IDLE.
74 /// also send a halt() signal to all RUNNING children
75 void resetChildren();
76};
77} // namespace BT
The ControlNode is the base class for nodes that can have multiple children.
Definition: control_node.h:32
void resetChildren()
void addChild(TreeNode *child)
The method used to add nodes to the children vector.
virtual void halt() override
void haltChildren()
same as resetChildren()
Abstract base class for Behavior Tree Nodes.
Definition: tree_node.h:154
Definition: action_node.h:24
NodeType
Enumerates the possible types of nodes.
Definition: basic_types.h:21
Definition: tree_node.h:105