sequence_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 
19 constexpr const char* SequenceStarNode::RESET_PARAM;
20 
21 SequenceStarNode::SequenceStarNode(const std::string& name, bool reset_on_failure)
22  : ControlNode::ControlNode(name, {{RESET_PARAM, std::to_string(reset_on_failure)}})
24  , reset_on_failure_(reset_on_failure)
26 {
27  setRegistrationName("SequenceStar");
28 }
29 
30 SequenceStarNode::SequenceStarNode(const std::string& name, const NodeParameters& params)
31  : ControlNode::ControlNode(name, params), current_child_idx_(0),
33 {
36  {
38  {
39  throw std::runtime_error("Missing parameter [reset_on_failure] in SequenceStarNode");
40  }
41  }
42 }
43 
45 {
47  {
49  {
50  throw std::runtime_error("Missing parameter [reset_on_failure] in SequenceStarNode");
51  }
52  }
53 
54  const unsigned children_count = children_nodes_.size();
55 
57 
58  while (current_child_idx_ < children_count)
59  {
60  TreeNode* current_child_node = children_nodes_[current_child_idx_];
61  const NodeStatus child_status = current_child_node->executeTick();
62 
63  switch (child_status)
64  {
66  {
67  return child_status;
68  }
70  {
72  {
73  haltChildren(0);
75  }
76  else
77  {
79  }
80  return child_status;
81  }
83  {
85  }
86  break;
87 
88  case NodeStatus::IDLE:
89  {
90  throw std::runtime_error("This is not supposed to happen");
91  }
92  } // end switch
93  } // end while loop
94 
95  // The entire while loop completed. This means that all the children returned SUCCESS.
96  if (current_child_idx_ == children_count)
97  {
98  haltChildren(0);
100  }
101  return NodeStatus::SUCCESS;
102 }
103 
105 {
106  current_child_idx_ = 0;
108 }
109 }
BT::optional< T > getParam(const std::string &key) const
Definition: tree_node.h:117
const std::string & name() const
Definition: tree_node.cpp:92
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.
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
SequenceStarNode(const std::string &name, bool reset_on_failure=true)
virtual void halt() override
The method used to interrupt the execution of a RUNNING node.
static constexpr const char * RESET_PARAM
virtual BT::NodeStatus tick() override
Method to be implemented by the user.
NodeStatus
Definition: basic_types.h:28
unsigned int current_child_idx_
static bool isBlackboardPattern(StringView str)
Definition: tree_node.cpp:127
virtual BT::NodeStatus executeTick()
The method that will be executed to invoke tick(); and setStatus();.
Definition: tree_node.cpp:35
std::basic_string< CharT, Traits > to_string(basic_string_view< CharT, Traits > v)
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