Skip to content

Commit 4f30e3a

Browse files
committed
[Breaking API change] make TreeNode::setStatus() protected
Users are not supposed to set the status of a node manually from the outside. This might be a source of hard to debug errors as seen in Navigation2 of ROS2. If this change breaks your code, there is an high probability that your code was already broken.
1 parent ad78acb commit 4f30e3a

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

include/behaviortree_cpp_v3/bt_factory.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,21 @@ struct Tree
154154
return *this;
155155
}
156156

157+
void haltTree()
158+
{
159+
// the halt should propagate to all the node if all the nodes
160+
// are implemented correctly
161+
root_node->halt();
162+
root_node->setStatus(NodeStatus::IDLE);
163+
164+
//but, just in case.... this should be no-op
165+
auto visitor = [](BT::TreeNode * node) {
166+
node->halt();
167+
node->setStatus(BT::NodeStatus::IDLE);
168+
};
169+
BT::applyRecursiveVisitor(root_node, visitor);
170+
}
171+
157172
~Tree();
158173

159174
Blackboard::Ptr rootBlackboard();

include/behaviortree_cpp_v3/condition_node.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class ConditionNode : public LeafNode
2828
//Do nothing
2929
virtual void halt() override final
3030
{
31-
// just in case, but it should not be needed
3231
setStatus(NodeStatus::IDLE);
3332
}
3433

include/behaviortree_cpp_v3/tree_node.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ class TreeNode
8080

8181
NodeStatus status() const;
8282

83-
void setStatus(NodeStatus new_status);
84-
8583
/// Name of the instance, not the type
8684
const std::string& name() const;
8785

@@ -153,6 +151,9 @@ class TreeNode
153151
virtual BT::NodeStatus tick() = 0;
154152

155153
friend class BehaviorTreeFactory;
154+
friend class DecoratorNode;
155+
friend class ControlNode;
156+
friend class Tree;
156157

157158
// Only BehaviorTreeFactory should call this
158159
void setRegistrationID(StringView ID)
@@ -162,6 +163,8 @@ class TreeNode
162163

163164
void modifyPortsRemapping(const PortsRemapping& new_remapping);
164165

166+
void setStatus(NodeStatus new_status);
167+
165168
private:
166169
const std::string name_;
167170

src/action_node.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ struct CoroActionNode::Pimpl
169169
{
170170
coroutine::routine_t coro;
171171
std::atomic<bool> pending_destroy;
172-
173172
};
174173

175174

src/decorators/timeout_node.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ NodeStatus TimeoutNode::tick()
6161
if (!aborted && child()->status() == NodeStatus::RUNNING)
6262
{
6363
child_halted_ = true;
64-
child()->halt();
65-
child()->setStatus(NodeStatus::IDLE);
64+
haltChild();
6665
}
6766
});
6867
}

0 commit comments

Comments
 (0)