pr2_props_rfn.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
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         # For error checking, each of these calls will return True upon success
00015         #   and False upon failure.
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         # WARNING: This is a roslaunch-caller-like abomination.
00027         #   (Plus, it's borrowed code from app_manager.)  We
00028         #   should leverage a true roslaunch API when it exists.
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                 # attempt to kill any launched resources
00042                 self.kill_launchfile()
00043             except:
00044                 pass
00045             rospy.logerr("launch failed! " + str(e))
00046             self.server.set_aborted()
00047             return False
00048         # Wait until we terminate.
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   # <node name="turtlebot_follower_rfn" pkg="turtlebot_follower_rfn" type="turtlebot_follower_rfn.py">
00079   #   <param name="launchfile"
00080   #          value="$(find turtlebot_follower_rfn)/turtlebot_follower_nodelet.launch" />
00081   # </node>


pr2_props_rfn
Author(s): Brian Thomas
autogenerated on Fri Dec 6 2013 20:35:41