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

Why does rospy::wait_for_message get stucked even though messages are being published?

asked 2019-05-21 03:38:15 -0500

kump gravatar image

updated 2019-05-21 06:09:38 -0500

I am using this method in my python script

rospy.wait_for_message("/my_topic", Bool, timeout=None)

The /my_topic messages are being published, I can see them when running rostopic echo /my_topic. But the script stays at the rospy.wait_for_message line as if it couldn't detect any messages. What could be the cause?


EDIT

$ rostopic echo -n1 /my_topic 
data: True
---
edit retag flag offensive close merge delete

Comments

wait_for_message is explicitly meant to get just one message on the topic. Does it detect at least one message? If you need to continuously receive the data on /my_topic, you need a Subscriber.

curi_ROS gravatar image curi_ROS  ( 2019-05-21 03:48:50 -0500 )edit

@curi_ROS no, it doesn't detect any message. Not even one.

kump gravatar image kump  ( 2019-05-21 04:11:16 -0500 )edit

What is the output of rostopic echo -n1 /my_topic?

gvdhoorn gravatar image gvdhoorn  ( 2019-05-21 04:12:26 -0500 )edit

@gvdhoorn It outputs the message.

kump gravatar image kump  ( 2019-05-21 04:17:59 -0500 )edit
1

I actually wanted to make sure that /my_topic is of type Bool. Because if it isn't, things won't work. I also wanted to make sure that /my_topic actually exists, and is not namespaced. Without you showing us that, we cannot help you.

gvdhoorn gravatar image gvdhoorn  ( 2019-05-21 04:45:34 -0500 )edit

@gvdhoorn ok, I didn't understand what you wanted me to do. The question is now edited with the output of this command.

kump gravatar image kump  ( 2019-05-21 06:10:41 -0500 )edit

Then I guess we'll need to see some of your code. Specifically how you initialise everything up to and including where you use wait_for_message(..).

It doesn't necessarily need to be your exact code, as long as it reproduces the problem you are experiencing.

gvdhoorn gravatar image gvdhoorn  ( 2019-05-21 06:16:05 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
5

answered 2019-06-13 09:52:25 -0500

pale gravatar image

I've experienced the exact same problem and I noticed I was using the wait_for_message() method before initializing the node using rospy.init_node().

So, the solution would be calling the init_node() method before any publishing/subscribing (which is done implicitly by the wait_for_message() method). Hope this helps!

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-05-21 03:38:15 -0500

Seen: 1,291 times

Last updated: May 21 '19