43 """Create file with interface init code.
48 filename of XML config file
50 filename of created interface file (Default value = "./robot_interface.py")
59 file_template[
"comment_file"] =
"\"\"\" Generated file for ANNarchy-iCub-interface usage. \"\"\"\n\n"
60 file_template[
"import_const"] =
"\nimport ANN_iCub_Interface.Vocabs as iCub_Constants\n"
61 file_template[
"import_interface"] =
"from ANN_iCub_Interface.iCub import iCub_Interface"
62 file_template[
"create_instance"] =
"{0[var]}{0[count]} = {0[mod]}.{0[type]}()\n"
63 file_template[
"args_dict"] =
"args_{var}{count} = {cont}\n"
64 file_template[
"comment_mod"] =
"## Create and initialize {mod} instances.\n"
65 file_template[
"instance_init"] =
"{var}{count}.init(iCub, **args_{var}{count})\n\n"
66 file_template[
"instance_init_grpc"] =
"{var}{count}.init_grpc(iCub, **args_{var}{count})\n\n"
69 file_data.append(file_template[
"comment_file"])
70 file_data.append(file_template[
"import_const"])
71 file_data.append(
"## Create main interface wrapper class\n")
72 file_data.append(file_template[
"create_instance"].format({
'var':
"iCub",
"count":
"",
"mod":
"iCub_Interface",
"type":
"ANNiCub_wrapper"}) +
"\n\n")
75 if os.path.isfile(filename_config):
76 tree = ET.parse(filename_config)
77 robot = tree.getroot()
82 for idx, jread
in enumerate(robot.iter(
'JReader')):
83 args = {
"name": jread.attrib[
'name']}
86 if jread.find(
'part')
is None:
87 print(args[
'name'],
"Element part is missing")
88 no_error_jread =
False
90 args[
'part'] = jread.find(
'part').text
91 if jread.find(
'sigma')
is None:
92 print(args[
'name'],
"Element sigma is missing")
93 no_error_jread =
False
95 args[
'sigma'] = float(jread.find(
'sigma').text)
96 if jread.find(
'popsize')
is None:
97 if jread.find(
'n_pop')
is None:
98 print(args[
'name'],
"Element popsize is missing")
99 no_error_jread =
False
101 args[
'n_pop'] = int(jread.find(
'n_pop').text)
103 args[
'n_pop'] = int(jread.find(
'popsize').text)
104 if jread.find(
'ini_path')
is None:
105 print(args[
'name'],
"Element ini_path is missing")
106 no_error_jread =
False
108 args[
'ini_path'] = jread.find(
'ini_path').text
109 if not jread.find(
'ip_address')
is None:
110 args[
'ip_address'] = jread.find(
'ip_address').text
111 if not jread.find(
'port')
is None:
112 args[
'port'] = int(jread.find(
'port').text)
114 if jread.find(
'deg_per_neuron')
is not None:
115 args[
'degr_per_neuron'] = float(jread.find(
'deg_per_neuron').text)
118 jreader.append(file_template[
"create_instance"].format({
'var':
"jreader",
"count": idx,
"mod":
"Joint_Reader",
"type":
"PyJointReader"}))
119 jreader.append(file_template[
"args_dict"].format(var=
"jreader", count=idx, cont=str(args)))
121 jreader.append(file_template[
"instance_init_grpc"].format(count=idx, var=
"jreader"))
123 jreader.append(file_template[
"instance_init"].format(count=idx, var=
"jreader"))
125 print(
"Skipped Joint Reader '" + jread.attrib[
'name'] +
"' init due to missing element")
128 file_data.append(file_template[
"comment_mod"].format(mod=
"Joint Reader"))
129 file_template[
"import_interface"] +=
", Joint_Reader"
130 file_data.extend(jreader)
131 file_data.append(
"\n")
135 for idx, jwrite
in enumerate(robot.iter(
'JWriter')):
136 args = {
"name": jwrite.attrib[
'name']}
138 no_error_jwrite =
True
139 if jwrite.find(
'part')
is None:
140 print(args[
'name'],
"Element part is missing")
141 no_error_jwrite =
False
143 args[
'part'] = jwrite.find(
'part').text
144 if jwrite.find(
'popsize')
is None:
145 if jwrite.find(
'n_pop')
is None:
146 print(args[
'name'],
"Element popsize is missing")
147 no_error_jwrite =
False
149 args[
'n_pop'] = int(jwrite.find(
'n_pop').text)
151 args[
'n_pop'] = int(jwrite.find(
'popsize').text)
152 if jwrite.find(
'speed')
is None:
153 print(args[
'name'],
"Element speed is missing")
154 no_error_jwrite =
False
156 args[
'speed'] = float(jwrite.find(
'speed').text)
157 if jwrite.find(
'ini_path')
is None:
158 print(args[
'name'],
"Element ini_path is missing")
159 no_error_jwrite =
False
161 args[
'ini_path'] = jwrite.find(
'ini_path').text
162 if not jwrite.find(
'ip_address')
is None:
163 args[
'ip_address'] = jwrite.find(
'ip_address').text
164 if not jwrite.find(
'port')
is None:
165 args[
'port'] = int(jwrite.find(
'port').text)
166 if not jwrite.find(
'mode')
is None:
167 args[
'mode'] = jwrite.find(
'mode').text
168 if not jwrite.find(
'blocking')
is None:
169 args[
'blocking'] = eval(jwrite.find(
'blocking').text.capitalize())
170 if not jwrite.find(
'joint_select')
is None:
171 args[
'joints'] =
_text_to_list(jwrite.find(
'joint_select').text)
173 elif not jwrite.find(
'joints')
is None:
176 if jwrite.find(
'deg_per_neuron')
is not None:
177 args[
'degr_per_neuron'] = float(jwrite.find(
'deg_per_neuron').text)
180 jwriter.append(file_template[
"create_instance"].format({
'var':
"jwriter",
"count": idx,
"mod":
"Joint_Writer",
"type":
"PyJointWriter"}))
181 jwriter.append(file_template[
"args_dict"].format(var=
"jwriter", count=idx, cont=str(args)))
183 jwriter.append(file_template[
"instance_init_grpc"].format(count=idx, var=
"jwriter"))
185 jwriter.append(file_template[
"instance_init"].format(count=idx, var=
"jwriter"))
188 file_data.append(file_template[
"comment_mod"].format(mod=
"Joint Writer"))
189 file_template[
"import_interface"] +=
", Joint_Writer"
190 file_data.extend(jwriter)
191 file_data.append(
"\n")
195 for idx, vread
in enumerate(robot.iter(
'VisReader')):
196 args = {
"name": vread.attrib[
'name']}
198 no_error_vread =
True
199 if vread.find(
'eye')
is None:
200 print(args[
'name'],
"Element eye is missing")
201 no_error_vread =
False
203 args[
'eye'] = vread.find(
'eye').text
204 if (vread.find(
'fov_width')
is None)
or (vread.find(
'fov_height')
is None):
205 print(args[
'name'],
"Element fov_width or fov_height is missing")
206 no_error_vread =
False
208 args[
'fov_width'] = float(vread.find(
'fov_width').text)
209 args[
'fov_height'] = float(vread.find(
'fov_height').text)
210 if (vread.find(
'img_width')
is None)
or (vread.find(
'img_height')
is None):
211 print(args[
'name'],
"Element img_width or img_height is missing")
212 no_error_vread =
False
214 args[
'img_width'] = int(vread.find(
'img_width').text)
215 args[
'img_height'] = int(vread.find(
'img_height').text)
216 if vread.find(
'fast_filter')
is None:
217 print(args[
'name'],
"Element fast_filter is missing")
218 no_error_vread =
False
220 args[
'fast_filter'] = eval(vread.find(
'fast_filter').text.capitalize())
221 if vread.find(
'ini_path')
is None:
222 print(args[
'name'],
"Element ini_path is missing")
223 no_error_vread =
False
225 args[
'ini_path'] = vread.find(
'ini_path').text
226 if not vread.find(
'ip_address')
is None:
227 args[
'ip_address'] = vread.find(
'ip_address').text
228 if not vread.find(
'port')
is None:
229 args[
'port'] = int(vread.find(
'port').text)
232 vreader.append(file_template[
"create_instance"].format({
'var':
"vreader",
"count": idx,
"mod":
"Visual_Reader",
"type":
"PyVisualReader"}))
233 vreader.append(file_template[
"args_dict"].format(var=
"vreader", count=idx, cont=str(args)))
235 vreader.append(file_template[
"instance_init_grpc"].format(count=idx, var=
"vreader"))
237 vreader.append(file_template[
"instance_init"].format(count=idx, var=
"vreader"))
239 print(
"Skipped Visual Reader init due to missing element")
242 file_data.append(file_template[
"comment_mod"].format(mod=
"Visual Reader"))
243 file_template[
"import_interface"] +=
", Visual_Reader"
244 file_data.extend(vreader)
245 file_data.append(
"\n")
249 for idx, sread
in enumerate(robot.iter(
'TacReader')):
250 args = {
"name": sread.attrib[
'name']}
252 no_error_sread =
True
253 if sread.find(
'arm')
is None:
254 print(args[
'name'],
"Element arm is missing")
255 no_error_sread =
False
257 args[
'arm'] = sread.find(
'arm').text
258 if sread.find(
'normalize')
is None:
259 print(args[
'name'],
"Element norm is missing")
260 no_error_sread =
False
262 args[
'norm'] = eval(sread.find(
'normalize').text.capitalize())
263 if sread.find(
'ini_path')
is None:
264 print(args[
'name'],
"Element ini_path is missing")
265 no_error_sread =
False
267 args[
'ini_path'] = sread.find(
'ini_path').text
268 if not sread.find(
'ip_address')
is None:
269 args[
'ip_address'] = sread.find(
'ip_address').text
270 if not sread.find(
'port')
is None:
271 args[
'port'] = int(sread.find(
'port').text)
274 sreader.append(file_template[
"create_instance"].format({
'var':
"sreader",
"count": idx,
"mod":
"Skin_Reader",
"type":
"PySkinReader"}))
275 sreader.append(file_template[
"args_dict"].format(var=
"sreader", count=idx, cont=str(args)))
277 sreader.append(file_template[
"instance_init_grpc"].format(count=idx, var=
"sreader"))
279 sreader.append(file_template[
"instance_init"].format(count=idx, var=
"sreader"))
281 print(
"Skipped Skin Reader '" + sread.attrib[
'name'] +
"' init due to missing element")
284 file_data.append(file_template[
"comment_mod"].format(mod=
"Skin Reader"))
285 file_template[
"import_interface"] +=
", Skin_Reader"
286 file_data.extend(sreader)
287 file_data.append(
"\n")
291 for idx, kread
in enumerate(robot.iter(
'KinReader')):
292 args = {
"name": kread.attrib[
'name']}
294 no_error_kread =
True
295 if kread.find(
'part')
is None:
296 print(args[
'name'],
"Element part is missing!")
297 no_error_kread =
False
299 args[
'part'] = kread.find(
'part').text
300 if kread.find(
'version')
is None:
301 print(args[
'name'],
"Element version is missing!")
302 no_error_kread =
False
304 args[
'version'] = float(kread.find(
'version').text)
305 if kread.find(
'ini_path')
is None:
306 print(args[
'name'],
"Element ini_path is missing!")
307 no_error_kread =
False
309 args[
'ini_path'] = kread.find(
'ini_path').text
310 if kread.find(
'offline_mode')
is None:
311 print(args[
'name'],
"Standard value for element 'offline_mode' is used.")
312 args[
'offline_mode'] =
False
314 args[
'offline_mode'] = eval(kread.find(
'offline_mode').text.capitalize())
315 if not kread.find(
'ip_address')
is None:
316 args[
'ip_address'] = kread.find(
'ip_address').text
317 if not kread.find(
'port')
is None:
318 args[
'port'] = int(kread.find(
'port').text)
321 kreader.append(file_template[
"create_instance"].format({
'var':
"kreader",
"count": idx,
"mod":
"Kinematic_Reader",
"type":
"PyKinematicReader"}))
322 kreader.append(file_template[
"args_dict"].format(var=
"kreader", count=idx, cont=str(args)))
324 kreader.append(file_template[
"instance_init_grpc"].format(count=idx, var=
"kreader"))
326 kreader.append(file_template[
"instance_init"].format(count=idx, var=
"kreader"))
328 print(
"Skipped Kinematic Reader '" + kread.attrib[
'name'] +
"' init due to missing element")
331 file_data.append(file_template[
"comment_mod"].format(mod=
"Kinematic Reader"))
332 file_template[
"import_interface"] +=
", Kinematic_Reader"
333 file_data.extend(kreader)
334 file_data.append(
"\n")
338 for idx, kwrite
in enumerate(robot.iter(
'KinWriter')):
339 args = {
"name": kwrite.attrib[
'name']}
341 no_error_kwrite =
True
342 if kwrite.find(
'part')
is None:
343 print(args[
'name'],
"Element part is missing")
344 no_error_kwrite =
False
346 args[
'part'] = kwrite.find(
'part').text
347 if kwrite.find(
'version')
is None:
348 print(args[
'name'],
"Element version is missing")
349 no_error_kwrite =
False
351 args[
'version'] = float(kwrite.find(
'version').text)
352 if kwrite.find(
'ini_path')
is None:
353 print(args[
'name'],
"Element ini_path is missing")
354 no_error_kwrite =
False
356 args[
'ini_path'] = kwrite.find(
'ini_path').text
357 if not kwrite.find(
'ip_address')
is None:
358 args[
'ip_address'] = kwrite.find(
'ip_address').text
359 if not kwrite.find(
'port')
is None:
360 args[
'port'] = int(kwrite.find(
'port').text)
363 kwriter.append(file_template[
"create_instance"].format({
'var':
"kwriter",
"count": idx,
"mod":
"Kinematic_Writer",
"type":
"PyKinematicWriter"}))
364 kwriter.append(file_template[
"args_dict"].format(var=
"kwriter", count=idx, cont=str(args)))
366 kwriter.append(file_template[
"instance_init_grpc"].format(count=idx, var=
"kwriter"))
368 kwriter.append(file_template[
"instance_init"].format(count=idx, var=
"kwriter"))
370 print(
"Skipped Kinematic Writer '" + kwrite.attrib[
'name'] +
"' init due to missing element")
373 file_data.append(file_template[
"comment_mod"].format(mod=
"Kinematic Writer"))
374 file_template[
"import_interface"] +=
", Kinematic_Writer"
375 file_data.extend(kwriter)
376 file_data.append(
"\n")
379 print(
"Failed to read XML-file")
381 print(
"Not a valid XML-Filepath given!")
384 file_data.insert(2, file_template[
"import_interface"] +
"\n\n\n")
385 with open(filename_interface,
"w", encoding=
"utf-8")
as file:
386 file.writelines(file_data)
390# Global loading/ saving methods for whole interface configuration
395 """Init iCub interface with the modules given in the xml-file
400 filename of the xml-config-file
405 Returns a bool value representing the success of the init and a dicionary containing the module names for each module type
409 if os.path.isfile(xml_file):
410 tree = ET.parse(xml_file)
411 robot = tree.getroot()
413 if robot
is not None:
415 for jread
in robot.iter(
'JReader'):
416 args = {
'name': jread.attrib[
'name']}
418 no_error_jread =
True
419 if jread.find(
'part')
is None:
420 print(
"Element part is missing")
421 no_error_jread =
False
423 args[
'part'] = jread.find(
'part').text
424 if jread.find(
'sigma')
is None:
425 print(
"Element sigma is missing")
426 no_error_jread =
False
428 args[
'sigma'] = float(jread.find(
'sigma').text)
429 if jread.find(
'popsize')
is None:
430 if jread.find(
'pop_size')
is None:
431 if jread.find(
'n_pop')
is None:
432 print(
"Element popsize is missing")
433 no_error_jread =
False
435 args[
'n_pop'] = int(jread.find(
'n_pop').text)
437 args[
'n_pop'] = int(jread.find(
'pop_size').text)
439 args[
'n_pop'] = int(jread.find(
'popsize').text)
440 if jread.find(
'ini_path')
is None:
441 print(
"Element ini_path is missing")
442 no_error_jread =
False
444 args[
'ini_path'] = jread.find(
'ini_path').text
445 if jread.find(
'ip_address')
is not None:
446 args[
'ip_address'] = jread.find(
'ip_address').text
447 if jread.find(
'port')
is not None:
448 args[
'port'] = int(jread.find(
'port').text)
450 if jread.find(
'deg_per_neuron')
is not None:
451 args[
'degr_per_neuron'] = float(jread.find(
'deg_per_neuron').text)
456 if not reader.init_grpc(iCub, **args):
457 print(
"Init Joint Reader '" + jread.attrib[
'name'] +
"' failed!")
459 if not reader.init(iCub, **args):
460 print(
"Init Joint Reader '" + jread.attrib[
'name'] +
"' failed!")
462 print(
"Skipped Joint Reader '" + jread.attrib[
'name'] +
"' init due to missing element")
465 for jwrite
in robot.iter(
'JWriter'):
466 args = {
'name': jwrite.attrib[
'name']}
468 no_error_jwrite =
True
469 if jwrite.find(
'part')
is None:
470 print(
"Element part is missing")
471 no_error_jwrite =
False
473 args[
'part'] = jwrite.find(
'part').text
474 if jwrite.find(
'popsize')
is None:
475 if jwrite.find(
'pop_size')
is None:
476 if jwrite.find(
'n_pop')
is None:
477 print(
"Element n_pop is missing")
478 no_error_jwrite =
False
480 args[
'n_pop'] = int(jwrite.find(
'n_pop').text)
482 args[
'n_pop'] = int(jwrite.find(
'pop_size').text)
484 args[
'n_pop'] = int(jwrite.find(
'popsize').text)
485 if jwrite.find(
'speed')
is not None:
486 args[
'speed'] = float(jwrite.find(
'speed').text)
487 if jwrite.find(
'ini_path')
is None:
488 print(
"Element ini_path is missing")
489 no_error_jwrite =
False
491 args[
'ini_path'] = jwrite.find(
'ini_path').text
492 if jwrite.find(
'ip_address')
is not None:
493 args[
'ip_address'] = jwrite.find(
'ip_address').text
494 if jwrite.find(
'port')
is not None:
495 args[
'port'] = int(jwrite.find(
'port').text)
496 if jwrite.find(
'mode')
is not None:
497 args[
'mode'] = jwrite.find(
'mode').text
498 if jwrite.find(
'blocking')
is not None:
499 args[
'blocking'] = eval(jwrite.find(
'blocking').text.capitalize())
500 if jwrite.find(
'joint_select')
is not None:
501 args[
'joints'] =
_text_to_list(jwrite.find(
'joint_select').text)
503 elif jwrite.find(
'joints')
is not None:
506 if jwrite.find(
'deg_per_neuron')
is not None:
507 args[
'deg_per_neuron'] = float(jwrite.find(
'deg_per_neuron').text)
512 if not writer.init_grpc(iCub, **args):
513 print(
"Init Joint Writer '" + jwrite.attrib[
'name'] +
"' failed!")
515 if not writer.init(iCub, **args):
516 print(
"Init Joint Writer '" + jwrite.attrib[
'name'] +
"' failed!")
518 print(
"Skipped Joint Writer '" + jwrite.attrib[
'name'] +
"' init due to missing element")
521 for vread
in robot.iter(
'VisReader'):
522 args = {
'name': vread.attrib[
'name']}
524 no_error_vread =
True
525 if vread.find(
'eye')
is None:
526 print(
"Element eye is missing")
527 no_error_vread =
False
529 args[
'eye'] = vread.find(
'eye').text
530 if vread.find(
'fov_width')
is not None:
531 args[
'fov_width'] = float(vread.find(
'fov_width').text)
532 if vread.find(
'fov_height')
is not None:
533 args[
'fov_height'] = float(vread.find(
'fov_height').text)
534 if vread.find(
'img_width')
is not None:
535 args[
'img_width'] = int(vread.find(
'img_width').text)
536 if vread.find(
'img_height')
is not None:
537 args[
'img_height'] = int(vread.find(
'img_height').text)
538 if vread.find(
'fast_filter')
is not None:
539 args[
'fast_filter'] = eval(vread.find(
'fast_filter').text.capitalize())
540 if vread.find(
'ini_path')
is None:
541 print(
"Element ini_path is missing")
542 no_error_vread =
False
544 args[
'ini_path'] = vread.find(
'ini_path').text
545 if vread.find(
'ip_address')
is not None:
546 args[
'ip_address'] = vread.find(
'ip_address').text
547 if vread.find(
'port')
is not None:
548 args[
'port'] = int(vread.find(
'port').text)
553 if not vreader.init_grpc(iCub, **args):
554 print(
"Init Visual Reader '" + vread.attrib[
'name'] +
"' failed!")
556 if not vreader.init(iCub, **args):
557 print(
"Init Visual Reader '" + vread.attrib[
'name'] +
"' failed!")
559 print(
"Skipped Visual Reader init due to missing element")
562 for sread
in robot.iter(
'TacReader'):
563 args = {
'name': sread.attrib[
'name']}
565 no_error_sread =
True
566 if sread.find(
'arm')
is None:
567 print(
"Element arm is missing")
568 no_error_sread =
False
570 args[
'arm'] = sread.find(
'arm').text
571 if sread.find(
'normalize')
is None:
572 if sread.find(
'norm_data')
is None:
573 if sread.find(
'norm')
is None:
574 print(
"Element norm is missing")
575 no_error_sread =
False
577 args[
'norm'] = eval(sread.find(
'norm').text.capitalize())
579 args[
'norm'] = eval(sread.find(
'norm_data').text.capitalize())
581 args[
'norm'] = eval(sread.find(
'normalize').text.capitalize())
582 if sread.find(
'ini_path')
is None:
583 print(
"Element ini_path is missing")
584 no_error_sread =
False
586 args[
'ini_path'] = sread.find(
'ini_path').text
587 if sread.find(
'ip_address')
is not None:
588 args[
'ip_address'] = sread.find(
'ip_address').text
589 if sread.find(
'port')
is not None:
590 args[
'port'] = int(sread.find(
'port').text)
595 if not sreader.init_grpc(iCub, **args):
596 print(
"Init Skin Reader '" + sread.attrib[
'name'] +
"' failed!")
598 if not sreader.init(iCub, **args):
599 print(
"Init Skin Reader '" + sread.attrib[
'name'] +
"' failed!")
601 print(
"Skipped Skin Reader '" + sread.attrib[
'name'] +
"' init due to missing element")
604 for kread
in robot.iter(
'KinReader'):
605 args = {
'name': kread.attrib[
'name']}
607 no_error_kread =
True
609 if kread.find(
'part')
is None:
610 print(
"Element part is missing")
611 no_error_kread =
False
613 args[
'part'] = kread.find(
'part').text
614 if kread.find(
'version')
is None:
615 print(
"Element version is missing")
616 no_error_kread =
False
618 args[
'version'] = float(kread.find(
'version').text)
619 if kread.find(
'ini_path')
is None:
620 print(
"Element ini_path is missing")
621 no_error_kread =
False
623 args[
'ini_path'] = kread.find(
'ini_path').text
624 if kread.find(
'offline_mode')
is not None:
625 args[
'offline_mode'] = eval(kread.find(
'offline_mode').text.capitalize())
627 if kread.find(
'ip_address')
is not None:
628 args[
'ip_address'] = kread.find(
'ip_address').text
629 if kread.find(
'port')
is not None:
630 args[
'port'] = int(kread.find(
'port').text)
636 if not kreader.init_grpc(iCub, **args):
637 print(
"Init Kinematic Reader '" + kread.attrib[
'name'] +
"' failed!")
639 if not kreader.init(iCub, **args):
640 print(
"Init Kinematic Reader '" + kread.attrib[
'name'] +
"' failed!")
642 print(
"Skipped Kinematic Reader '" + kread.attrib[
'name'] +
"' init due to missing element")
645 for kwrite
in robot.iter(
'KinWriter'):
648 no_error_kwrite =
True
649 if kwrite.find(
'part')
is None:
650 print(
"Element part is missing")
651 no_error_kwrite =
False
653 args[
'part'] = kwrite.find(
'part').text
654 if kwrite.find(
'version')
is None:
655 print(
"Element version is missing")
656 no_error_kwrite =
False
658 args[
'version'] = float(kwrite.find(
'version').text)
659 if kwrite.find(
'ini_path')
is None:
660 print(
"Element ini_path is missing")
661 no_error_kwrite =
False
663 args[
'ini_path'] = kwrite.find(
'ini_path').text
664 if kwrite.find(
'ip_address')
is not None:
665 args[
'ip_address'] = kwrite.find(
'ip_address').text
666 if kwrite.find(
'port')
is not None:
667 args[
'port'] = int(kwrite.find(
'port').text)
673 if not kwriter.init_grpc(iCub, **args):
674 print(
"Init Kinematic Writer '" + kwrite.attrib[
'name'] +
"' failed!")
676 if not kwriter.init(iCub, **args):
677 print(
"Init Kinematic Writer '" + kwrite.attrib[
'name'] +
"' failed!")
679 print(
"Skipped Kinematic Writer '" + kwrite.attrib[
'name'] +
"' init due to missing element")
681 name_dict[
"Joint_Reader"] = iCub._get_jreader_dict().keys()
682 name_dict[
"Joint_Writer"] = iCub._get_jwriter_dict().keys()
683 name_dict[
"Skin_Reader"] = iCub._get_sreader_dict().keys()
684 name_dict[
"Visual_Reader"] = iCub._get_vreader_dict().keys()
685 name_dict[
"Kinematic_Reader"] = iCub._get_kreader_dict().keys()
686 name_dict[
"Kinematic_Writer"] = iCub._get_kwriter_dict().keys()
688 return True, name_dict
690 print(
"Failed to read XML-file")
691 return False, name_dict
693 print(
"Not a valid XML-Filepath given!")
694 return False, name_dict
698 """Save robot configuration to xml-config file
703 filename for the xml-config-file
705 optional description added as comment in the robot section. Defaults to "".
711 root = ET.Element(
"robot")
712 root.append(ET.Comment(description))
714 for name, module
in iCub._get_jreader_dict().items():
715 jreader = ET.SubElement(root,
"JReader", attrib={
"name": name})
716 jread_param = module._get_parameter()
717 for key, value
in jread_param.items():
718 ET.SubElement(jreader, key.decode(
'utf-8')).text = value.decode(
'utf-8')
720 for name, module
in iCub._get_jwriter_dict().items():
721 jwriter = ET.SubElement(root,
"JWriter", attrib={
"name": name})
722 jwrite_param = module._get_parameter()
723 for key, value
in jwrite_param.items():
724 ET.SubElement(jwriter, key.decode(
'utf-8')).text = value.decode(
'utf-8')
726 for name, module
in iCub._get_vreader_dict().items():
727 vreader = ET.SubElement(root,
"VisReader", attrib={
"name": name})
728 vread_param = module._get_parameter()
729 for key, value
in vread_param.items():
730 ET.SubElement(vreader, key.decode(
'utf-8')).text = value.decode(
'utf-8')
732 for name, module
in iCub._get_sreader_dict().items():
733 sreader = ET.SubElement(root,
"TacReader", attrib={
"name": name})
734 sread_param = module._get_parameter()
735 for key, value
in sread_param.items():
736 ET.SubElement(sreader, key.decode(
'utf-8')).text = value.decode(
'utf-8')
738 for name, module
in iCub._get_kreader_dict().items():
739 kreader = ET.SubElement(root,
"KinReader", attrib={
"name": name})
740 kread_param = module._get_parameter()
741 for key, value
in kread_param.items():
742 ET.SubElement(kreader, key.decode(
'utf-8')).text = value.decode(
'utf-8')
744 for name, module
in iCub._get_kwriter_dict().items():
745 kwriter = ET.SubElement(root,
"KinWriter", attrib={
"name": name})
746 kwrite_param = module._get_parameter()
747 for key, value
in kwrite_param.items():
748 ET.SubElement(kwriter, key.decode(
'utf-8')).text = value.decode(
'utf-8')
750 xml_file_string = minidom.parseString(ET.tostring(root,
'utf-8')).toprettyxml(indent=
" ")
751 with open(xml_file,
"w", encoding=
"utf-8")
as files:
752 files.write(xml_file_string)