ros::topic::waitForMessage doesn't wait until timeout

asked 2022-07-30 07:32:56 -0600

Kevin1719 gravatar image

I want to wait for a message to be published on a topic with waitForMessage method for an amount of time. Here is my code:

ros::topic::waitForMessage<sensor_msgs::BatteryState>("battery_info", ros::Duration(10.0));

but it didn't wait for the message, but if I set the timeout to ros::Duration(1000.0), it worked, or if I remove the timeout parameter, it also worked. Did I do anything wrong?

edit retag flag offensive close merge delete



Not sure how we're supposed to debug from just one line of code. Please edit your description and include a short, complete ros node that exhibits the problem. This call is basicly doing a standard subscribe(), so all the requirements for that need to be in place.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-07-30 08:55:30 -0600 )edit

Sorry for late response. I figured out the problem, which is quite weird. If I ran the program with a specified world in Gazebo, the above code would not wait for messages, but if I ran with an empty world, it worked as expected.

Kevin1719 gravatar image Kevin1719  ( 2022-08-07 23:16:03 -0600 )edit