Package roshlaunch :: Module scriptapi
[frames] | no frames]

Source Code for Module roshlaunch.scriptapi

  1  # Software License Agreement (BSD License) 
  2  # 
  3  # Copyright (c) 2008, Willow Garage, Inc. 
  4  # All rights reserved. 
  5  # 
  6  # Redistribution and use in source and binary forms, with or without 
  7  # modification, are permitted provided that the following conditions 
  8  # are met: 
  9  # 
 10  #  * Redistributions of source code must retain the above copyright 
 11  #    notice, this list of conditions and the following disclaimer. 
 12  #  * Redistributions in binary form must reproduce the above 
 13  #    copyright notice, this list of conditions and the following 
 14  #    disclaimer in the documentation and/or other materials provided 
 15  #    with the distribution. 
 16  #  * Neither the name of Willow Garage, Inc. nor the names of its 
 17  #    contributors may be used to endorse or promote products derived 
 18  #    from this software without specific prior written permission. 
 19  # 
 20  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 21  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 22  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 23  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 24  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 25  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 26  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 27  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 28  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 29  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 30  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  # POSSIBILITY OF SUCH DAMAGE. 
 32  # 
 33  # Revision $Id: scriptapi.py 9676 2010-05-11 23:23:07Z kwc $ 
 34   
 35  """ 
 36  Scripting interface for roslaunch 
 37  """ 
 38   
 39  from roslaunch.core import Node, Test, Master, RLException 
 40   
 41  import roslaunch.config 
 42  import roslaunch.parent 
 43  import roslaunch.xmlloader  
 44   
45 -class ROSLaunch(object):
46 """ 47 Scripting interface to roslaunch. 48 49 This must be called from the Python Main thread due to signal registration. 50 """ 51
52 - def __init__(self):
53 """ 54 @raise RLException: if fails to initialize 55 """ 56 import rosgraph.masterapi 57 master = rosgraph.masterapi.Master('/roslaunch_script') 58 uuid = master.getParam('/run_id') 59 self.parent = roslaunch.parent.ROSLaunchParent(uuid, [], is_core=False) 60 61 # should manage our own config separately of parent? 62 self.parent._load_config() 63 self.started = False
64
65 - def load(self, f):
66 """ 67 Load roslaunch file 68 69 @param f: filename 70 @type f: str 71 """ 72 73 # TODO: clone base config, load new config, load machine defs back to original config, launch new config 74 raise NotImplemented
75
76 - def load_str(self, s):
77 """ 78 Load roslaunch string 79 80 @param s: string representation of roslaunch config 81 @type s: str 82 """ 83 raise NotImplemented
84
85 - def launch(self, node):
86 """ 87 Launch a roslaunch node instance 88 89 @param node: roslaunch Node instance 90 @type node: roslaunch.Node 91 @return: node process 92 @rtype: roslaunch.Process 93 @raise RLException: if launch fails 94 """ 95 if not self.started: 96 raise RLException("please start ROSLaunch first") 97 elif not isinstance(node, Node): 98 raise ValueError("arg must be of type Node") 99 100 proc, success = self.parent.runner.launch_node(self.parent.config, node) 101 if not success: 102 raise RLException("failed to launch") 103 return proc
104
105 - def start(self):
106 """ 107 Start roslaunch. This will launch any pre-configured launches and spin up the process monitor thread. 108 """ 109 self.parent.start(auto_terminate=False) 110 self.started = True
111
112 - def spin(self):
113 self.parent.spin()
114
115 - def spin_once(self):
116 self.parent.spin_once()
117
118 - def stop(self):
119 self.parent.shutdown()
120