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

How to get publisher info from a message?

asked 2012-12-16 21:31:57 -0600

HQ gravatar image

Can anyone tell me if it's possible to get publisher information in the callback of a particular message?

For the system I'm trying to setup, I've implemented a node that publishes odometry messages (type: nav_msgs/Odometry) and am using a launch file to start multiple instances of this node, under different name spaces. Another node type (call it the coordinator node) will listen for the odometry messages from the multiple publishers. The point of the coordinator node is that it will coordinate the movement of multiple robots based on their reported locations. I'm new to ROS, so I've started by implementing my nodes using the basic templates shown in the tutorials, but I'm now realizing that the example callback method doesn't allow for identifying which particular node broadcasted a given message.

For now, I'm programming in Java and using the client_rosjava_jni library. I was hoping there would be another callback class that would include the publisher info, along with the published message, but I'm not seeing that option, at least in the JNI wrappers. I can imagine getting around this by making my first node type publish a custom message type that includes the pedigree information along with the basic odometry message type, but it seems like this should already be available in the core system. Does anyone know if that's true? Am I not seeing this option because I'm using the JNI wrappers?

Thanks in advance for any help-suggestions.

Hung

edit retag flag offensive close merge delete

Comments

Thanks for the two suggestions, tfoote. I haven't had any success getting the remapping feature working, so that may be another short-coming of the Java JNI wrappers I'm using. Been thinking about switching to the full Java core implementation and it looks like it's time. Appreciate your help with both of my recent questions. :)

HQ gravatar image HQ  ( 2012-12-17 08:46:01 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
4

answered 2012-12-16 22:06:35 -0600

tfoote gravatar image

The information is embedded in the header information and can be found through the C++ and python implementations. The Java implementation may or may not provide a way to get to the metadata.

Overall this breaks the anonymous publish subscribe abstraction which is core to ROS's design. A much cleaner solution is for you to remap your different robots onto different topics so that you know that everything coming in on a specific topic has the same semantic information, and you can provide specific or parameterized callbacks for each source.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-12-16 21:31:57 -0600

Seen: 37,368 times

Last updated: Dec 16 '12