1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 """
36 Uncategorized utility routines for roslaunch.
37
38 This API should not be considered stable.
39 """
40
41 import os
42 import time
43
44 from roslib.names import SEP
45
46 import roslaunch.core
47 try:
48 from rosmaster import DEFAULT_MASTER_PORT
49 except:
50
51 DEFAULT_MASTER_PORT = 11311
52
54 """
55 Check size of log directory. If high, print warning to user
56 """
57 try:
58 import rosclean
59 import roslib.rosenv
60 d = roslib.rosenv.get_log_dir()
61 roslaunch.core.printlog("Checking log directory for disk usage. This may take awhile.\nPress Ctrl-C to interrupt")
62 disk_usage = rosclean.get_disk_usage(d)
63
64 if disk_usage > 1073741824:
65 roslaunch.core.printerrlog("WARNING: disk usage in log directory [%s] is over 1GB.\nIt's recommended that you use the 'rosclean' command."%d)
66 else:
67 roslaunch.core.printlog("Done checking log file disk usage. Usage is <1GB.")
68 except:
69 pass
70
72 """
73 Resolve command-line args to roslaunch filenames.
74 @return: resolved filenames
75 @rtype: [str]
76 """
77 import roslib.packages
78 import roslib.scriptutil
79
80
81 args = roslib.scriptutil.myargv(args)
82
83
84
85
86 if not args:
87 return args
88 resolved_args = None
89 top = args[0]
90 if os.path.isfile(top):
91 resolved_args = [top] + args[1:]
92 elif len(args) == 1:
93 raise roslaunch.core.RLException("[%s] does not exist. please specify a package and launch file"%(top))
94 else:
95 try:
96 resolved = roslib.packages.find_resource(top, args[1])
97 if len(resolved) == 1:
98 resolved = resolved[0]
99 elif len(resolved) > 1:
100 raise roslaunch.core.RLException("multiple files named [%s] in package [%s].\nPlease specify full path instead"%(args[1], top))
101 except roslib.packages.InvalidROSPkgException, e:
102 raise roslaunch.core.RLException("[%s] is not a package or launch file name"%top)
103 if not resolved:
104 raise roslaunch.core.RLException("cannot locate [%s] in package [%s]"%(args[1], top))
105 else:
106 resolved_args = [resolved] + args[2:]
107 return resolved_args
108
110 """
111 Block until ROS Master is online
112
113 @raise RuntimeError: if unexpected error occurs
114 """
115 m = roslaunch.core.Master()
116 is_running = m.is_running()
117 if not is_running:
118 roslaunch.core.printlog("roscore/master is not yet running, will wait for it to start")
119 while not is_running:
120 time.sleep(0.1)
121 is_running = m.is_running()
122 if is_running:
123 roslaunch.core.printlog("master has started, initiating launch")
124 else:
125 raise RuntimeError("unknown error waiting for master to start")
126
127 _terminal_name = None
128
130 import platform
131 if platform.system() in ['FreeBSD', 'Linux', 'Darwin', 'Unix']:
132 try:
133 print '\033]2;%s\007'%(s)
134 except:
135 pass
136
143
145 """
146 use echo (where available) to change the name of the terminal window
147 """
148 global _terminal_name
149 _terminal_name = 'roscore' if is_core else ','.join(args)
150 _set_terminal(_terminal_name)
151
153 """
154 @param options_runid: run_id value from command-line or None
155 @type options_runid: str
156 @param options_wait_for_master: the wait_for_master command
157 option. If this is True, it means that we must retrieve the
158 value from the parameter server and need to avoid any race
159 conditions with the roscore being initialized.
160 @type options_wait_for_master: bool
161 """
162 import roslib.scriptutil
163
164
165
166
167
168 if options_runid:
169 return options_runid
170
171
172
173
174 param_server = roslib.scriptutil.get_param_server()
175 val = None
176 while val is None:
177 try:
178 code, msg, val = param_server.getParam('/roslaunch', '/run_id')
179 if code == 1:
180 return val
181 else:
182 val = None
183 raise RuntimeError("unknown error communicating with Parameter Server: %s"%msg)
184 except:
185 if not options_wait_for_master:
186 val = roslaunch.core.generate_run_id()
187 return val
188
190 """
191 Check roslaunch file for errors, returning error message if check fails. This routine
192 is mainly to support rostest's roslaunch_check.
193
194 @param f: roslaunch file name
195 @type f: str
196 @return: error message or None
197 @rtype: str
198 """
199 try:
200 import roslaunch.config
201 config = roslaunch.config.load_config_default([f], DEFAULT_MASTER_PORT, verbose=False)
202 except roslaunch.RLException, e:
203 return str(e)
204
205 errors = []
206
207 import roslaunch.depends
208 base_pkg, file_deps, missing = roslaunch.depends.roslaunch_deps([f])
209 for pkg, miss in missing.iteritems():
210 if miss:
211 errors.append("Missing manifest dependencies: %s/manifest.xml: %s"%(pkg, ', '.join(miss)))
212
213
214 nodes = []
215 for filename, rldeps in file_deps.iteritems():
216 nodes.extend(rldeps.nodes)
217
218
219 import roslib.packages
220 for pkg, node_type in nodes:
221 try:
222 roslib.packages.get_pkg_dir(pkg, required=True)
223 except:
224 errors.append("cannot find package [%s] for node [%s]"%(pkg, node_type))
225
226
227 for pkg, node_type in nodes:
228 try:
229 if not roslib.packages.find_node(pkg, node_type):
230 errors.append("cannot find node [%s] in package [%s]"%(node_type, pkg))
231 except Exception, e:
232 errors.append("unable to find node [%s/%s]: %s"%(pkg, node_type, str(e)))
233
234
235 for err in config.config_errors:
236 errors.append('ROSLaunch config error: %s' % err)
237
238 if errors:
239 return '\n'.join(errors)
240
241
243 if name is None:
244 raise ValueError('name')
245 if not isinstance(name, basestring):
246 raise TypeError('name')
247 if not name:
248 return [SEP]
249
250 splits = [x for x in name.split(SEP) if x]
251 return ['/'] + ['/'+SEP.join(splits[:i]) for i in xrange(1, len(splits))]
252