How to read only once a message published in a topic? [closed]

asked 2022-07-04 20:03:15 -0500

LuisEFA1998 gravatar image

I created a ROS node that continuously publishes a geometry_msgs/Pose type message within a topic, the published information comes from a sensor, I would like to know if it is possible to read only a single topic message instead of reading all the messages that are being published to the queue.

The following image shows the information that is published within the topic. How can I get the information from a single message to store it inside a variable?

image description

If I use a subscriber node, the callback() function reads all the information that is being published on the topic and I only want to access a single message.

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by gvdhoorn
close date 2022-07-05 01:33:57.650790


You can "echo" or print a single message from a particular ROS topic using:
rostopic echo -n COUNT where COUNT equals the number of messages you want to print or see.

I figured this out using rostopic echo -h.


electrophod gravatar image electrophod  ( 2022-07-05 00:42:16 -0500 )edit

I've closed this as a duplicate, as it is a duplicate of at least #q270298, #q222029, #q292582, #q62176 and a couple more.

You might have done so already, but for future readers: please search before posting. And use Google: append to your search query. For me, subscribe only once returns many results, including the Q&As I've linked.

gvdhoorn gravatar image gvdhoorn  ( 2022-07-05 01:36:01 -0500 )edit

Additionally, @LuisEFA1998:

The following image shows the information that is published within the topic.

please do not post screenshots of terminals. This goes against the support guidelines and is also unnecessary. It's all text, so copy-paste the text into your question, then format it using the Preformatted Text button (the one with 101010 on it).

gvdhoorn gravatar image gvdhoorn  ( 2022-07-05 01:37:35 -0500 )edit