fallback_node.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2015-2018 Michele Colledanchise - All Rights Reserved
2  * Copyright (C) 2018 Davide Faconti - 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 
15 
16 namespace BT
17 {
18 FallbackNode::FallbackNode(const std::string& name)
20 {
21  setRegistrationName("Fallback");
22 }
23 
25 {
26  // gets the number of children. The number could change if, at runtime, one edits the tree.
27  const unsigned children_count = children_nodes_.size();
28 
29  // Routing the ticks according to the fallback node's logic:
30 
32 
33  for (unsigned index = 0; index < children_count; index++)
34  {
35  TreeNode* child_node = children_nodes_[index];
36  const NodeStatus child_status = child_node->executeTick();
37 
38  switch (child_status)
39  {
41  {
42  return child_status;
43  }
45  {
46  haltChildren(0);
47  return child_status;
48  }
50  {
51  // continue;
52  }
53  break;
54 
55  case NodeStatus::IDLE:
56  {
57  throw std::runtime_error("This is not supposed to happen");
58  }
59  } // end switch
60  } // end for loop
61 
62  haltChildren(0);
63  return NodeStatus::FAILURE;
64 }
65 }
std::vector< TreeNode * > children_nodes_
Definition: control_node.h:26
void setRegistrationName(const std::string &registration_name)
registrationName() is set by the BehaviorTreeFactory
Definition: tree_node.cpp:113
void haltChildren(int i)
std::unordered_map< std::string, std::string > NodeParameters
Definition: tree_node.h:33
FallbackNode(const std::string &name)
virtual BT::NodeStatus tick() override
Method to be implemented by the user.
NodeStatus
Definition: basic_types.h:28
virtual BT::NodeStatus executeTick()
The method that will be executed to invoke tick(); and setStatus();.
Definition: tree_node.cpp:35
void setStatus(NodeStatus new_status)
Definition: tree_node.cpp:43


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Feb 2 2019 04:01:53