Description
It's common practice to place all logic inside a ROS node, with the main method simply creating and spinning the node. However, registering BT nodes from within an rclcpp::Node child class can lead to a circular dependency:
RosNodeParams params;
params.nh = this->shared_from_this();
params.default_port_value = "btcpp_string";
factory_->registerNodeType<ReceiveString>("ReceiveString", params);
This is due to passing this->shared_from_this()
as a rclcpp node pointer, creating a situation where the main ROS node holds a reference to a BT node and vice versa, leading to a circular dependency. One potential solution is to use weak pointers for BT nodes. It worked for me in a simple example similar to subscriber_test
. Not sure if there are any obvious drawbacks of this approach. What are your thoughts on this?
Also, what's your opinion on creating and ticking BT tree inside ROS node e.g. using ROS timer? Currently, I use ROS parameters to load BT nodes via plugins, and moving this outside the node might get complicated.