Skip to content

Commit 5053226

Browse files
doisygGuillaume Doisy
andauthored
Use native library haltTree() (#3950)
* Use native library haltTree() * lint --------- Co-authored-by: Guillaume Doisy <guillaume@dexory.com>
1 parent be370db commit 5053226

File tree

4 files changed

+8
-19
lines changed

4 files changed

+8
-19
lines changed

‎nav2_behavior_tree/include/nav2_behavior_tree/behavior_tree_engine.hpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ class BehaviorTreeEngine
8585

8686
/**
8787
* @brief Function to explicitly reset all BT nodes to initial state
88-
* @param root_node Pointer to BT root node
88+
* @param tree Tree to halt
8989
*/
90-
void haltAllActions(BT::TreeNode * root_node);
90+
void haltAllActions(BT::Tree & tree);
9191

9292
protected:
9393
// The factory that will be used to dynamically construct the behavior tree

‎nav2_behavior_tree/include/nav2_behavior_tree/bt_action_server.hpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,11 @@ class BtActionServer
177177
/**
178178
* @brief Function to halt the current tree. It will interrupt the execution of RUNNING nodes
179179
* by calling their halt() implementation (only for Async nodes that may return RUNNING)
180+
* This should already done for all the exit states of the action but preemption
180181
*/
181182
void haltTree()
182183
{
183-
tree_.rootNode()->halt();
184+
tree_.haltTree();
184185
}
185186

186187
protected:

‎nav2_behavior_tree/include/nav2_behavior_tree/bt_action_server_impl.hpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ bool BtActionServer<ActionT>::on_cleanup()
203203
plugin_lib_names_.clear();
204204
current_bt_xml_filename_.clear();
205205
blackboard_.reset();
206-
bt_->haltAllActions(tree_.rootNode());
206+
bt_->haltAllActions(tree_);
207207
bt_.reset();
208208
return true;
209209
}
@@ -281,7 +281,7 @@ void BtActionServer<ActionT>::executeCallback()
281281

282282
// Make sure that the Bt is not in a running state from a previous execution
283283
// note: if all the ControlNodes are implemented correctly, this is not needed.
284-
bt_->haltAllActions(tree_.rootNode());
284+
bt_->haltAllActions(tree_);
285285

286286
// Give server an opportunity to populate the result message or simple give
287287
// an indication that the action is complete.

‎nav2_behavior_tree/src/behavior_tree_engine.cpp‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,10 @@ BehaviorTreeEngine::createTreeFromFile(
9090

9191
// In order to re-run a Behavior Tree, we must be able to reset all nodes to the initial state
9292
void
93-
BehaviorTreeEngine::haltAllActions(BT::TreeNode * root_node)
93+
BehaviorTreeEngine::haltAllActions(BT::Tree & tree)
9494
{
95-
if (!root_node) {
96-
return;
97-
}
98-
9995
// this halt signal should propagate through the entire tree.
100-
root_node->halt();
101-
102-
// but, just in case...
103-
auto visitor = [](BT::TreeNode * node) {
104-
if (node->status() == BT::NodeStatus::RUNNING) {
105-
node->halt();
106-
}
107-
};
108-
BT::applyRecursiveVisitor(root_node, visitor);
96+
tree.haltTree();
10997
}
11098

11199
} // namespace nav2_behavior_tree

0 commit comments

Comments
 (0)