4 roslib.load_manifest(
'openrtm_tools')
12 from xml.dom.minidom
import parse
15 from rtshell
import rtcon
16 from rtshell
import path
17 from rtshell
import state_control_base
18 from rtshell
import rts_exceptions
21 if tree.has_path(path)
and tree.is_component(path):
22 node = tree.get_node(path)
23 return node.plain_state_string
25 tree._root._remove_all_children()
26 tree.load_servers_from_env()
31 path = rtctree.path.parse_path(cmd_path)[0]
35 print >>sys.stderr,
"\033[33m[rtmlaunch] Wait for ",cmd_path,
" ",count,
"/30\033[0m" 41 raise rts_exceptions.NoSuchObjectError(cmd_path)
45 src_path, src_port = rtctree.path.parse_path(src_path)
46 dest_path, dest_port = rtctree.path.parse_path(dest_path)
47 src_node = tree.get_node(src_path)
48 dest_node = tree.get_node(dest_path)
49 port = src_node.get_port_by_name(src_port)
50 for conn
in port.connections:
51 for name, p
in conn.ports:
52 tmp_dest_path, tmp_dest_port = rtctree.path.parse_path(name)
53 if dest_path[-1] == tmp_dest_path[-1]
and dest_port == tmp_dest_port:
60 if len(input_path.split(
"$(arg")) > 1:
61 arg_str = input_path.split(
"$(arg")[1].split(
")")[0]
62 env_str = os.getenv(arg_str.replace(
" ",
""))
65 ret_str = re.sub(
"\$\(arg"+arg_str+
"\)",env_str,input_path)
73 if tag.attributes.get(
u'if'):
74 val = tag.attributes.get(
u'if').value
75 arg = val.split(
" ")[1].strip(
")")
77 if tag.attributes.get(
u'unless'):
78 val = tag.attributes.get(
u'unless').value
79 arg = val.split(
" ")[1].strip(
")")
84 source_path = nameserver+
"/"+tag.attributes.get(
"from").value
85 dest_path = nameserver+
"/"+tag.attributes.get(
"to").value
89 source_full_path = path.cmd_path_to_full_path(source_path)
90 dest_full_path = path.cmd_path_to_full_path(dest_path)
91 if tag.attributes.get(
"subscription_type") !=
None:
92 sub_type = tag.attributes.get(
"subscription_type").value
94 if not sub_type
in [
'flush',
'new',
'periodic']:
95 print >>sys.stderr, sub_type+
' is not a subscription type' 108 print >>sys.stderr,
'\033[31m[rtmlaunch] [ERROR] Could not Connect (', source_full_path,
',', dest_full_path,
'): ', e,
'\033[0m' 112 sub_type = str(sub_type)
113 props = {
'dataport.subscription_type': sub_type}
114 if tag.attributes.get(
"push_policy") !=
None:
118 if sub_type ==
'new':
119 props[
'dataport.publisher.push_policy'] = push_policy
120 elif sub_type ==
'periodic':
121 props[
'dataport.publisher.push_policy'] = push_policy
122 if tag.attributes.get(
"push_rate") !=
None:
125 props[
'dataport.push_rate'] = str(
'50.0')
126 if tag.attributes.get(
"buffer_length") !=
None:
128 options = optparse.Values({
'verbose':
False,
'id':
'',
'name':
None,
'properties': props})
129 print >>sys.stderr,
"[rtmlaunch] Connected from",source_path
130 print >>sys.stderr,
"[rtmlaunch] to",dest_path
131 print >>sys.stderr,
"[rtmlaunch] with",options
133 rtcon.connect_ports(source_path, source_full_path, dest_path, dest_full_path, options, tree=tree)
134 except Exception, e_1_1_0:
136 rtcon.connect_ports([(source_path,source_full_path), (dest_path, dest_full_path)], options, tree=tree)
137 except Exception, e_1_0_0:
138 print >>sys.stderr,
'\033[31m[rtmlaunch] {0} did not work on both OpenRTM 1.0.0 and 1.1.0'.format(os.path.basename(sys.argv[1])),
'\033[0m' 139 print >>sys.stderr,
'\033[31m[rtmlaunch] OpenRTM 1.0.0 {0}'.format(e_1_0_0),
'\033[0m' 140 print >>sys.stderr,
'\033[31m[rtmlaunch] OpenRTM 1.1.0 {0}'.format(e_1_1_0),
'\033[0m' 141 print >>sys.stderr,
'\033[31m[rtmlaunch] This is very weird situation, Please check your network\033[0m' 142 print >>sys.stderr,
'\033[31m[rtmlaunch] configuration with `ifconfig` on both robot and client side. \033[0m' 143 print >>sys.stderr,
'\033[31m[rtmlaunch] Having multiple network interface sometimes causes problem, \033[0m' 144 print >>sys.stderr,
'\033[31m[rtmlaunch] please see FAQ site http://www.openrtm.org/OpenRTM-aist/html/FAQ2FE38388E383A9E38396E383ABE382B7E383A5E383BCE38386E382A3E383B3E382B0.html#f2bc375d\033[0m' 145 print >>sys.stderr,
'\033[31m[rtmlaunch] Issue related to this https://github.com/start-jsk/rtmros_hironx/issues/33\033[0m' 146 print >>sys.stderr,
'\033[31m[rtmlaunch] ~/.ros/log may contains usefully informations\033[0m' 148 print >>sys.stderr,
'\033[31m[rtmlaunch] {0}: {1}'.format(os.path.basename(sys.argv[1]), e),
'\033[0m' 152 def activate_action(object, ec_index):
153 object.activate_in_ec(ec_index)
158 if tag.attributes.get(
u'if'):
159 val = tag.attributes.get(
u'if').value
160 arg = val.split(
" ")[1].strip(
")")
162 if tag.attributes.get(
u'unless'):
163 val = tag.attributes.get(
u'unless').value
164 arg = val.split(
" ")[1].strip(
")")
169 cmd_path = nameserver+
"/"+tag.attributes.get(
"component").value
170 full_path = path.cmd_path_to_full_path(cmd_path)
175 if state ==
'Active':
178 print >>sys.stderr,
"[rtmlaunch] Activate <-",state,full_path
180 print >>sys.stderr,
'\033[31m[rtmlaunch] Could not Activate (', cmd_path,
') : ', e,
'\033[0m' 183 options = optparse.Values({
"ec_index": 0,
'verbose':
False})
185 state_control_base.alter_component_state(activate_action, cmd_path, full_path, options, tree=tree)
187 state_control_base.alter_component_states(activate_action, [(cmd_path, full_path)], options, tree=tree)
189 print >>sys.stderr,
'[rtmlaunch] {0}: {1}'.format(os.path.basename(sys.argv[0]), e)
194 usage =
'''Usage: %prog [launchfile]''' 195 if len(sys.argv) <= 1:
196 print >>sys.stderr, usage
198 fullpathname = sys.argv[1]
199 print >>sys.stderr,
"[rtmlaunch] starting... ",fullpathname
201 parser = parse(fullpathname)
202 nodes = parser.getElementsByTagName(
"launch")[0].childNodes
205 if node.nodeName ==
u'group':
206 if node.attributes.get(
u'if'):
207 val = node.getAttributeNode(
u'if').value
208 arg = val.split(
" ")[1].strip(
")")
210 remove_nodes.append(node)
211 if node.attributes.get(
u'unless'):
212 val = node.getAttributeNode(
u'unless').value
213 arg = val.split(
" ")[1].strip(
")")
215 remove_nodes.append(node)
217 for remove_node
in remove_nodes:
218 nodes.remove(remove_node)
223 if os.getenv(
"RTCTREE_NAMESERVERS") ==
None:
224 print >>sys.stderr,
"[rtmlaunch] RTCTREE_NAMESERVERS is not set, use localhost:15005" 225 nameserver =
"localhost:15005" 226 os.environ[
"RTCTREE_NAMESERVERS"] = nameserver
228 nameserver = os.getenv(
"RTCTREE_NAMESERVERS")
230 print >>sys.stderr,
"\033[32m[rtmlaunch] RTCTREE_NAMESERVERS", nameserver, os.getenv(
"RTCTREE_NAMESERVERS"),
"\033[0m" 231 print >>sys.stderr,
"\033[32m[rtmlaunch] SIMULATOR_NAME", os.getenv(
"SIMULATOR_NAME",
"Simulator"),
"\033[0m" 234 tree = rtctree.tree.RTCTree()
236 print >>sys.stderr,
"\033[31m[rtmlaunch] Could not start rtmlaunch.py, Caught exception (", e,
")\033[0m" 239 hostname = nameserver.split(
':')[0]
240 ip_address = socket.gethostbyname(hostname)
242 print >>sys.stderr,
"\033[31m[rtmlaunch] .. Could not find IP address of ", hostname,
", Caught exception (", e,
")\033[0m" 243 print >>sys.stderr,
"\033[31m[rtmlaunch] .. Please check /etc/hosts or DNS setup\033[0m" 246 print >>sys.stderr,
"\033[31m[rtmlaunch] .. Could not connect to NameServer at ", nameserver,
", Caught exception (", e,
")\033[0m" 247 print >>sys.stderr,
"\033[31m[rtmlaunch] .. Please make sure that you have NameServer running at %s/`\033[0m"%(nameserver)
248 print >>sys.stderr,
"\033[31m[rtmlaunch] .. You can check with `rtls %s/`\033[0m"%(nameserver)
251 print >>sys.stderr,
"[rtmlaunch] check connection/activation" 252 rtconnect(nameserver, parser.getElementsByTagName(
"rtconnect"), tree)
253 rtactivate(nameserver, parser.getElementsByTagName(
"rtactivate"), tree)
255 tree.add_name_server(nameserver, [])
256 if os.getenv(
"RTC_CONNECTION_CHECK_ONCE")
and os.getenv(
"RTC_CONNECTION_CHECK_ONCE").lower() ==
"true":
257 print >>sys.stderr,
"[rtmlaunch] break from rtmlaunch main loop." 258 print >>sys.stderr,
"[rtmlaunch] If you check the rtc connection in the while loop, real-time loop becomes slow." 263 return True if 'true' in a.split(
"=")[1]
else False