15 #include "nav2_behavior_tree/plugins/control/persistent_sequence.hpp"
16 #include "behaviortree_cpp/action_node.h"
17 #include "behaviortree_cpp/bt_factory.h"
19 namespace nav2_behavior_tree
22 PersistentSequenceNode::PersistentSequenceNode(
23 const std::string & name,
24 const BT::NodeConfiguration & conf)
25 : BT::ControlNode::ControlNode(name, conf) {}
27 BT::NodeStatus PersistentSequenceNode::tick()
29 const int children_count = children_nodes_.size();
31 int current_child_idx;
32 getInput(
"current_child_idx", current_child_idx);
34 setStatus(BT::NodeStatus::RUNNING);
36 while (current_child_idx < children_count) {
37 TreeNode * current_child_node = children_nodes_[current_child_idx];
38 const BT::NodeStatus child_status = current_child_node->executeTick();
40 switch (child_status) {
41 case BT::NodeStatus::RUNNING:
44 case BT::NodeStatus::FAILURE:
47 current_child_idx = 0;
48 setOutput(
"current_child_idx", 0);
51 case BT::NodeStatus::SUCCESS:
52 case BT::NodeStatus::SKIPPED:
55 setOutput(
"current_child_idx", current_child_idx);
58 case BT::NodeStatus::IDLE:
59 throw std::runtime_error(
"A child node must never return IDLE");
64 if (current_child_idx >= children_count) {
66 setOutput(
"current_child_idx", 0);
68 return BT::NodeStatus::SUCCESS;
73 BT_REGISTER_NODES(factory)
75 BT::NodeBuilder builder =
76 [](
const std::string & name,
const BT::NodeConfiguration & config)
78 return std::make_unique<nav2_behavior_tree::PersistentSequenceNode>(
83 "PersistentSequence", builder);
The PersistentSequenceNode is similar to the SequenceNode, but it stores the index of the last runnin...