Go to the documentation of this file.00001
00002 import roslib; roslib.load_manifest('pr2_props_rfn')
00003 import rospy
00004 import roslaunch.parent
00005 import roslaunch.pmon
00006 from rfnserver import RFNServer
00007
00008 class PropsLauncher:
00009 def __init__(self, launchfile):
00010 self.launch = None
00011 self.launchfile = launchfile
00012 roslaunch.pmon._init_signal_handlers()
00013 self.server = RFNServer("high_five", lambda fsf: self.launch_launchfile())
00014
00015
00016 self.server.register_with_frame("high_fiving")
00017 self.server.register_preempt_callback(self.kill_launchfile)
00018 self.server.start()
00019
00020
00021 def launch_launchfile(self):
00022 if not self.launchfile:
00023 rospy.logerr("Param launchfile not found!")
00024 self.server.set_aborted()
00025 return False
00026
00027
00028
00029 rospy.loginfo("Lauching file: " + str(self.launchfile))
00030 rospy.loginfo("(Note: roslaunch API is unstable. Cross " +
00031 "your fingers this still works!")
00032 try:
00033 self.launch = roslaunch.parent.ROSLaunchParent(rospy.get_param("/run_id"),
00034 [self.launchfile],
00035 is_core=False,
00036 process_listeners=())
00037 self.launch._load_config()
00038 self.launch.start()
00039 except Exception as e:
00040 try:
00041
00042 self.kill_launchfile()
00043 except:
00044 pass
00045 rospy.logerr("launch failed! " + str(e))
00046 self.server.set_aborted()
00047 return False
00048
00049 self.launch.spin()
00050 self.server.set_succeeded()
00051 return True
00052
00053
00054 def kill_launchfile(self):
00055 try:
00056 if self.launch:
00057 self.launch.shutdown()
00058 finally:
00059 self.launch = None
00060 self.server.set_preempted()
00061
00062
00063
00064
00065
00066 def main():
00067 rospy.init_node('pr2_props_rfn')
00068 launchfile = rospy.get_param('pr2_props_rfn/launchfile')
00069 t = PropsLauncher(launchfile)
00070 rospy.spin()
00071
00072
00073 if __name__ == '__main__':
00074 main()
00075
00076
00077
00078
00079
00080
00081