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 ROSH library for running processes.
37
38 This library is necessary as ROSH commands, like set_master, can
39 manipulate the environment in ways that would affect subprocesses.
40 """
41
42 import os
43 from subprocess import Popen, PIPE
44
45 import roslib.rosenv
46 import roslaunch
47
48
49 -def run(config, cmd, stdout=True):
50 """
51 Run the specified command using the current ROS configuration.
52 """
53 env = os.environ.copy()
54 env[roslib.rosenv.ROS_MASTER_URI] = config.master.master_uri
55
56 if 0:
57 print "CMD", cmd
58
59
60 if stdout:
61 p = Popen(cmd, stderr=PIPE, env=env)
62 else:
63 p = Popen(cmd, stdout=PIPE, stderr=PIPE, env=env)
64
65 p.poll()
66 return p.returncode in [None, 0]
67
69 """
70 Add shared roslaunch instance to ctx if not already initialized.
71
72 @param ctx: ROSH context
73 @type ctx: Contextj
74 """
75 if not ctx._roslaunch.started:
76 ctx._roslaunch.start()
77
78
80 """
81 ROSH wrapper for processes to make them kill-able
82 """
83
85 self.roslaunch_process = roslaunch_process
86
88 self.roslaunch_process.stop()
89
90 -def launch_node(ctx, pkg, type_, args=[], remap={}, stdout=False):
91 """
92 Low-level launch() API for internal ROSH and ROSH plugin use.
93
94 @param ctx: ROSH context
95 @type ctx: Context
96 @param pkg: package name
97 @param type_: node type
98 @return: Node and Process instance
99 @rtype: (roslaunch.Node, roslaunch.Process)
100 """
101 output = 'screen' if stdout else None
102 if type(args) in (list, tuple):
103 args = ' '.join([str(x) for x in args])
104 if remap:
105 args = args + ' '.join(['%s:=%s'%(k, v) for k, v in remap.iteritems()])
106
107 return launch_roslaunch_Node(ctx, roslaunch.Node(pkg, type_, args=args, output=output, filename='<rosh>'))
108
110
111 raise NotImplemented
112
114 """
115 Launch a Node instance. This is a low-level launch() API for
116 internal ROSH and ROSH plugin use.
117
118 @param ctx: ROSH context
119 @type ctx: Context
120 @param node: node instance. The name attribute may be overwritten.
121 @type node: roslaunch.Node
122 @return: Node instance
123 @rtype: Node
124 """
125 _init_ctx(ctx)
126 p = ctx._roslaunch.launch(node)
127 return node, Process(p)
128