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
55import os
66import xmlrpc .client
77import 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 ,
0 commit comments