Skip to content

Commit

Permalink
rebane haltChildren to resetChildren
Browse files Browse the repository at this point in the history
  • Loading branch information
facontidavide committed Dec 7, 2022
1 parent ac72e9a commit 87c3669
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 22 deletions.
5 changes: 5 additions & 0 deletions include/behaviortree_cpp_v3/control_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ControlNode : public TreeNode

virtual void halt() override;

/// same as resetChildren()
void haltChildren();

[[deprecated("deprecated: please use explicitly haltChildren() or haltChild(i)")]] void
Expand All @@ -53,5 +54,9 @@ class ControlNode : public TreeNode
{
return NodeType::CONTROL;
}

/// Set the status of all children to IDLE.
/// also send a halt() signal to all RUNNING children
void resetChildren();
};
} // namespace BT
2 changes: 1 addition & 1 deletion include/behaviortree_cpp_v3/controls/switch_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ inline NodeStatus SwitchNode<NUM_CASES>::tick()
}
else
{
haltChildren();
resetChildren();
running_child_ = -1;
}
return ret;
Expand Down
6 changes: 5 additions & 1 deletion include/behaviortree_cpp_v3/decorator_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DecoratorNode : public TreeNode
/// The method used to interrupt the execution of this node
virtual void halt() override;

/// Halt() the child node
/// Same as resetChild()
void haltChild();

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

NodeStatus executeTick() override;

/// Set the status of the child to IDLE.
/// also send a halt() signal to a RUNNING child
void resetChild();
};

/**
Expand Down
14 changes: 13 additions & 1 deletion src/control_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,19 @@ size_t ControlNode::childrenCount() const

void ControlNode::halt()
{
haltChildren();
resetChildren();
}

void ControlNode::resetChildren()
{
for (auto child: children_nodes_)
{
if (child->status() == NodeStatus::RUNNING)
{
child->halt();
}
child->resetStatus();
}
}

const std::vector<TreeNode*>& ControlNode::children() const
Expand Down
4 changes: 2 additions & 2 deletions src/controls/fallback_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ NodeStatus FallbackNode::tick()
return child_status;
}
case NodeStatus::SUCCESS: {
haltChildren();
resetChildren();
current_child_idx_ = 0;
return child_status;
}
Expand All @@ -56,7 +56,7 @@ NodeStatus FallbackNode::tick()
// The entire while loop completed. This means that all the children returned FAILURE.
if (current_child_idx_ == children_count)
{
haltChildren();
resetChildren();
current_child_idx_ = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/controls/if_then_else_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ NodeStatus IfThenElseNode::tick()
}
else
{
haltChildren();
resetChildren();
child_idx_ = 0;
return status;
}
Expand Down
4 changes: 2 additions & 2 deletions src/controls/parallel_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ NodeStatus ParallelNode::tick()
if (success_childred_num == successThreshold())
{
skip_list_.clear();
haltChildren();
resetChildren();
return NodeStatus::SUCCESS;
}
}
Expand All @@ -116,7 +116,7 @@ NodeStatus ParallelNode::tick()
(failure_childred_num == failureThreshold()))
{
skip_list_.clear();
haltChildren();
resetChildren();
return NodeStatus::FAILURE;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/controls/reactive_fallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ NodeStatus ReactiveFallback::tick()
break;

case NodeStatus::SUCCESS: {
haltChildren();
resetChildren();
return NodeStatus::SUCCESS;
}

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

if (failure_count == childrenCount())
{
haltChildren();
resetChildren();
return NodeStatus::FAILURE;
}

Expand Down
4 changes: 2 additions & 2 deletions src/controls/reactive_sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ NodeStatus ReactiveSequence::tick()
}

case NodeStatus::FAILURE: {
haltChildren();
resetChildren();
return NodeStatus::FAILURE;
}
case NodeStatus::SUCCESS: {
Expand All @@ -53,7 +53,7 @@ NodeStatus ReactiveSequence::tick()

if (success_count == childrenCount())
{
haltChildren();
resetChildren();
return NodeStatus::SUCCESS;
}
return NodeStatus::RUNNING;
Expand Down
4 changes: 2 additions & 2 deletions src/controls/sequence_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ NodeStatus SequenceNode::tick()
}
case NodeStatus::FAILURE: {
// Reset on failure
haltChildren();
resetChildren();
current_child_idx_ = 0;
return child_status;
}
Expand All @@ -64,7 +64,7 @@ NodeStatus SequenceNode::tick()
// The entire while loop completed. This means that all the children returned SUCCESS.
if (current_child_idx_ == children_count)
{
haltChildren();
resetChildren();
current_child_idx_ = 0;
}
return NodeStatus::SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/controls/sequence_star_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ NodeStatus SequenceStarNode::tick()
// The entire while loop completed. This means that all the children returned SUCCESS.
if (current_child_idx_ == children_count)
{
haltChildren();
resetChildren();
current_child_idx_ = 0;
}
return NodeStatus::SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/controls/while_do_else_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ NodeStatus WhileDoElseNode::tick()
}
else
{
haltChildren();
resetChildren();
return status;
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/decorator_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void DecoratorNode::setChild(TreeNode* child)

void DecoratorNode::halt()
{
haltChild();
resetChild();
}

const TreeNode* DecoratorNode::child() const
Expand All @@ -45,6 +45,11 @@ TreeNode* DecoratorNode::child()
}

void DecoratorNode::haltChild()
{
resetChild();
}

void DecoratorNode::resetChild()
{
if (!child_node_)
{
Expand All @@ -57,6 +62,7 @@ void DecoratorNode::haltChild()
child_node_->resetStatus();
}


SimpleDecoratorNode::SimpleDecoratorNode(const std::string& name,
TickFunctor tick_functor,
const NodeConfiguration& config) :
Expand Down
1 change: 1 addition & 0 deletions src/decorators/delay_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ NodeStatus DelayNode::tick()
{
delay_started_ = false;
delay_aborted_ = false;
resetChild();
}
return child_status;
}
Expand Down
2 changes: 2 additions & 0 deletions src/decorators/inverter_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ NodeStatus InverterNode::tick()
switch (child_state)
{
case NodeStatus::SUCCESS: {
resetChild();
return NodeStatus::FAILURE;
}

case NodeStatus::FAILURE: {
resetChild();
return NodeStatus::SUCCESS;
}

Expand Down
4 changes: 2 additions & 2 deletions src/decorators/repeat_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ NodeStatus RepeatNode::tick()
{
case NodeStatus::SUCCESS: {
repeat_count_++;
haltChild();
resetChild();
}
break;

case NodeStatus::FAILURE: {
repeat_count_ = 0;
haltChild();
resetChild();
return (NodeStatus::FAILURE);
}

Expand Down
4 changes: 2 additions & 2 deletions src/decorators/retry_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ NodeStatus RetryNode::tick()
{
case NodeStatus::SUCCESS: {
try_count_ = 0;
haltChild();
resetChild();
return (NodeStatus::SUCCESS);
}

case NodeStatus::FAILURE: {
try_count_++;
haltChild();
resetChild();
}
break;

Expand Down
8 changes: 7 additions & 1 deletion src/decorators/subtree_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ BT::NodeStatus BT::SubtreeNode::tick()
{
setStatus(NodeStatus::RUNNING);
}
return child_node_->executeTick();
auto status = child_node_->executeTick();
if(status != NodeStatus::RUNNING)
{
resetChild();
}

return status;
}

//--------------------------------
Expand Down

0 comments on commit 87c3669

Please sign in to comment.