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

Revision history [back]

@dornhege's answer is correct. However, if all you want to do is execute some last commands when the node is killed (e.g., by pressing Ctrl-C), I think it's better to leave your code as it is and do something like this instead:

try:
    # ... your code
except rospy.ROSInterruptException:
    # ... some last commands before the node terminates

This feels cleaner than relying on a TF exception to tell you when "rosbag play has finished". (For instance, you'll also get TF exceptions before the transform you're looking for is published, not just after it has stopped publishing.)

Also, it's cleaner than relying on some relationship between ROS time and wall time. (You'll get into trouble when you pause your bag otherwise.)

If you don't like having to explicitly kill the node yourself, but rather have it exit when the bag ends, it's better to use the rosbag API explicitly (since you're already implementing some special behaviour for bags anyway).