Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "behaviortree_cpp/decorators/retry_node.h"
00015
00016 namespace BT
00017 {
00018 constexpr const char* RetryNode::NUM_ATTEMPTS;
00019
00020 RetryNode::RetryNode(const std::string& name, int NTries)
00021 : DecoratorNode(name, {} ),
00022 max_attempts_(NTries),
00023 try_index_(0),
00024 read_parameter_from_ports_(false)
00025 {
00026 setRegistrationID("RetryUntilSuccesful");
00027 }
00028
00029 RetryNode::RetryNode(const std::string& name, const NodeConfiguration& config)
00030 : DecoratorNode(name, config),
00031 max_attempts_(0),
00032 try_index_(0),
00033 read_parameter_from_ports_(true)
00034 {
00035 }
00036
00037 void RetryNode::halt()
00038 {
00039 try_index_ = 0;
00040 DecoratorNode::halt();
00041 }
00042
00043 NodeStatus RetryNode::tick()
00044 {
00045 if( read_parameter_from_ports_ )
00046 {
00047 if( !getInput(NUM_ATTEMPTS, max_attempts_) )
00048 {
00049 throw RuntimeError("Missing parameter [", NUM_ATTEMPTS,"] in RetryNode");
00050 }
00051 }
00052
00053 setStatus(NodeStatus::RUNNING);
00054
00055 while (try_index_ < max_attempts_)
00056 {
00057 NodeStatus child_state = child_node_->executeTick();
00058
00059 switch (child_state)
00060 {
00061 case NodeStatus::SUCCESS:
00062 {
00063 try_index_ = 0;
00064 return (NodeStatus::SUCCESS);
00065 }
00066
00067 case NodeStatus::FAILURE:
00068 {
00069 try_index_++;
00070 }
00071 break;
00072
00073 case NodeStatus::RUNNING:
00074 {
00075 return NodeStatus::RUNNING;
00076 }
00077
00078 default:
00079 {
00080 throw LogicError("A child node must never return IDLE");
00081 }
00082 }
00083 }
00084
00085 try_index_ = 0;
00086 return NodeStatus::FAILURE;
00087 }
00088
00089 }