Skip to content

Commit c0b4521

Browse files
updated launch to resolve absolute path of launch files
1 parent 9b6717a commit c0b4521

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

src/roswire/proxy/roscore.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
__all__ = ('ROSCore',)
33

4-
from typing import Dict, List, Optional, Union
4+
from typing import Dict, List, Mapping, Optional, Union
55
import os
66
import xmlrpc.client
77
import shlex
@@ -52,7 +52,7 @@ def __init__(self,
5252
self.__port = port
5353
self.__ip_address = ip_address
5454
self.__uri = f"http://{ip_address}:{port}"
55-
logger.debug("connecting to ROS Master: %s", self.__uri)
55+
logger.debug(f"connecting to ROS Master: {self.__uri}")
5656
self.__connection = xmlrpc.client.ServerProxy(self.__uri)
5757
time.sleep(5) # FIXME #1
5858
self.__parameters = ParameterServer(self.__connection)
@@ -95,7 +95,8 @@ def launch(self,
9595
*,
9696
package: Optional[str] = None,
9797
args: Optional[Dict[str, Union[int, str]]] = None,
98-
prefix: Optional[str] = None
98+
prefix: Optional[str] = None,
99+
launch_prefixes: Optional[Mapping[str, str]] = None
99100
) -> None:
100101
"""Provides an interface to roslaunch.
101102
@@ -110,14 +111,36 @@ def launch(self,
110111
Keyword arguments that should be supplied to roslaunch.
111112
prefix: str, optional
112113
An optional prefix to add before the roslaunch command.
114+
launch_prefixes: Mapping[str, str], optional
115+
An optional mapping from nodes, given by their names, to their
116+
individual launch prefix.
113117
"""
118+
shell = self.__shell
114119
if not args:
115120
args = {}
121+
if not launch_prefixes:
122+
launch_prefixes = {}
116123
launch_args: List[str] = [f'{arg}:={val}' for arg, val in args.items()]
117-
cmd = ['roslaunch']
124+
125+
if launch_prefixes:
126+
m = "individual launch prefixes are not yet implemented"
127+
raise NotImplementedError(m)
128+
129+
# determine the absolute path of the launch file
118130
if package:
119-
cmd += [shlex.quote(package)]
120-
cmd += [shlex.quote(filename)]
131+
filename_original = filename
132+
logger.debug(f'determing location of launch file [{filename}]'
133+
f' in package [{package}]')
134+
package_escaped = shlex.quote(package)
135+
find_package_command = f'rospack find {package_escaped}'
136+
package_path = shell.check_output(find_package_command,
137+
stderr=False)
138+
filename = os.path.join(package_path, 'launch', filename)
139+
logger.debug('determined location of launch file'
140+
f' [{filename_original}] in package [{package}]: '
141+
f'{filename}')
142+
143+
cmd = ['roslaunch', shlex.quote(filename)]
121144
cmd += launch_args
122145
if prefix:
123146
cmd = [prefix] + cmd
@@ -184,12 +207,12 @@ def playback(self,
184207
else:
185208
delete_file_after_use = True
186209
fn_ctr = self.__files.mktemp(suffix='.bag')
187-
logger.debug("copying bag from host [%s] to container [%s]",
188-
fn, fn_ctr)
210+
logger.debug(f"copying bag from host [{fn}] "
211+
f"to container [{fn_ctr}]")
189212
self.__files.copy_from_host(fn, fn_ctr)
190213
else:
191214
fn_ctr = fn
192-
logger.debug("playing back bag file: %s", fn_ctr)
215+
logger.debug(f"playing back bag file: {fn_ctr}")
193216
return BagPlayer(fn_ctr,
194217
self.__shell,
195218
self.__files,

src/roswire/roswire.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self,
4141
logger.debug("no workspace specified: using default workspace.")
4242
dir_home = os.path.expanduser("~")
4343
dir_workspace = os.path.join(dir_home, ".roswire")
44-
logger.debug("default workspace: %s", dir_workspace)
44+
logger.debug(f"default workspace: {dir_workspace}")
4545
if not os.path.exists(dir_workspace):
4646
logger.debug("initialising default workspace")
4747
os.mkdir(dir_workspace)

0 commit comments

Comments
 (0)