16 #include "nav2_behavior_tree/plugins/control/recovery_node.hpp"
18 namespace nav2_behavior_tree
22 const std::string & name,
23 const BT::NodeConfiguration & conf)
24 : BT::ControlNode::ControlNode(name, conf),
25 current_child_idx_(0),
26 number_of_retries_(1),
29 getInput(
"number_of_retries", number_of_retries_);
32 BT::NodeStatus RecoveryNode::tick()
34 const unsigned children_count = children_nodes_.size();
36 if (children_count != 2) {
37 throw BT::BehaviorTreeException(
"Recovery Node '" + name() +
"' must only have 2 children.");
40 setStatus(BT::NodeStatus::RUNNING);
42 while (current_child_idx_ < children_count && retry_count_ <= number_of_retries_) {
43 TreeNode * child_node = children_nodes_[current_child_idx_];
44 const BT::NodeStatus child_status = child_node->executeTick();
46 if (current_child_idx_ == 0) {
47 switch (child_status) {
48 case BT::NodeStatus::SUCCESS:
52 return BT::NodeStatus::SUCCESS;
55 case BT::NodeStatus::FAILURE:
57 if (retry_count_ < number_of_retries_) {
59 ControlNode::haltChild(0);
65 return BT::NodeStatus::FAILURE;
69 case BT::NodeStatus::RUNNING:
71 return BT::NodeStatus::RUNNING;
76 throw BT::LogicError(
"A child node must never return IDLE");
80 }
else if (current_child_idx_ == 1) {
81 switch (child_status) {
82 case BT::NodeStatus::SUCCESS:
85 ControlNode::haltChild(1);
91 case BT::NodeStatus::FAILURE:
95 return BT::NodeStatus::FAILURE;
98 case BT::NodeStatus::RUNNING:
100 return BT::NodeStatus::RUNNING;
105 throw BT::LogicError(
"A child node must never return IDLE");
113 return BT::NodeStatus::FAILURE;
116 void RecoveryNode::halt()
120 current_child_idx_ = 0;
125 #include "behaviortree_cpp_v3/bt_factory.h"
126 BT_REGISTER_NODES(factory)
The RecoveryNode has only two children and returns SUCCESS if and only if the first child returns SUC...
RecoveryNode(const std::string &name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::RecoveryNode.