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

How to find out the publisher node for a certain received message?

asked 2012-08-15 22:20:16 -0500

sacrif gravatar image

updated 2012-08-16 00:49:49 -0500

Hi everyone!

I am currently writing a node to capture the network traffic between single nodes.Therefore my node subscribes to all published messages and sorts them - amongst others - according to their publisher. Since it is possible that different nodes publish the same topic I would like to know if there is a way to find out the publisher-node of a certain received message in my callback function.

Regards scr

EDIT:

Thanks for the hint on MessageEvents. In the meanwhile I also found that there exist MessageEvents, which can also be passed to the subscribers callback function. In cpp it can be used as shown HERE. Thereby you can simply use event.getPublisher() to obtain the publisher of a message.

However I need the publisher of a message in rosjava. There also exists a MessageEvent (org.jboss.netty.channel.MessageEvent) for rosjava. However it does not seem to contain the desired information (message publisher). Moreover I am not sure whether it can be used for a callback function as simple as in cpp. When I create subscriber as following I receive the Exception "Exception in thread "pool-1-thread-13" java.lang.ClassCastException: org.ros.internal.message.$Proxy3 cannot be cast to org.jboss.netty.channel.MessageEvent"

Code:

        Subscriber<org.jboss.netty.channel.MessageEvent> subscriber = node.newSubscriber(topicType.getName(), topicType.getMessageType());
        subscriber.addMessageListener(new MessageListener<org.jboss.netty.channel.MessageEvent>() {
            @Override
            public void onNewMessage(org.jboss.netty.channel.MessageEvent event) {
                ...

            }
        });

Do you know how to use MessageEvents in rosjava, or is there an other way to find out a messages publisher?

EDIT2: After some more research I found this post. So it seams it is currently not possible to access a messages publisher in the subscriber callback function. Is there probably a smart workaround?

edit retag flag offensive close merge delete

Comments

1

Yes, use a callback signature that uses a [Message Event](http://www.ros.org/wiki/roscpp/Overview/Publishers%20and%20Subscribers#MessageEvent_.5BROS_1.1.2B-.5D).

dornhege gravatar image dornhege  ( 2012-08-15 23:28:25 -0500 )edit
1

Well, with java you'd have to look in the respective client API docs if something like that is supported. It looks like the MessageEvent you found is something totally else and unrelated to ROS.

dornhege gravatar image dornhege  ( 2012-08-16 00:42:10 -0500 )edit

Hi, thx for the reply. I also found an other post which suggests my request is currently not provided (see EDIT2). The MessageEvent is at least used in the SubscriberHandshakeHandler and Subscriber class of rosjava. Is there probably a smart workaround to simply retrieve the message publisher?

sacrif gravatar image sacrif  ( 2012-08-16 00:52:36 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2012-08-16 04:38:58 -0500

joq gravatar image

updated 2012-08-16 04:41:32 -0500

Why do you need that information?

The usual ROS practice is to distinguish topics, but decouple subscribers from worrying about which node published each message.

To work around that: add a source field to your message (or wrap some standard message in a custom message containing one), and define constants for the message sources you wish to distinguish. Then clients can tell the source without needing to worry about other nodes coming, going and restarting.

I did something similar in this custom message.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-08-15 22:20:16 -0500

Seen: 4,903 times

Last updated: Aug 16 '12