BehaviorTree
Core Library to create and execute Behavior Trees
Loading...
Searching...
No Matches
fallback_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 FallbackNode is used to try different strategies,
22 * until one succeeds.
23 * If any child returns RUNNING, previous children will NOT be ticked again.
24 *
25 * - If all the children return FAILURE, this node returns FAILURE.
26 *
27 * - If a child returns RUNNING, this node returns RUNNING.
28 *
29 * - If a child returns SUCCESS, stop the loop and return SUCCESS.
30 *
31 */
32class FallbackNode : public ControlNode
33{
34public:
35 FallbackNode(const std::string& name, bool make_asynch = false);
36
37 ~FallbackNode() override = default;
38
39 FallbackNode(const FallbackNode&) = delete;
40 FallbackNode& operator=(const FallbackNode&) = delete;
41 FallbackNode(FallbackNode&&) = delete;
42 FallbackNode& operator=(FallbackNode&&) = delete;
43
44 virtual void halt() override;
45
46private:
47 size_t current_child_idx_;
48 size_t skipped_count_ = 0;
49 bool asynch_ = false;
50
51 virtual BT::NodeStatus tick() override;
52};
53
54} // namespace BT
The ControlNode is the base class for nodes that can have multiple children.
Definition: control_node.h:32
The FallbackNode is used to try different strategies, until one succeeds. If any child returns RUNNIN...
Definition: fallback_node.h:33
virtual void halt() override
Definition: action_node.h:24
NodeStatus
Definition: basic_types.h:34