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

Source Code for Module roslaunch.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$ 
 34   
 35  """ 
 36  Scripting interface for roslaunch 
 37  """ 
 38   
 39  from roslaunch.core import Node, Master, RLException 
 40   
 41  import roslaunch.config 
 42  import roslaunch.parent 
 43  import roslaunch.xmlloader  
 44   
45 -class ROSLaunch(object):
46 """ 47 ROSLaunchParent represents the main 'parent' roslaunch process. It 48 is responsible for loading the launch files, assigning machines, 49 and then starting up any remote processes. The __main__ method 50 delegates most of runtime to ROSLaunchParent. 51 52 This must be called from the Python Main thread due to signal registration. 53 """ 54
55 - def __init__(self):
56 """ 57 @raise RLException: if fails to initialize 58 """ 59 import rosgraph.masterapi 60 master = rosgraph.masterapi.Master('/roslaunch_script') 61 uuid = master.getParam('/run_id') 62 self.parent = roslaunch.parent.ROSLaunchParent(uuid, [], is_core=False) 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 raise NotImplemented
73
74 - def load_str(self, s):
75 """ 76 Load roslaunch string 77 78 @param s: string representation of roslaunch config 79 @type s: str 80 """ 81 raise NotImplemented
82
83 - def launch(self, node):
84 """ 85 Launch a roslaunch node instance 86 87 @param node: roslaunch Node instance 88 @type node: roslaunch.Node 89 @return: node process 90 @rtype: roslaunch.Process 91 @raise RLException: if launch fails 92 """ 93 if not self.started: 94 raise RLException("please start ROSLaunch first") 95 elif not isinstance(node, Node): 96 raise ValueError("arg must be of type Node") 97 98 proc, success = self.parent.runner.launch_node(node) 99 if not success: 100 raise RLException("failed to launch %s/%s"%(node.package, node.type)) 101 return proc
102
103 - def start(self):
104 """ 105 Start roslaunch. This will launch any pre-configured launches and spin up the process monitor thread. 106 """ 107 self.parent.start(auto_terminate=False) 108 self.started = True
109
110 - def spin(self):
111 self.parent.spin()
112
113 - def spin_once(self):
114 self.parent.spin_once()
115
116 - def stop(self):
117 self.parent.shutdown()
118