Skip to content

Commit 41cb606

Browse files
committed
add resetChild to all the decorators that missed it
1 parent ee68e15 commit 41cb606

File tree

9 files changed

+45
-47
lines changed

9 files changed

+45
-47
lines changed

include/behaviortree_cpp/decorators/force_failure_node.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,15 @@ inline NodeStatus ForceFailureNode::tick()
3737
{
3838
setStatus(NodeStatus::RUNNING);
3939

40-
const NodeStatus child_state = child_node_->executeTick();
40+
const NodeStatus child_status = child_node_->executeTick();
4141

42-
switch (child_state)
42+
if(isStatusCompleted(child_status))
4343
{
44-
case NodeStatus::FAILURE:
45-
case NodeStatus::SUCCESS: {
46-
return NodeStatus::FAILURE;
47-
}
48-
49-
case NodeStatus::RUNNING: {
50-
return NodeStatus::RUNNING;
51-
}
52-
53-
default: {
54-
// TODO throw?
55-
}
44+
resetChild();
45+
return NodeStatus::FAILURE;
5646
}
57-
return status();
47+
48+
// RUNNING or skipping
49+
return child_status;
5850
}
5951
} // namespace BT

include/behaviortree_cpp/decorators/force_success_node.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,15 @@ inline NodeStatus ForceSuccessNode::tick()
3737
{
3838
setStatus(NodeStatus::RUNNING);
3939

40-
const NodeStatus child_state = child_node_->executeTick();
40+
const NodeStatus child_status = child_node_->executeTick();
4141

42-
switch (child_state)
42+
if(isStatusCompleted(child_status))
4343
{
44-
case NodeStatus::FAILURE:
45-
case NodeStatus::SUCCESS: {
46-
return NodeStatus::SUCCESS;
47-
}
48-
49-
case NodeStatus::RUNNING: {
50-
return NodeStatus::RUNNING;
51-
}
52-
53-
default: {
54-
// TODO throw?
55-
}
44+
resetChild();
45+
return NodeStatus::SUCCESS;
5646
}
57-
return status();
47+
48+
// RUNNING or skipping
49+
return child_status;
5850
}
5951
} // namespace BT

include/behaviortree_cpp/decorators/keep_running_until_failure_node.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ inline NodeStatus KeepRunningUntilFailureNode::tick()
4343
switch (child_state)
4444
{
4545
case NodeStatus::FAILURE: {
46+
resetChild();
4647
return NodeStatus::FAILURE;
4748
}
48-
case NodeStatus::SUCCESS:
49+
case NodeStatus::SUCCESS: {
50+
resetChild();
51+
return NodeStatus::RUNNING;
52+
}
4953
case NodeStatus::RUNNING: {
5054
return NodeStatus::RUNNING;
5155
}

include/behaviortree_cpp/decorators/run_once_node.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ inline NodeStatus RunOnceNode::tick()
7070
}
7171

7272
setStatus(NodeStatus::RUNNING);
73-
auto const status = child_node_->executeTick();
73+
const NodeStatus status = child_node_->executeTick();
7474

75-
if(isStatusCompleted(status) ) {
75+
if(isStatusCompleted(status)) {
7676
already_ticked_ = true;
7777
returned_status_ = status;
78+
resetChild();
7879
}
7980
return status;
8081
}

include/behaviortree_cpp/decorators/script_precondition.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,18 @@ class PreconditionNode : public DecoratorNode
4949
}
5050

5151
Ast::Environment env = {config().blackboard, config().enums};
52-
Any res = _executor(env);
53-
return (res.cast<bool>()) ? child_node_->executeTick() : else_return;
52+
if(_executor(env).cast<bool>())
53+
{
54+
auto const child_status = child_node_->executeTick();
55+
if(isStatusCompleted(child_status))
56+
{
57+
resetChild();
58+
}
59+
return child_status;
60+
}
61+
else {
62+
return else_return;
63+
}
5464
}
5565

5666
void loadExecutor()

include/behaviortree_cpp/decorators/timeout_node.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,14 @@ class TimeoutNode : public DecoratorNode
104104
}
105105
else
106106
{
107-
auto child_status = child()->executeTick();
108-
if (child_status != NodeStatus::RUNNING)
107+
const NodeStatus child_status = child()->executeTick();
108+
if(isStatusCompleted(child_status))
109109
{
110110
timeout_started_ = false;
111111
timeout_mutex_.unlock();
112112
timer_.cancel(timer_id_);
113113
timeout_mutex_.lock();
114+
resetChild();
114115
}
115116
return child_status;
116117
}

src/decorators/delay_node.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ NodeStatus DelayNode::tick()
6060
}
6161
else if (delay_complete_)
6262
{
63-
auto child_status = child()->executeTick();
64-
if(child_status != NodeStatus::RUNNING)
63+
const NodeStatus child_status = child()->executeTick();
64+
if(isStatusCompleted(child_status))
6565
{
6666
delay_started_ = false;
6767
delay_aborted_ = false;

src/decorators/inverter_node.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@ NodeStatus InverterNode::tick()
3737
return NodeStatus::SUCCESS;
3838
}
3939

40-
case NodeStatus::RUNNING: {
41-
return NodeStatus::RUNNING;
42-
}
43-
40+
case NodeStatus::RUNNING:
4441
case NodeStatus::SKIPPED: {
45-
return NodeStatus::SKIPPED;
42+
return child_status;
4643
}
44+
4745
case NodeStatus::IDLE: {
4846
throw LogicError("[", name(), "]: A children should not return IDLE");
4947
}

src/decorators/subtree_node.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ BT::NodeStatus BT::SubTreeNode::tick()
2525
{
2626
setStatus(NodeStatus::RUNNING);
2727
}
28-
auto status = child_node_->executeTick();
29-
if(status != NodeStatus::RUNNING)
28+
const NodeStatus child_status = child_node_->executeTick();
29+
if(isStatusCompleted(child_status))
3030
{
3131
resetChild();
3232
}
3333

34-
return status;
34+
return child_status;
3535
}

0 commit comments

Comments
 (0)