roslaunch_caller.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2008, Willow Garage, Inc.
00006 # All rights reserved.
00007 #
00008 # Redistribution and use in source and binary forms, with or without
00009 # modification, are permitted provided that the following conditions
00010 # are met:
00011 #
00012 #  * Redistributions of source code must retain the above copyright
00013 #    notice, this list of conditions and the following disclaimer.
00014 #  * Redistributions in binary form must reproduce the above
00015 #    copyright notice, this list of conditions and the following
00016 #    disclaimer in the documentation and/or other materials provided
00017 #    with the distribution.
00018 #  * Neither the name of the Willow Garage nor the names of its
00019 #    contributors may be used to endorse or promote products derived
00020 #    from this software without specific prior written permission.
00021 #
00022 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 # POSSIBILITY OF SUCH DAMAGE.
00034 
00035 ##\brief Kevin Watts and Ken Conley
00036 
00037 import roslib
00038 roslib.load_manifest('roslaunch_caller')
00039 
00040 import roslaunch
00041 import roslaunch.core
00042 import roslaunch.parent
00043 import roslaunch.pmon
00044 import roslaunch.config
00045 
00046 import rospy
00047 
00048 
00049 
00050 # Hot patch to shut down XmlRpcNode properly, #4739
00051 ##@todo Wait until roslib is patched with ROS r11219 to remove this
00052 import roslib.xmlrpc
00053 def my_shutdown(self, reason):
00054     """
00055     Terminate i/o connections for this server.
00056     @param reason: human-readable debug string
00057     @type  reason: str
00058     """
00059     if self.server:
00060         server = self.server
00061         handler = self.handler
00062         self.handler = self.server = self.port = self.uri = None
00063         if handler:
00064             handler._shutdown(reason)
00065         if server:
00066             server.socket.close()
00067             server.server_close()
00068 
00069 ## ScriptRoslaunch is a specialization of the roslaunch parent for
00070 ## using the roslaunch API. It allows registration of a process listener with
00071 ## the launched parent and also overrides the default roslaunch config
00072 ## initialiation in order to load from strings instead of files.
00073 class ScriptRoslaunch(roslaunch.parent.ROSLaunchParent):
00074 
00075     ## @param self
00076     ## @param launch_str str: roslaunch XML config (as a string, not a
00077     ## file path)
00078     ## @param process_listener (optional): process listener to
00079     ## register with roslaunch
00080     def __init__(self, launch_str, process_listener=None):
00081         roslib.xmlrpc.XmlRpcNode.shutdown = my_shutdown
00082 
00083         self.launch_strs = [launch_str]
00084         # use run_id from parent
00085         run_id = rospy.get_param('/run_id')
00086         if process_listener:
00087             process_listeners = [process_listener]
00088         else:
00089             process_listeners = []
00090         super(ScriptRoslaunch, self).__init__(run_id, [], process_listeners=process_listeners)
00091         
00092     def _load_config(self):
00093         self.config = roslaunch.config.load_config_default([], self.port,
00094                                           roslaunch_strs=self.launch_strs)
00095     
00096 def launch_core():
00097     # Launch the core, generate the run_id
00098 
00099     # in the future this may need a rewrite as roslaunch gets the
00100     # ability to remotely launch cores, but for now this is fine
00101     config = roslaunch.ROSLaunchConfig()
00102     try:
00103         config.master.auto = config.master.AUTO_START
00104     except Exception, e:
00105         print "Failed to set the AUTO_START attribute when launching roscore. Diamondback OK"
00106 
00107     run_id = roslaunch.core.generate_run_id()
00108     core_launcher = roslaunch.ROSLaunchRunner(run_id, config)
00109     core_launcher.launch()
00110     
00111     return core_launcher
00112 


roslaunch_caller
Author(s): Kevin Watts (watts@willowgarage.com), Ken Conley (kwc@willowgarage.com)
autogenerated on Sat Dec 28 2013 17:56:09