Ask Your Question
1

Check if messages are published on a topic

asked 2016-06-22 10:14:04 -0500

Laurens Verhulst gravatar image

updated 2016-06-22 10:14:56 -0500

Hello,

I would like to check in my c++ code, if a message has been pusblished onto a certain topic. Is it possible to do this with basic ROS functions? If not, what would you advise to do? Thanks.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
3

answered 2016-06-22 10:19:31 -0500

mgruhler gravatar image

updated 2016-06-23 01:45:37 -0500

You could subscribe to the topic ( http://wiki.ros.org/ROS/Tutorials/Wri... ).


EDIT

If you subscribe to the topic, the respective callback will be called every time a message is sent on this topic. If not, it will not be called. Then you can do what you want with the respective result.

edit flag offensive delete link more

Comments

1

I would like to check if messages are published at all, I don't need to know the message. It is a topic from an actionserver, but I need to check without writing a client/

Laurens Verhulst gravatar imageLaurens Verhulst ( 2016-06-23 01:44:56 -0500 )edit
1

Right... of course, I will give this a shot and report back.

Laurens Verhulst gravatar imageLaurens Verhulst ( 2016-06-23 01:47:18 -0500 )edit
1

You will receive the messages content, but just ignore that. I don't think that there is another way...

mgruhler gravatar imagemgruhler ( 2016-06-23 01:47:24 -0500 )edit
1

mig is right, there is no other way. From the command line, you can call rostopic hz <topic name>, but that command is also implemented by subscribing to the topic and throwing away the message contents.

Martin Günther gravatar imageMartin Günther ( 2016-06-23 02:40:01 -0500 )edit
1

Yes is it working as I want it to, thanks!

Laurens Verhulst gravatar imageLaurens Verhulst ( 2016-06-23 03:03:56 -0500 )edit

@Laurens Verhulst May I ask how did you do that

Hunterx gravatar imageHunterx ( 2018-07-26 03:26:10 -0500 )edit

just write a subscriber (like in the tutorial) that hooks on the topic you are interested in. Then, once the callback gets called just store the time (inside the callback -> ros::Time callback_time = ros::Time::now();). In the main program check if the time has changed.

-LD- gravatar image-LD- ( 2018-10-10 09:53:17 -0500 )edit
1

answered 2016-06-22 10:39:23 -0500

You can open a terminal window while the node is running and enter the command rostopic echo <topic name>. If data is being published to the topic it will now show up in the terminal window.

Here is a list of the rostopic commands for future reference.

edit flag offensive delete link more

Comments

1

He asked how to check from C++ code. Other than that, you are right.

mgruhler gravatar imagemgruhler ( 2016-06-23 01:27:47 -0500 )edit
1

I would like to check in C++ code indeed. Additionally I want check whether messages are published at all.

Laurens Verhulst gravatar imageLaurens Verhulst ( 2016-06-23 01:43:41 -0500 )edit
1

see edit in my answer.

mgruhler gravatar imagemgruhler ( 2016-06-23 01:45:17 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2016-06-22 10:14:04 -0500

Seen: 8,605 times

Last updated: Jun 23 '16