fallback_star_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 FallbackStarNode::FallbackStarNode(const std::string& name)
20 {
21  setRegistrationName("FallbackStar");
22 }
23 
25 {
26  // Vector size initialization. children_count_ could change at runtime if you edit the tree
27  const unsigned children_count = children_nodes_.size();
28 
30 
31  while (current_child_idx_ < children_count)
32  {
33  TreeNode* current_child_node = children_nodes_[current_child_idx_];
34  const NodeStatus child_status = current_child_node->executeTick();
35 
36  switch (child_status)
37  {
39  {
40  return child_status;
41  }
43  {
44  haltChildren(0);
46  return child_status;
47  }
49  {
51  }
52  break;
53 
54  case NodeStatus::IDLE:
55  {
56  throw std::runtime_error("This is not supposed to happen");
57  }
58  } // end switch
59  } // end while loop
60 
61  // The entire while loop completed. This means that all the children returned FAILURE.
62  if (current_child_idx_ == children_count)
63  {
64  haltChildren(0);
66  }
67  return NodeStatus::FAILURE;
68 }
69 
71 {
74 }
75 }
virtual void halt() override
The method used to interrupt the execution of a RUNNING node.
std::vector< TreeNode * > children_nodes_
Definition: control_node.h:26
virtual void halt() override
The method used to interrupt the execution of a RUNNING node.
FallbackStarNode(const std::string &name)
void setRegistrationName(const std::string &registration_name)
registrationName() is set by the BehaviorTreeFactory
Definition: tree_node.cpp:113
void haltChildren(int i)
unsigned int current_child_idx_
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 Sun Feb 3 2019 03:14:32