BehaviorTree
Core Library to create and execute Behavior Trees
Loading...
Searching...
No Matches
sequence_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/control_node.h"
17
18namespace BT
19{
20/**
21 * @brief The SequenceNode is used to tick children in an ordered sequence.
22 * If any child returns RUNNING, previous children will NOT be ticked again.
23 *
24 * - If all the children return SUCCESS, this node returns SUCCESS.
25 *
26 * - If a child returns RUNNING, this node returns RUNNING.
27 * Loop is NOT restarted, the same running child will be ticked again.
28 *
29 * - If a child returns FAILURE, stop the loop and return FAILURE.
30 * Restart the loop only if (reset_on_failure == true)
31 *
32 */
33
34class SequenceNode : public ControlNode
35{
36public:
37 SequenceNode(const std::string& name, bool make_async = false,
38 const NodeConfiguration& conf = NodeConfiguration());
39
40 ~SequenceNode() override = default;
41
42 SequenceNode(const SequenceNode&) = delete;
43 SequenceNode& operator=(const SequenceNode&) = delete;
44 SequenceNode(SequenceNode&&) = delete;
45 SequenceNode& operator=(SequenceNode&&) = delete;
46
47 virtual void halt() override;
48
49protected:
50 size_t current_child_idx_;
51
52 virtual BT::NodeStatus tick() override;
53
54private:
55 size_t skipped_count_ = 0;
56 bool asynch_ = false;
57};
58
59} // namespace BT
The ControlNode is the base class for nodes that can have multiple children.
Definition: control_node.h:32
The SequenceNode is used to tick children in an ordered sequence. If any child returns RUNNING,...
Definition: sequence_node.h:35
virtual BT::NodeStatus tick() override
Method to be implemented by the user.
virtual void halt() override
Definition: action_node.h:24
NodeStatus
Definition: basic_types.h:34