Ask Your Question
0

Using Rospy to check on empty topic

asked 2020-08-31 23:46:12 -0600

loguna gravatar image

Hi,

I want to code a simple publisher and subscriber. However, I realized that whenever Ros is subscribing to a topic, e.g.:

rospy.subscriber("/chatter",string,callback)

it will always wait for the topic in the callback function. In this example, lets assume there is no '/chatter' topic published and the user himself had type the wrong topic. I wish to create a some kind of warning to users that warn them regarding "chatter" has not yet been publish or empty. How can I do that?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-09-01 01:10:53 -0600

mgruhler gravatar image

There is a bit of a misunderstanding here.

it will always wait for the topic in the callback function

The code is not "waiting" in the callback function. The callback function is fired once a message is received, otherwise it will not be called at all.

Also note that you will get a warning on the terminal when you launch a node that is subscribing to a (published) topic which has another topic type. if by "user himself had typed the wrong topic" you mean this is really just a typo, the python interpreter will throw an exception, if the type does not exist

About your question:

I wish to create a some kind of warning to users that warn them regarding "chatter" has not yet been publish

see #q237789

or empty.

If by "empty" you mean that a std_msgs/String message is published to the chatter topic, you should add this check in the callback:

if len(msg.data) == 0:
    rospy.logwarn("Message empty")
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

2 followers

Stats

Asked: 2020-08-31 23:46:12 -0600

Seen: 582 times

Last updated: Sep 01 '20