ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org
Ask Your Question
2

Check if topic name already exists

asked 2013-10-27 15:37:29 -0500

BeLi gravatar image

updated 2014-01-28 17:18:22 -0500

ngrennan gravatar image

Hi there,

How can I check if a topic name already exists with Python?

I think this can be a noob question, but I have not managed to find it...

Regards.

edit retag flag offensive close merge delete

Comments

This question is with good cause, as one could avoid subscribing to topics not being out there. I ran into the same problem in roscpp and there seems to be no solution, but subscribing to the topics having in mind and checking for incoming msgs.

user23fj239 gravatar imageuser23fj239 ( 2016-02-16 07:28:27 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-10-27 16:21:16 -0500

Thomas gravatar image

updated 2013-10-28 16:51:26 -0500

AFAIK there is not. The reason is that there is nothing such as "creating" a topic. Topics are implicitly considered as "existing" as soon as one node starts publishing on it. To this extent, if you really want to see if a ""topic exists"" you should create a subscriber and wait for a message to come. This is the best approximation you can get.

Also, this is a perfectly valid behavior for two nodes to emit on the same topic (see /tf for instance).

On a more general point of view, you should not do that when designing your node, please use meaningful names for your topic instead (aka in, out, position, velocity, etc.) even if they create name clash.

Making sure that a topic name is the duty of the roslaunch XML file and of the architect (the guy who write this file). It is not your role as a node designer.

edit flag offensive delete link more

Comments

surely, you mean create a subscriber, not a publisher, right?

basheersubei gravatar imagebasheersubei ( 2013-10-28 10:17:58 -0500 )edit

Indeed, fixed! Thanks for reporting.

Thomas gravatar imageThomas ( 2013-10-28 16:51:37 -0500 )edit
1

Thaks for your reply and explanation Thomas. My intention was to check if a topic have been registered in the ROS Master, but from your explanation I gather that this is not possible, at least in the way I was trying to do it.

BeLi gravatar imageBeLi ( 2013-10-29 06:47:08 -0500 )edit

What do you mean by create a subscriber and _wait_ for a message to come? I tried creating a subscriber but it doesn't know immediately once the topic is present. I find that it takes upwards of 30 seconds to know about the topic (if the subscriber is created before the publisher).

2ROS0 gravatar image2ROS0 ( 2016-08-09 16:02:46 -0500 )edit
3

answered 2017-04-03 11:31:28 -0500

DC gravatar image

You could use rospy.get_published_topics() to get all the names of all the published topics. A simple comparison would then tell you if your particular topic is already being published.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-10-27 15:37:29 -0500

Seen: 2,510 times

Last updated: Oct 28 '13