Skip to content

Commit 87c3669

Browse files
committed
rebane haltChildren to resetChildren
1 parent ac72e9a commit 87c3669

18 files changed

+58
-22
lines changed

include/behaviortree_cpp_v3/control_node.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ControlNode : public TreeNode
4242

4343
virtual void halt() override;
4444

45+
/// same as resetChildren()
4546
void haltChildren();
4647

4748
[[deprecated("deprecated: please use explicitly haltChildren() or haltChild(i)")]] void
@@ -53,5 +54,9 @@ class ControlNode : public TreeNode
5354
{
5455
return NodeType::CONTROL;
5556
}
57+
58+
/// Set the status of all children to IDLE.
59+
/// also send a halt() signal to all RUNNING children
60+
void resetChildren();
5661
};
5762
} // namespace BT

include/behaviortree_cpp_v3/controls/switch_node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ inline NodeStatus SwitchNode<NUM_CASES>::tick()
119119
}
120120
else
121121
{
122-
haltChildren();
122+
resetChildren();
123123
running_child_ = -1;
124124
}
125125
return ret;

include/behaviortree_cpp_v3/decorator_node.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DecoratorNode : public TreeNode
2424
/// The method used to interrupt the execution of this node
2525
virtual void halt() override;
2626

27-
/// Halt() the child node
27+
/// Same as resetChild()
2828
void haltChild();
2929

3030
virtual NodeType type() const override
@@ -33,6 +33,10 @@ class DecoratorNode : public TreeNode
3333
}
3434

3535
NodeStatus executeTick() override;
36+
37+
/// Set the status of the child to IDLE.
38+
/// also send a halt() signal to a RUNNING child
39+
void resetChild();
3640
};
3741

3842
/**

src/control_node.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,19 @@ size_t ControlNode::childrenCount() const
3131

3232
void ControlNode::halt()
3333
{
34-
haltChildren();
34+
resetChildren();
35+
}
36+
37+
void ControlNode::resetChildren()
38+
{
39+
for (auto child: children_nodes_)
40+
{
41+
if (child->status() == NodeStatus::RUNNING)
42+
{
43+
child->halt();
44+
}
45+
child->resetStatus();
46+
}
3547
}
3648

3749
const std::vector<TreeNode*>& ControlNode::children() const

src/controls/fallback_node.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ NodeStatus FallbackNode::tick()
3838
return child_status;
3939
}
4040
case NodeStatus::SUCCESS: {
41-
haltChildren();
41+
resetChildren();
4242
current_child_idx_ = 0;
4343
return child_status;
4444
}
@@ -56,7 +56,7 @@ NodeStatus FallbackNode::tick()
5656
// The entire while loop completed. This means that all the children returned FAILURE.
5757
if (current_child_idx_ == children_count)
5858
{
59-
haltChildren();
59+
resetChildren();
6060
current_child_idx_ = 0;
6161
}
6262

src/controls/if_then_else_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ NodeStatus IfThenElseNode::tick()
7171
}
7272
else
7373
{
74-
haltChildren();
74+
resetChildren();
7575
child_idx_ = 0;
7676
return status;
7777
}

src/controls/parallel_node.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ NodeStatus ParallelNode::tick()
9797
if (success_childred_num == successThreshold())
9898
{
9999
skip_list_.clear();
100-
haltChildren();
100+
resetChildren();
101101
return NodeStatus::SUCCESS;
102102
}
103103
}
@@ -116,7 +116,7 @@ NodeStatus ParallelNode::tick()
116116
(failure_childred_num == failureThreshold()))
117117
{
118118
skip_list_.clear();
119-
haltChildren();
119+
resetChildren();
120120
return NodeStatus::FAILURE;
121121
}
122122
}

src/controls/reactive_fallback.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ NodeStatus ReactiveFallback::tick()
3939
break;
4040

4141
case NodeStatus::SUCCESS: {
42-
haltChildren();
42+
resetChildren();
4343
return NodeStatus::SUCCESS;
4444
}
4545

@@ -51,7 +51,7 @@ NodeStatus ReactiveFallback::tick()
5151

5252
if (failure_count == childrenCount())
5353
{
54-
haltChildren();
54+
resetChildren();
5555
return NodeStatus::FAILURE;
5656
}
5757

src/controls/reactive_sequence.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ NodeStatus ReactiveSequence::tick()
3737
}
3838

3939
case NodeStatus::FAILURE: {
40-
haltChildren();
40+
resetChildren();
4141
return NodeStatus::FAILURE;
4242
}
4343
case NodeStatus::SUCCESS: {
@@ -53,7 +53,7 @@ NodeStatus ReactiveSequence::tick()
5353

5454
if (success_count == childrenCount())
5555
{
56-
haltChildren();
56+
resetChildren();
5757
return NodeStatus::SUCCESS;
5858
}
5959
return NodeStatus::RUNNING;

src/controls/sequence_node.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ NodeStatus SequenceNode::tick()
4646
}
4747
case NodeStatus::FAILURE: {
4848
// Reset on failure
49-
haltChildren();
49+
resetChildren();
5050
current_child_idx_ = 0;
5151
return child_status;
5252
}
@@ -64,7 +64,7 @@ NodeStatus SequenceNode::tick()
6464
// The entire while loop completed. This means that all the children returned SUCCESS.
6565
if (current_child_idx_ == children_count)
6666
{
67-
haltChildren();
67+
resetChildren();
6868
current_child_idx_ = 0;
6969
}
7070
return NodeStatus::SUCCESS;

0 commit comments

Comments
 (0)