dmodel.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from ros import rosparam
4 import yaml
5 import tempfile
6 from resource_retriever import get
7 import subprocess
8 import signal
9 import argparse
10 import os
11 import sys
12 
14  return "roslaunch all of the nodes"
15 
16 
17 def show_usage(cmd=None):
18  cmd = os.path.relpath(sys.argv[0], os.getcwd()) if cmd is None else cmd
19  return "{0} [-h|--help] [--version]".format(cmd)
20 
21 
23  return "epilog..."
24 
26  def __init__(self, base_file=None):
27  if base_file:
28  self.data = yaml.load(base_file)
29  else:
30  self.data = {}
31  def write(self, f):
32  f.write(yaml.dump(self.data, default_flow_style=False))
33 
34  def add_display(self, name, class_name, topic=None, color=None, fields={}, enabled=True):
35  d = {'Name': name, 'Class': class_name, 'Enabled': enabled}
36  if topic:
37  d['Topic'] = topic
38  if color:
39  d['Color'] = '%d; %d; %d' % color
40  d.update(fields)
41  self.data['Visualization Manager']['Displays'].append(d)
42 
43  def add_model(self, parameter='robot_description', tf_prefix=None):
44  fields = {'Robot Description': parameter}
45  if tf_prefix:
46  fields['TF Prefix'] = tf_prefix
47  self.add_display(tf_prefix[1:], 'rviz/RobotModel', fields=fields)
48 
49 
50 if __name__=="__main__":
51  # Ref : https://docs.python.org/2/library/argparse
52  parser = argparse.ArgumentParser(description=show_description(),
53  usage=show_usage(),
54  epilog=show_epilog(),
55  formatter_class=argparse.ArgumentDefaultsHelpFormatter)
56 
57  parser.add_argument('-o', '--option', type=str, default='eof', help='dont care')
58  parsed_known_args, unknown_args = parser.parse_known_args(sys.argv[1:])
59  print(parsed_known_args)
60  usp = None
61  try:
62  l = rosparam.list_params('')
63  models = []
64  for p in l:
65  v = rosparam.get_param(p)
66  if type(v) is str and len(v) > 10000:
67  models.append(p)
68  r = create_robot_model(get('package://dsr_launcher/rviz/default.rviz'))
69  for m in models:
70  r.add_model(m, m[0:-18])
71  temp = tempfile.NamedTemporaryFile()
72  r.write(temp)
73  temp.flush()
74  args = ['rosrun', 'rviz', 'rviz', '-d', temp.name]
75  usp = subprocess.call(args)
76  temp.close()
77  except KeyboardInterrupt:
78  print("Interrupted by user, shutting down...")
type
Definition: dmodel.py:57
def show_usage(cmd=None)
Definition: dmodel.py:17
def add_display(self, name, class_name, topic=None, color=None, fields={}, enabled=True)
Definition: dmodel.py:34
def show_description()
Definition: dmodel.py:13
def __init__(self, base_file=None)
Definition: dmodel.py:26
def add_model(self, parameter='robot_description', tf_prefix=None)
Definition: dmodel.py:43
def show_epilog()
Definition: dmodel.py:22
def write(self, f)
Definition: dmodel.py:31


dsr_launcher
Author(s): Kab Kyoum Kim , Jin Hyuk Gong , Jeongwoo Lee
autogenerated on Sat May 18 2019 02:32:50