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

How do I check only one message from a topic?

asked 2022-07-13 04:35:36 -0600

adroit.levees.0r gravatar image

updated 2022-07-13 04:36:42 -0600

I can continuously print messages from a topic using ros2 topic echo <topic_name>. Instead, I want to save to file exactly one message from the topic to examine it. It doesn't matter what message I save, e.g. there are 10 messages per second and it doesn't matter which one to save. How to I do it?

edit retag flag offensive close merge delete

Comments

In my opinion, you can create a callback function that writes a topic message in a file. At the end of the callback you can create a if statement ( if file is not empty) you can shut the node down. Basic Subscriber , you can refer this link you will need to change topic name and listener_callback function.

OguzKahraman gravatar image OguzKahraman  ( 2022-07-13 09:15:02 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-07-14 08:32:57 -0600

BlakeAnderson gravatar image

updated 2022-07-14 08:36:22 -0600

In the past, I've done this using a callback function in which the subscriber unsubscribes itself at the end. So for rclpp, this would be the rclpp::Subscription::reset() method. Make sure to also set the subscriber buffer size to 1.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-07-13 04:35:36 -0600

Seen: 330 times

Last updated: Jul 14 '22