ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Naming a node while playing from rosbag [closed]

asked 2023-02-20 23:22:04 -0500

shouvik1984 gravatar image

updated 2023-02-21 13:15:11 -0500

gvdhoorn gravatar image


As a part of my application logic I have a single callback to obtain data from multiple topics from multiple nodes that are subscribed. Each topic has the same message type.

void callBackName(
const ros::MessageEvent<geometry_msgs::PoseWithCovarianceStamped>& any_node)

I am disambiguating the node name inside the callback function using.

const std::string& node_name = any_node.getPublisherName();

Sometimes we do unit test the application logic using recorded rosbags just by executing the subscriber node. However when we start playing rosbag, under the topic graph a random node name is created viz. play_<timestamp of recording> and hence the callBackName logic fails as the node name does not match the publisher node name as it would appear for a fully integrated system where the publisher nodes are also executing.

Is there a way to impart a suitable node name while playing the rosbag so that the node name disambiguation logic works as it should in a fully integrated system.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by shouvik1984
close date 2023-03-15 07:02:41.016819



This is going to be super pedantic, for which I apologise, but for anyone reading this in the future: this is exactly one of those examples which shows why anonymous publish-subscribe should not be broken or circumvented by (trying to) write special logic for nodes with particular names.

This is not a critique directed at the OP, nor at the system he's working with. There are probably valid reasons why it was constructed the way it is constructed. Just make absolutely sure, when intending to create a similar setup, you need to know the name of the publisher -- instead of something like the location where sensor data was captured (for example). Those are different things, and there are other ways to get that sort of information (TF for instance).

gvdhoorn gravatar image gvdhoorn  ( 2023-02-21 13:16:13 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2023-02-21 08:49:11 -0500

ljaniec gravatar image

Perhaps you could change the node name with this keyword?


`__name` is a special reserved keyword for "the name of the node." It

lets you remap the node name without having to know its actual name. It can only be used if the program that is being launched contains one node.

I tried to find the relevant code snippet in the rosbag repository but could not find it, unfortunately. I would also like to see the answer to this question, it is interesting and a solution would be useful.

edit flag offensive delete link more



You can specify the name of the rosbag ros node by using the option __name:=myname after the play keyword. In noetic, the rosbag play command is a python wrapper around compiled app /opt/ros/noetic/lib/rosbag/play.

A bag file does not record the publisher node name for a message, so if there was originally more than one publisher, it's not possible to recreate the original behavior using the bag file they have.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2023-02-22 07:19:03 -0500 )edit

Thank you. This appears to work. Multiple node is indeed a challenge.

shouvik1984 gravatar image shouvik1984  ( 2023-02-23 00:11:12 -0500 )edit

Question Tools



Asked: 2023-02-20 23:22:04 -0500

Seen: 89 times

Last updated: Feb 21