How to change ROS2 node's topic in runtime?
How to change ROS2 node's topic in runtime?
How to change ROS2 node's topic in runtime?
Do you want to change it multiple times in runtime or only at startup?
If at startup dynamically without compiling, I would recommend parameters.
If you want to change the topic, just create a new subscription/publisher and assign it to the object of the old subscription/publisher. The old one stops then because it's a shared pointer and is not used anymore and the old callback is not triggered anymore.
Example:
rclcpp::Subscription<std_msgs::msg::Bool>::SharedPtr sub_;
sub_ = this->create_subscription<std_msgs::msg::Bool>("/topic1", 1, sub_cb);
// change topic
sub_ = this->create_subscription<std_msgs::msg::Bool>("/topic2", 1, sub_cb);
Hi
Really appreciate your help, i actually want to change a node's topic couple of times during runtime (when node is already spinning), as far as i know its not possible as of now but i wanted to confirm.
Regards, Chandrashekhar
It's possible as I described. Just create a new subscription/publisher and replace the old one by it.
Yeah, actually i meant that i want the node to publish on topic1 for a while and then same node should start publishing on topic2 during runtime.
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2020-06-04 07:31:55 -0500
Seen: 387 times
Last updated: Jun 05 '20
Types of input for get_logger in ros2 RCLCPP_INFO
Cmake error when compiling ros_tutorials packages in windows 10 ROS 2 Foxy Fitzroy Patch Release 4
rclpy BufferClient strange timeout on lookup_transform
ros2 node stuck in RCLCPP_INFO when using launch files
webviz does not accept ros2 bag files
Rate and sleep function in RCLPY library for ROS2
rqt_image_view for Foxy and Galactic
I want to develop a publisher which should publish on 'topic1' and after some time the same publisher should start publishing on 'topic2' during runtime (and i want to be able to trigger this transition by some external function call, SetParameter for example).