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

rospy.wait_for_message is unable to subscribe to a message

asked 2019-01-17 03:10:51 -0500

updated 2019-01-17 08:42:53 -0500

rospy.wait_for_message can receive one message from topic. It will create a new subscription to the topic, receive one message, then unsubscribe. But when I try to use it, the function can't work at all. For example,

roscore &
rostopic pub -r 1 /data std_msgs/Float32 2.0

the use this function to subscribe once:

import rospy
from std_msgs.msg import Float32
rospy.wait_for_message('/data', Float32)

It will be stuck here and there is no response at all. But if we subscribe directly

rostopic echo /data

It can work. What's the matter with this function? And I try to test it on different computers and ROS version, the result is the same.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-01-17 08:44:18 -0500

just add

rospy.init_node('test')

before.

edit flag offensive delete link more

Comments

jayess gravatar image jayess  ( 2019-01-17 16:44:28 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2019-01-17 03:10:51 -0500

Seen: 967 times

Last updated: Jan 17 '19