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

Revision history [back]

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")