Why isn't rospy.Rate.sleep() terminating?
Hi, I have written a python script which takes two tf frames and writes the transform between them to a file. The abbreviated code of the script looks like this:
listener = tf.TransformListener()
# waiting for first transform between origin and pose
listener.waitForTransform(origin, pose, rospy.Time(), rospy.Duration(5.0))
rate = rospy.Rate(10)
while not rospy.is_shutdown():
try:
now = rospy.Time.now()
listener.waitForTransform(origin, pose, now, rospy.Duration(1.0))
(trans, rot) = listener.lookupTransform(origin, pose, now)
... write trans and rot to the file ...
# this exception is usually thrown when waitForTransform timed out
except tf.Exception as e:
break # get out of the loop
rate.sleep()
... some last commands before the script terminates ...
Usually this script should terminate when no more tf frames are published because I leave the loop when waitForTransform(...)
throws an exception.
When I run this code and start playing a bagfile (use_sim_time true
and --clock
) the script does not terminate because it gets stuck at rate.sleep()
when rosbag play
is finished. Any ideas why it behaves this way?