parallel_node.h
Go to the documentation of this file.
1 /* Copyright (C) 2015-2018 Michele Colledanchise - All Rights Reserved
2  * Copyright (C) 2018-2022 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 <set>
18 
19 namespace BT
20 {
40 class ParallelNode : public ControlNode
41 {
42 public:
43  ParallelNode(const std::string& name);
44 
45  ParallelNode(const std::string& name, const NodeConfig& config);
46 
48  {
49  return { InputPort<int>(THRESHOLD_SUCCESS, -1,
50  "number of children that need to succeed to trigger a "
51  "SUCCESS"),
52  InputPort<int>(THRESHOLD_FAILURE, 1,
53  "number of children that need to fail to trigger a "
54  "FAILURE") };
55  }
56 
57  ~ParallelNode() override = default;
58 
59  virtual void halt() override;
60 
61  size_t successThreshold() const;
62  size_t failureThreshold() const;
63  void setSuccessThreshold(int threshold);
64  void setFailureThreshold(int threshold);
65 
66 private:
69 
70  std::set<size_t> completed_list_;
71 
72  size_t success_count_ = 0;
73  size_t failure_count_ = 0;
74 
76  static constexpr const char* THRESHOLD_SUCCESS = "success_count";
77  static constexpr const char* THRESHOLD_FAILURE = "failure_count";
78 
79  virtual BT::NodeStatus tick() override;
80 
81  void clear();
82 };
83 
84 } // namespace BT
BT::ParallelNode::tick
virtual BT::NodeStatus tick() override
Method to be implemented by the user.
Definition: parallel_node.cpp:40
BT
Definition: ex01_wrap_legacy.cpp:29
BT::ParallelNode::clear
void clear()
Definition: parallel_node.cpp:134
BT::TreeNode::config
const NodeConfig & config() const
Definition: tree_node.cpp:345
BT::ParallelNode::success_count_
size_t success_count_
Definition: parallel_node.h:72
BT::ParallelNode::THRESHOLD_FAILURE
static constexpr const char * THRESHOLD_FAILURE
Definition: parallel_node.h:77
BT::ParallelNode
The ParallelNode execute all its children concurrently, but not in separate threads!
Definition: parallel_node.h:40
BT::ParallelNode::success_threshold_
int success_threshold_
Definition: parallel_node.h:67
BT::ParallelNode::read_parameter_from_ports_
bool read_parameter_from_ports_
Definition: parallel_node.h:75
BT::ParallelNode::failureThreshold
size_t failureThreshold() const
Definition: parallel_node.cpp:159
BT::PortsList
std::unordered_map< std::string, PortInfo > PortsList
Definition: basic_types.h:585
BT::ParallelNode::failure_count_
size_t failure_count_
Definition: parallel_node.h:73
BT::ParallelNode::successThreshold
size_t successThreshold() const
Definition: parallel_node.cpp:147
BT::ParallelNode::~ParallelNode
~ParallelNode() override=default
control_node.h
BT::ParallelNode::setFailureThreshold
void setFailureThreshold(int threshold)
Definition: parallel_node.cpp:176
BT::TreeNode::name
const std::string & name() const
Name of the instance, not the type.
Definition: tree_node.cpp:296
BT::ParallelNode::ParallelNode
ParallelNode(const std::string &name)
Definition: parallel_node.cpp:24
BT::ParallelNode::THRESHOLD_SUCCESS
static constexpr const char * THRESHOLD_SUCCESS
Definition: parallel_node.h:76
BT::ParallelNode::setSuccessThreshold
void setSuccessThreshold(int threshold)
Definition: parallel_node.cpp:171
BT::NodeConfig
Definition: tree_node.h:73
BT::ParallelNode::halt
virtual void halt() override
Definition: parallel_node.cpp:141
BT::ParallelNode::providedPorts
static PortsList providedPorts()
Definition: parallel_node.h:47
BT::ControlNode
Definition: control_node.h:21
BT::ParallelNode::failure_threshold_
int failure_threshold_
Definition: parallel_node.h:68
BT::NodeStatus
NodeStatus
Definition: basic_types.h:33
BT::ParallelNode::completed_list_
std::set< size_t > completed_list_
Definition: parallel_node.h:70


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Jun 28 2024 02:20:07