Robotics StackExchange | Archived questions

How do I check only one message from a topic?

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?

Asked by adroit.levees.0r on 2022-07-13 04:35:36 UTC

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.

Asked by OguzKahraman on 2022-07-13 09:15:02 UTC

Answers

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.

Asked by BlakeAnderson on 2022-07-14 08:32:57 UTC

Comments