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?
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.
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.