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),
31 BT::NodeStatus RecoveryNode::tick()
33 getInput(
"number_of_retries", number_of_retries_);
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::SKIPPED:
51 return BT::NodeStatus::SKIPPED;
53 case BT::NodeStatus::SUCCESS:
56 ControlNode::haltChild(1);
58 return BT::NodeStatus::SUCCESS;
60 case BT::NodeStatus::RUNNING:
61 return BT::NodeStatus::RUNNING;
63 case BT::NodeStatus::FAILURE:
65 if (retry_count_ < number_of_retries_) {
67 ControlNode::haltChild(0);
73 return BT::NodeStatus::FAILURE;
78 throw BT::LogicError(
"A child node must never return IDLE");
81 }
else if (current_child_idx_ == 1) {
82 switch (child_status) {
83 case BT::NodeStatus::SKIPPED:
89 current_child_idx_ = 0;
90 ControlNode::haltChild(1);
91 return BT::NodeStatus::FAILURE;
93 case BT::NodeStatus::RUNNING:
96 case BT::NodeStatus::SUCCESS:
99 ControlNode::haltChild(1);
101 current_child_idx_ = 0;
105 case BT::NodeStatus::FAILURE:
108 return BT::NodeStatus::FAILURE;
111 throw BT::LogicError(
"A child node must never return IDLE");
118 return BT::NodeStatus::FAILURE;
121 void RecoveryNode::halt()
125 current_child_idx_ = 0;
130 #include "behaviortree_cpp/bt_factory.h"
131 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.