Package smach_ros :: Module util

Source Code for Module smach_ros.util

 1   
 2  import roslib; roslib.load_manifest('smach_ros') 
 3  import rospy 
 4   
 5  import threading 
 6  import smach 
 7   
 8  __all__ = ['set_preempt_handler'] 
 9   
10  # Signal handler 
11 -def set_preempt_handler(sc):
12 """Sets a ROS pre-shutdown handler to preempt a given SMACH container when 13 ROS receives a shutdown request. 14 15 This can be attached to multiple containers, but only needs to be used on 16 the top-level containers. 17 18 @type sc: L{smach.Container} 19 @param sc: Container to preempt on ROS shutdown. 20 """ 21 ### Define handler 22 def handler(sc): 23 sc.request_preempt() 24 25 while sc.is_running(): 26 rospy.loginfo("Received shutdown request... sent preempt... waiting for state machine to terminate.") 27 rospy.sleep(1.0)
28 29 ### Add handler 30 rospy.core.add_client_shutdown_hook(lambda: handler(sc)) 31