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 """
37 roslaunch API for clients. The lower-level implementation is in
38 rosh.impl.proc, which is the general process system of
39 rosh. rosh.impl.launch is just the roslaunch-level API for clients.
40 """
41
42 import os
43 import sys
44
45 import roslib.packages
46 import roslaunch
47
48 import rosh.impl.proc
49
51
52 def launch(launchable, type_=None, args=[], remap={}):
53 """
54 Launch things that are launchable. This includes::
55
56 launch('path/to/file.launch')
57 launch('my_pkg', 'file.launch')
58
59 launch('path/to/node')
60 launch('pkg', 'nodetype')
61 launch('pkg') # == launch('pkg', 'pkg'), e.g. 'rviz'
62
63 launch(roslaunch.Node)
64
65 @param launchable: ROS package name or Node instance
66 @type launchable: str or Node
67 @param type_: node type (executable name). If None and
68 launchable is a package name, this will default to package
69 name.
70 @type type_: str
71 @param args: node arguments
72 @type args: [str]
73 @param remap: remapping arguments
74 @type remap: dict
75
76 @return: List of nodes launched
77 @rtype: [rosh.impl.Node]
78 """
79 if type(launchable) == str:
80
81 if os.path.isfile(launchable):
82 if launchable.endswith('.launch'):
83 if type_:
84 raise ValueError("launch of launch file does not accept additional type_ arg")
85 if remap:
86 raise ValueError("launch of launch file does not accept remap arguments")
87
88 return _launch_roslaunch_file(ctx, launchable, args)
89 else:
90
91 pkg, pkg_dir = roslib.packages.get_dir_pkg(launchable)
92 if pkg == None:
93 raise ValueError("launch: cannot determine package of [%s]"%(launchable))
94 type_ = os.path.basename(launchable)
95 return _launch_node(ctx, pkg, type_, args, remap)
96 else:
97
98 try:
99 roslib.packages.get_pkg_dir(launchable)
100 except roslib.packages.InvalidROSPkgException:
101 raise ValueError("launch: [%s] does not appear to be a package or filename"%(launchable))
102
103
104 if type_ is None:
105 type_ = launchable
106
107
108 if type_.endswith('.launch'):
109 if remap:
110 raise ValueError("launch of launch file does not accept remap arguments")
111 return _launch_roslaunch_file(ctx, findros(launchable, type_), args)
112 else:
113 return _launch_node(ctx, launchable, type_, args, remap)
114
115 elif type(launchable) == roslaunch.Node:
116 if type_:
117 raise ValueError("launch of Node instance does not accept additional type_ arg")
118 return _launch_Node(ctx, launchable, args, remap)
119 elif hasattr(launchable, '_launch'):
120 return launchable._launch(*args, **remap)
121
122 return launch
123
127
129 if args:
130 if type(args) in (list, tuple):
131 args = ' '.join([str(x) for x in args])
132 n.args = args
133 if remap:
134 raise NotImplemented
135 n, p = rosh.impl.proc.launch_roslaunch_Node(ctx, n)
136 return [_node_ref(ctx, n, p)]
137
141
143 """
144 Convert to rosh.impl.Node reference and attach process for killing
145 @param node: roslaunch Node instance. 'name' attribute must be initialized
146 @type node: roslaunch.Node
147 @param process: Process instance
148 @type process: rosh.impl.proc.Process
149 """
150
151
152 ns_node = ctx.nodes[node.name]
153
154 ns_node._process = process
155 return ns_node
156
158 def rosrun(pkg, type_, args=[]):
159 n, p = rosh.impl.proc.launch(ctx, pkg, type_, args)
160 ns_node = _node_ref(ctx, n)
161
162 ns_node._process = p
163 return ns_node
164 return rosrun
165
178