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

Check if messages are published on a topic

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

Laurens Verhulst gravatar image

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

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
4

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

mgruhler gravatar image

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

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

2

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 image Laurens Verhulst  ( 2016-06-23 01:44:56 -0600 )edit
1

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

Laurens Verhulst gravatar image Laurens Verhulst  ( 2016-06-23 01:47:18 -0600 )edit
1

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

mgruhler gravatar image mgruhler  ( 2016-06-23 01:47:24 -0600 )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 image Martin Günther  ( 2016-06-23 02:40:01 -0600 )edit
1

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

Laurens Verhulst gravatar image Laurens Verhulst  ( 2016-06-23 03:03:56 -0600 )edit

@Laurens Verhulst May I ask how did you do that

Hunterx gravatar image Hunterx  ( 2018-07-26 03:26:10 -0600 )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 -0600 )edit
1

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

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 image mgruhler  ( 2016-06-23 01:27:47 -0600 )edit
1

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

Laurens Verhulst gravatar image Laurens Verhulst  ( 2016-06-23 01:43:41 -0600 )edit
1

see edit in my answer.

mgruhler gravatar image mgruhler  ( 2016-06-23 01:45:17 -0600 )edit

Question Tools

3 followers

Stats

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

Seen: 19,958 times

Last updated: Dec 02 '20