Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 77d2aa7

Browse files
committed
Remove duplication related to IDLE
1 parent 7bbc567 commit 77d2aa7

File tree

10 files changed

+37
-37
lines changed

10 files changed

+37
-37
lines changed

include/behaviortree_cpp/decorator_node.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class DecoratorNode : public TreeNode
3131
{
3232
return NodeType::DECORATOR;
3333
}
34+
35+
NodeStatus executeTick() override;
3436
};
3537

3638
/**

include/behaviortree_cpp/decorators/force_failure_node.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ inline NodeStatus ForceFailureDecorator::tick()
4242
case NodeStatus::FAILURE:
4343
case NodeStatus::SUCCESS:
4444
{
45-
child_node_->setStatus(NodeStatus::IDLE);
4645
return NodeStatus::FAILURE;
4746
}
4847

include/behaviortree_cpp/decorators/force_success_node.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ inline NodeStatus ForceSuccessDecorator::tick()
4242
case NodeStatus::FAILURE:
4343
case NodeStatus::SUCCESS:
4444
{
45-
child_node_->setStatus(NodeStatus::IDLE);
4645
return NodeStatus::SUCCESS;
4746
}
4847

include/behaviortree_cpp/decorators/repeat_node.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ class RepeatNode : public DecoratorNode
4141
bool read_parameter_from_blackboard_;
4242
static constexpr const char* NUM_CYCLES = "num_cycles";
4343

44-
virtual BT::NodeStatus tick() override;
44+
virtual NodeStatus tick() override;
45+
46+
void halt() override;
4547
};
48+
4649
}
4750

4851
#endif

src/decorator_node.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,16 @@ NodeStatus SimpleDecoratorNode::tick()
6767
{
6868
return tick_functor_(child()->executeTick(), *this);
6969
}
70+
71+
NodeStatus DecoratorNode::executeTick()
72+
{
73+
NodeStatus status = TreeNode::executeTick();
74+
NodeStatus child_status =child()->status();
75+
if( child_status == NodeStatus::SUCCESS || child_status == NodeStatus::FAILURE )
76+
{
77+
child()->setStatus(NodeStatus::IDLE);
78+
}
79+
return status;
80+
}
81+
7082
}

src/decorators/inverter_node.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,18 @@ NodeStatus InverterNode::tick()
3030
{
3131
case NodeStatus::SUCCESS:
3232
{
33-
setStatus(NodeStatus::FAILURE);
34-
child_node_->setStatus(NodeStatus::IDLE);
33+
return NodeStatus::FAILURE;
3534
}
36-
break;
3735

3836
case NodeStatus::FAILURE:
3937
{
40-
setStatus(NodeStatus::SUCCESS);
41-
child_node_->setStatus(NodeStatus::IDLE);
38+
return NodeStatus::SUCCESS;
4239
}
43-
break;
4440

4541
case NodeStatus::RUNNING:
4642
{
47-
setStatus(NodeStatus::RUNNING);
43+
return NodeStatus::RUNNING;
4844
}
49-
break;
5045

5146
default:
5247
{

src/decorators/repeat_node.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,33 +61,35 @@ NodeStatus RepeatNode::tick()
6161
try_index_++;
6262
if (try_index_ >= num_cycles_)
6363
{
64-
setStatus(NodeStatus::SUCCESS);
6564
try_index_ = 0;
65+
return (NodeStatus::SUCCESS);
6666
}
67-
child_node_->setStatus(NodeStatus::IDLE);
6867
}
6968
break;
7069

7170
case NodeStatus::FAILURE:
7271
{
7372
try_index_ = 0;
74-
setStatus(NodeStatus::FAILURE);
75-
child_node_->setStatus(NodeStatus::IDLE);
73+
return (NodeStatus::FAILURE);
7674
}
77-
break;
7875

7976
case NodeStatus::RUNNING:
8077
{
81-
setStatus(NodeStatus::RUNNING);
78+
return (NodeStatus::RUNNING);
8279
}
83-
break;
8480

8581
default:
8682
{
8783
// TODO throw?
8884
}
8985
}
90-
9186
return status();
9287
}
88+
89+
void RepeatNode::halt()
90+
{
91+
try_index_ = 0;
92+
DecoratorNode::halt();
93+
}
94+
9395
}

src/decorators/retry_node.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,24 @@ NodeStatus RetryNode::tick()
6565
case NodeStatus::SUCCESS:
6666
{
6767
try_index_ = 0;
68-
setStatus(NodeStatus::SUCCESS);
69-
child_node_->setStatus(NodeStatus::IDLE);
68+
return (NodeStatus::SUCCESS);
7069
}
71-
break;
7270

7371
case NodeStatus::FAILURE:
7472
{
7573
try_index_++;
7674
if (try_index_ >= max_attempts_)
7775
{
7876
try_index_ = 0;
79-
setStatus(NodeStatus::FAILURE);
77+
return (NodeStatus::FAILURE);
8078
}
81-
child_node_->setStatus(NodeStatus::IDLE);
8279
}
8380
break;
8481

8582
case NodeStatus::RUNNING:
8683
{
87-
setStatus(NodeStatus::RUNNING);
84+
return (NodeStatus::RUNNING);
8885
}
89-
break;
9086

9187
default:
9288
{
@@ -96,4 +92,5 @@ NodeStatus RetryNode::tick()
9692

9793
return status();
9894
}
95+
9996
}

src/decorators/subtree_node.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ BT::NodeStatus BT::DecoratorSubtreeNode::tick()
1414
{
1515
setStatus(NodeStatus::RUNNING);
1616
}
17-
auto status = child_node_->executeTick();
18-
setStatus(status);
19-
20-
// reset child if completed
21-
if( status == NodeStatus::SUCCESS || status == NodeStatus::FAILURE)
22-
{
23-
child_node_->setStatus(NodeStatus::IDLE);
24-
}
25-
return status;
17+
return child_node_->executeTick();
2618
}
2719

src/decorators/timeout_node.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ NodeStatus TimeoutNode::tick()
5454
if (!aborted && child()->status() == NodeStatus::RUNNING)
5555
{
5656
child()->halt();
57-
child()->setStatus(NodeStatus::IDLE);
5857
child_halted_ = true;
5958
}
6059
});
@@ -70,12 +69,12 @@ NodeStatus TimeoutNode::tick()
7069
auto child_status = child()->executeTick();
7170
if (child_status != NodeStatus::RUNNING)
7271
{
73-
child()->setStatus(NodeStatus::IDLE);
7472
timer().cancel(timer_id_);
7573
}
7674
setStatus(child_status);
7775
}
7876

7977
return status();
8078
}
79+
8180
}

0 commit comments

Comments
 (0)