while_do_else_node.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2020 Davide Faconti - 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 
14 
15 namespace BT
16 {
17 WhileDoElseNode::WhileDoElseNode(const std::string& name) :
18  ControlNode::ControlNode(name, {})
19 {
20  setRegistrationID("WhileDoElse");
21 }
22 
24 {
26 }
27 
29 {
30  const size_t children_count = children_nodes_.size();
31 
32  if (children_count != 3)
33  {
34  throw std::logic_error("WhileDoElse must have 3 children");
35  }
36 
38 
39  NodeStatus condition_status = children_nodes_[0]->executeTick();
40 
41  if (condition_status == NodeStatus::RUNNING)
42  {
43  return condition_status;
44  }
45 
47 
48  if (condition_status == NodeStatus::SUCCESS)
49  {
50  haltChild(2);
51  status = children_nodes_[1]->executeTick();
52  }
53  else if (condition_status == NodeStatus::FAILURE)
54  {
55  haltChild(1);
56  status = children_nodes_[2]->executeTick();
57  }
58 
59  if (status == NodeStatus::RUNNING)
60  {
61  return NodeStatus::RUNNING;
62  }
63  else
64  {
65  resetChildren();
66  return status;
67  }
68 }
69 
70 } // namespace BT
std::vector< TreeNode * > children_nodes_
Definition: control_node.h:24
virtual void halt() override
NodeStatus status() const
Definition: tree_node.cpp:84
WhileDoElseNode(const std::string &name)
virtual BT::NodeStatus tick() override
Method to be implemented by the user.
void setRegistrationID(StringView ID)
Definition: tree_node.cpp:201
void haltChild(size_t i)
NodeStatus
Definition: basic_types.h:35
virtual void halt() override
void setStatus(NodeStatus new_status)
Definition: tree_node.cpp:63


behaviortree_cpp_v3
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Mon Jul 3 2023 02:50:14