Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import rospy
00019 import tf
00020
00021 from cob_msgs.msg import EmergencyStopState
00022
00023 from simple_script_server import *
00024 sss = simple_script_server()
00025
00026 class AutoInit():
00027
00028 def __init__(self):
00029 self.components = rospy.get_param('~components', {})
00030 self.max_retries = rospy.get_param('~max_retries', 50)
00031 self.em_state = 1
00032 rospy.Subscriber("/emergency_stop_state", EmergencyStopState, self.em_cb, queue_size=1)
00033
00034
00035 for component in self.components.keys():
00036 rospy.loginfo("[auto_init]: Waiting for %s to start...", component)
00037 rospy.wait_for_service("/" + component + "/driver/init")
00038
00039
00040 while not rospy.is_shutdown():
00041 if self.em_state == 1:
00042 rospy.loginfo("[auto_init]: Waiting for emergency stop to be released...")
00043 try:
00044 rospy.sleep(1)
00045 except rospy.exceptions.ROSInterruptException as e:
00046 pass
00047 else:
00048
00049 rospy.loginfo("[auto_init]: Initializing components")
00050 for component in self.components.keys():
00051 retries = 0
00052 while not rospy.is_shutdown():
00053 if retries >= self.max_retries:
00054 rospy.logerr("[auto_init]: Could not initialize %s after %s retries", component, str(retries))
00055 break
00056 retries += 1
00057 handle = sss.init(component)
00058 if not (handle.get_error_code() == 0):
00059 rospy.logerr("[auto_init]: Could not initialize %s. Retrying...(%s of %s)", component, str(retries), str(self.max_retries))
00060 else:
00061 rospy.loginfo("[auto_init]: Component %s initialized successfully", component)
00062 break
00063 break
00064
00065 def em_cb(self, msg):
00066 self.em_state = msg.emergency_state
00067
00068 if __name__ == "__main__":
00069 rospy.init_node("auto_init")
00070 rospy.loginfo("auto init running")
00071 AI = AutoInit()
00072 rospy.loginfo("auto init finished")