BehaviorTree
Core Library to create and execute Behavior Trees
Loading...
Searching...
No Matches
reactive_fallback.h
1/* Copyright (C) 2020-2025 Davide Faconti, Eurecat - All Rights Reserved
2*
3* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
4* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
5* 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:
6* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7*
8* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9* 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,
10* 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.
11*/
12
13#pragma once
14
15#include "behaviortree_cpp/control_node.h"
16
17namespace BT
18{
19/**
20 * @brief The ReactiveFallback is similar to a ParallelNode.
21 * All the children are ticked from first to last:
22 *
23 * - If a child returns RUNNING, continue to the next sibling.
24 * - If a child returns FAILURE, continue to the next sibling.
25 * - If a child returns SUCCESS, stop and return SUCCESS.
26 *
27 * If all the children fail, than this node returns FAILURE.
28 *
29 * IMPORTANT: to work properly, this node should not have more than
30 * a single asynchronous child.
31 *
32 */
33class ReactiveFallback : public ControlNode
34{
35public:
36 ReactiveFallback(const std::string& name) : ControlNode(name, {})
37 {}
38
39 /** A ReactiveFallback is not supposed to have more than a single
40 * anychronous node; if it does an exception is thrown.
41 * You can disabled that check, if you know what you are doing.
42 */
43 static void EnableException(bool enable);
44
45private:
46 BT::NodeStatus tick() override;
47
48 void halt() override;
49
50 int running_child_ = -1;
51 static bool throw_if_multiple_running;
52};
53
54} // namespace BT
The ControlNode is the base class for nodes that can have multiple children.
Definition: control_node.h:32
The ReactiveFallback is similar to a ParallelNode. All the children are ticked from first to last:
Definition: reactive_fallback.h:34
static void EnableException(bool enable)
Definition: action_node.h:24
NodeStatus
Definition: basic_types.h:34