0
$\begingroup$

Rosanswers logo

Greetings

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.


Originally posted by shouvik1984 on ROS Answers with karma: 28 on 2023-02-21

Post score: 1


Original comments

Comment by gvdhoorn on 2023-02-21:
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).

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Perhaps you could change the node name with this keyword?

__name

`__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.


Originally posted by ljaniec with karma: 3064 on 2023-02-21

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Mike Scheutzow on 2023-02-22:
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.

Comment by shouvik1984 on 2023-02-23:
Thank you. This appears to work. Multiple node is indeed a challenge.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.