How to echo messages published on a particular topic by a node?
Let's say that we have 2 nodes named node_a
and node_b
. Let's assume that both the nodes are publishing on the topics - topic_1
, topic_2
, topic_3
and topic_4
. Is there a way to find out what the node_a
is publishing on the topic_1
?
Asked by skpro19 on 2021-02-03 09:50:36 UTC
Answers
One idea (not tested):
1) change the name of the outputs topics if node a (for example topic_1_a instead of topic_1), or remap the names (using a launch file)
2) use the relay node (http://wiki.ros.org/topic_tools/relay) to copy the content of topic_1_a into topic_1.
This way, you have all your data from topic one in separated topics, but you also have your "normal" topic with messages from all nodes.
You might do the same for node_b and group the messages in topic_x.
Asked by felixN on 2021-02-03 12:00:00 UTC
Comments
It is not clear from your description, but I assume you are talking about a situation where multiple nodes are publishing on the same topic. If this is the case, there is no way to find who is the owner of the message, since the publishing system is "fire-and-forget". (Apparently this is not true)
I think you should change the design of your connection to avoid this situation, especially if you end up in an N-to-N (multiple nodes on both sides of a topic) situation. However, a workaround is to define an extra field on the message to add an ID to identify the source.
Asked by g.bardaro on 2021-02-03 12:21:06 UTC
Comments
If this is the case, there is no way to find who is the owner of the message
this is actually not true.
a MessageEvent can tell you which node published a message.
Whether this leads to a properly designed application is something else.
Asked by gvdhoorn on 2021-02-03 12:24:42 UTC
Comments
Are you looking for something as simple as
rostopic echo \topic_a
or something more detailed? This will only work if your topic_a is sourced of course.Asked by Akhil Kurup on 2021-02-03 10:48:10 UTC
I have edited the question. Does it make sense now?
I don't want to
echo
everything that is being published totopic_1
. I just want toecho
the messages being published bynode_a
ontopic_1
.Asked by skpro19 on 2021-02-03 11:24:56 UTC