roslaunch: prototyping scripting-friendly API
This commit is contained in:
parent
d1ae95a084
commit
0d0ee386f3
|
@ -44,6 +44,9 @@ from roslaunch.config import ROSLaunchConfig
|
|||
from roslaunch.launch import ROSLaunchRunner
|
||||
from roslaunch.xmlloader import XmlLoader, XmlParseException
|
||||
|
||||
# script api
|
||||
from roslaunch.scriptapi import ROSLaunch
|
||||
|
||||
NAME = 'roslaunch'
|
||||
|
||||
def configure_logging(uuid):
|
||||
|
|
|
@ -249,7 +249,7 @@ class ROSLaunchRunner(object):
|
|||
local_nodes = [n for n in config.nodes if is_machine_local(n.machine)]
|
||||
|
||||
for node in local_nodes:
|
||||
name, success = self._launch_node(node)
|
||||
name, success = self.launch_node(node)
|
||||
if success:
|
||||
succeeded.append(name)
|
||||
else:
|
||||
|
@ -448,20 +448,28 @@ Please use ROS_IP to set the correct IP address to use."""%(reverse_ip, hostname
|
|||
|
||||
for node in tolaunch:
|
||||
node_name = roslib.names.ns_join(node.namespace, node.name)
|
||||
name, success = self._launch_node(node, core=True)
|
||||
name, success = self.launch_node(node, core=True)
|
||||
if success:
|
||||
print "started core service [%s]"%node_name
|
||||
else:
|
||||
raise RLException("failed to start core service [%s]"%node_name)
|
||||
|
||||
def _launch_node(self, node, core=False):
|
||||
def launch_node(self, node, core=False):
|
||||
"""
|
||||
Launch a single node locally. Remote launching is handled separately by the remote module.
|
||||
|
||||
@param node Node: node to launch
|
||||
@param core bool: if True, core node
|
||||
@return str, bool: node process name, successful launch
|
||||
"""
|
||||
self.logger.info("... preparing to launch node of type [%s/%s]", node.package, node.type)
|
||||
|
||||
# TODO: should this always override, per spec?. I added this
|
||||
# so that this api can be called w/o having to go through an
|
||||
# extra assign machines step.
|
||||
if node.machine is None:
|
||||
node.machine = self.config.machines['']
|
||||
|
||||
master = self.config.master
|
||||
import roslaunch.node_args
|
||||
try:
|
||||
|
@ -591,8 +599,6 @@ Please use ROS_IP to set the correct IP address to use."""%(reverse_ip, hostname
|
|||
try:
|
||||
self._setup()
|
||||
succeeded, failed = self._launch_nodes()
|
||||
# inform process monitor that we are done with process registration
|
||||
self.pm.registrations_complete()
|
||||
return succeeded, failed
|
||||
except KeyboardInterrupt:
|
||||
self.stop()
|
||||
|
@ -606,7 +612,7 @@ Please use ROS_IP to set the correct IP address to use."""%(reverse_ip, hostname
|
|||
@raise RLTestTimeoutException: if test fails to launch or test times out
|
||||
"""
|
||||
self.logger.info("... preparing to run test [%s] of type [%s/%s]", test.test_name, test.package, test.type)
|
||||
name, success = self._launch_node(test)
|
||||
name, success = self.launch_node(test)
|
||||
if not success:
|
||||
raise RLException("test [%s] failed to launch"%test.test_name)
|
||||
|
||||
|
|
|
@ -209,9 +209,16 @@ class ROSLaunchParent(object):
|
|||
self.pm.shutdown()
|
||||
self.pm.join()
|
||||
|
||||
def start(self):
|
||||
def start(self, auto_terminate=True):
|
||||
"""
|
||||
Run the parent roslaunch
|
||||
Run the parent roslaunch.
|
||||
|
||||
@param auto_terminate: stop process monitor once there are no
|
||||
more processes to monitor (default True). This defaults to
|
||||
True, which is the command-line behavior of roslaunch. Scripts
|
||||
may wish to set this to False if they wish to keep the
|
||||
roslauch infrastructure up regardless of processes being
|
||||
monitored.
|
||||
"""
|
||||
self.logger.info("starting roslaunch parent run")
|
||||
|
||||
|
@ -224,6 +231,11 @@ class ROSLaunchParent(object):
|
|||
|
||||
# Start the launch
|
||||
self.runner.launch()
|
||||
|
||||
# inform process monitor that we are done with process registration
|
||||
if auto_terminate:
|
||||
self.pm.registrations_complete()
|
||||
|
||||
self.logger.info("... roslaunch parent running, waiting for process exit")
|
||||
if self.process_listeners:
|
||||
for l in self.process_listeners:
|
||||
|
|
|
@ -281,7 +281,7 @@ class ProcessMonitor(Thread):
|
|||
self.plock = RLock()
|
||||
self.is_shutdown = False
|
||||
self.done = False
|
||||
#self.setDaemon(True)
|
||||
self.setDaemon(True)
|
||||
self.reacquire_signals = set()
|
||||
self.listeners = []
|
||||
self.dead_list = []
|
||||
|
|
Loading…
Reference in New Issue