MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / tick

Method tick

src/decorators/retry_node.cpp:40–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40NodeStatus RetryNode::tick()
41{
42 if(read_parameter_from_ports_)
43 {
44 if(!getInput(NUM_ATTEMPTS, max_attempts_))
45 {
46 throw RuntimeError("Missing parameter [", NUM_ATTEMPTS, "] in RetryNode");
47 }
48 }
49
50 bool do_loop = try_count_ < max_attempts_ || max_attempts_ == -1;
51 setStatus(NodeStatus::RUNNING);
52
53 while(do_loop)
54 {
55 const NodeStatus prev_status = child_node_->status();
56 const NodeStatus child_status = child_node_->executeTick();
57
58 switch(child_status)
59 {
60 case NodeStatus::SUCCESS: {
61 try_count_ = 0;
62 resetChild();
63 return (NodeStatus::SUCCESS);
64 }
65
66 case NodeStatus::FAILURE: {
67 try_count_++;
68 // Refresh max_attempts_ in case it changed in one of the child nodes
69 getInput(NUM_ATTEMPTS, max_attempts_);
70 do_loop = try_count_ < max_attempts_ || max_attempts_ == -1;
71
72 resetChild();
73
74 // Return the execution flow if the child is async,
75 // to make this interruptible.
76 if(requiresWakeUp() && prev_status == NodeStatus::IDLE && do_loop)
77 {
78 emitWakeUpSignal();
79 return NodeStatus::RUNNING;
80 }
81 }
82 break;
83
84 case NodeStatus::RUNNING: {
85 return NodeStatus::RUNNING;
86 }
87
88 case NodeStatus::SKIPPED: {
89 // to allow it to be skipped again, we must reset the node
90 resetChild();
91 // the child has been skipped. Slip this too
92 return NodeStatus::SKIPPED;
93 }
94
95 case NodeStatus::IDLE: {
96 throw LogicError("[", name(), "]: A children should not return IDLE");
97 }

Callers

nothing calls this directly

Calls 4

RuntimeErrorClass · 0.85
LogicErrorClass · 0.85
statusMethod · 0.80
executeTickMethod · 0.45

Tested by

no test coverage detected