Robotics StackExchange | Archived questions

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

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?

Asked by Kevin1719 on 2022-07-30 07:32:56 UTC

Comments

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.

Asked by Mike Scheutzow on 2022-07-30 08:55:30 UTC

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.

Asked by Kevin1719 on 2022-08-07 23:16:03 UTC

Answers