Go to the documentation of this file.00001
00002 from __future__ import print_function
00003 import sys
00004 import yaml
00005 from rwt_config_generator import *
00006 import argparse
00007 import rospy
00008
00009 def warning(*objs):
00010 print("WARNING: ", *objs, file=sys.stderr)
00011
00012 parser = argparse.ArgumentParser()
00013 parser.add_argument('rviz_config')
00014 parser.add_argument('output_html_file', nargs='?')
00015 parser.add_argument('-b', '--bson', action='store_true')
00016 parser.add_argument('-u', '--host', type=str, nargs='?')
00017 args = parser.parse_args(rospy.myargv()[1:])
00018
00019 rviz = yaml.load( open(args.rviz_config) )['Visualization Manager']
00020
00021 def to_hex(s):
00022 if s is None:
00023 return None
00024 ns = tuple(map(int, s.split(';')))
00025 s = '0x%02x%02x%02x'%ns
00026 return s
00027
00028 def get(key, d=None):
00029 if d is None:
00030 d = rviz
00031 for s in key.split('/'):
00032 d = d.get(s, None)
00033 if d==None:
00034 return None
00035 return d
00036
00037 def parse_displays(c, displays):
00038 for display in displays:
00039 if not display.get('Enabled', True):
00040 continue
00041 cls = display['Class']
00042 if cls == 'rviz/Grid':
00043 c.add_grid()
00044 elif cls == 'rviz/RobotModel':
00045 c.add_model(param=display.get('Robot Description'), tfPrefix=display.get('TF Prefix'))
00046 elif cls == 'rviz/Marker':
00047 c.add_markers(topic=display.get('Marker Topic'))
00048 elif cls == 'rviz/MarkerArray':
00049 c.add_marker_array(topic=display.get('Marker Topic'))
00050 elif cls == 'rviz/InteractiveMarkers':
00051 topic = display.get('Update Topic')
00052 topic = topic.replace('/update', '')
00053 c.add_imarkers(topic=topic)
00054 elif cls == 'rviz/PointCloud2':
00055 c.add_pointcloud(topic=display.get('Topic'), size=display.get('Size (m)'))
00056 elif cls == 'rviz/LaserScan':
00057 c.add_laserscan(topic=display.get('Topic'), color=to_hex(display.get('Color')), size=display.get('Size (m)'))
00058 elif cls == 'rviz/Path':
00059 c.add_path(topic=display.get('Topic'), color=to_hex(display.get('Color')))
00060 elif cls == 'rviz/Polygon':
00061 c.add_polygon(topic=display.get('Topic'), color=to_hex(display.get('Color')))
00062 elif cls == 'rviz/Pose':
00063 c.add_pose(topic=display.get('Topic'), color=to_hex(display.get('Color')),
00064 shaft_radius=display.get('Shaft Radius'),
00065 head_radius=display.get('Head Radius'),
00066 shaft_length=display.get('Shaft Length'),
00067 head_length=display.get('Head Length'))
00068 elif cls == 'rviz/Odometry':
00069 c.add_odometry(topic=display.get('Topic'), color=to_hex(display.get('Color')),
00070 shaft_length=display.get('Length'), keep=display.get('Keep'))
00071
00072 elif cls == 'rviz/PoseArray':
00073 c.add_posearray(topic=display.get('Topic'), color=to_hex(display.get('Color')), length=display.get('Arrow Length'))
00074 elif cls == 'rviz/PointStamped':
00075 c.add_point(topic=display.get('Topic'), color=to_hex(display.get('Color')), radius=display.get('Radius'))
00076 elif cls == 'rviz/Group':
00077 parse_displays( c, display['Displays'] )
00078 elif cls == 'rviz/Map':
00079 c.add_map(topic=display.get('Topic'), alpha=display.get('Alpha'), tf=True)
00080 else:
00081 warning("Class %s not supported yet!"%cls)
00082
00083
00084 frame = get('Global Options/Fixed Frame')
00085
00086 c = RWTConfig(host=args.host, fixed_frame=frame)
00087 if args.bson:
00088 c.add_bson_header()
00089 parse_displays(c, get('Displays'))
00090
00091 if args.output_html_file:
00092 with open(args.output_html_file, 'w') as f:
00093 f.write(str(c))
00094 else:
00095 print(c)