00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 from __future__ import print_function
00036
00037 import sys
00038
00039 WXVER = ['2.8', '2.9']
00040 import wxversion
00041 if wxversion.checkInstalled(WXVER):
00042 wxversion.select(WXVER)
00043 else:
00044 sys.stderr.write("This application requires wxPython version %s\n"%(WXVER))
00045 sys.exit(1)
00046 import wx
00047
00048 import rospy
00049 import rosgraph.names
00050
00051 import rxtools.rxplot
00052
00053
00054 def rxplot_main():
00055 from optparse import OptionParser
00056 parser = OptionParser(usage="usage: rxplot [options] /topic/field1 [/topic/field2] [topic/field1:field2:field3]")
00057 parser.add_option("-l", "--legend", type="string",
00058 dest="legend", default='',
00059 help="set the legend")
00060 parser.add_option("-p", "--period", type="int",
00061 dest="period", default=5,
00062 help="set period displayed in window")
00063 parser.add_option("-m", "--marker", type="string",
00064 dest="marker", default='None',
00065 help="set the line marker, e.g. o, ^, .")
00066 parser.add_option("-t", "--title", type="string",
00067 dest="title", default='RXPlot',
00068 help="set the title")
00069 parser.add_option("--ymax", type="float",
00070 dest="maxy", default=0,
00071 help="set initial y-axis maximum")
00072 parser.add_option("--ymin", type="float",
00073 dest="miny", default=0,
00074 help="set initial y-axis minimum")
00075 parser.add_option("-b", "--buffer", type="int",
00076 dest="buffer", default=-1,
00077 help="set size of buffer in seconds (default of -1 keeps all data)")
00078 parser.add_option("-r", "--refresh_rate", type="float",
00079 dest="refresh_rate", default=2,
00080 help="set refresh rate (default 2hz)")
00081 parser.add_option("-P", "--pause", action="store_true",
00082 dest="start_paused",
00083 help="start in paused state")
00084 parser.add_option("-M", "--mode",
00085 dest="mode", default="2d",
00086 help="options: \"2d\", \"3d\", or \"scatter\" [default=%default]. "
00087 "Use \"2d\" to plot all topics vs. time. "
00088 "Use \"3d\" or \"scatter\" to plot in 3D using mplot3d. "
00089 "Both \"3d\" and \"scatter\" plot against time if 2 topics"
00090 "are provided, and against third topic if 3 are provided. "
00091 )
00092 options, topics = parser.parse_args(rospy.myargv()[1:])
00093
00094 if not topics:
00095 parser.error("Please specify a topic field")
00096 if options.mode not in ['2d', '3d', 'scatter']:
00097 parser.error("invalid mode: %s\nValid modes are 2d, 3d, and scatter"%(options.mode))
00098
00099 topic_list = []
00100 for t in topics:
00101
00102 c_topics = []
00103
00104 for sub_t in [x for x in t.split(',') if x]:
00105
00106 if ':' in sub_t:
00107 base = sub_t[:sub_t.find(':')]
00108
00109 c_topics.append(base)
00110 if not '/' in base:
00111 parser.error("%s must contain a topic and field name"%sub_t)
00112 base = base[:base.rfind('/')]
00113
00114
00115 fields = sub_t.split(':')[1:]
00116 c_topics.extend(["%s/%s"%(base, f) for f in fields if f])
00117 else:
00118 c_topics.append(sub_t)
00119
00120
00121 c_topics = [rosgraph.names.script_resolve_name('rxplot', n) for n in c_topics]
00122
00123 topic_list.append(c_topics)
00124
00125
00126 print_topic_list = []
00127 for l in topic_list:
00128 if type(l) == list:
00129 print_topic_list.extend(l)
00130 else:
00131 print_topic_list.append(l)
00132
00133
00134
00135 if len(print_topic_list) > len(rxtools.rxplot.COLORS):
00136 parser.error("maximum number of topics that can be plotted is %d"%len(rxtools.rxplot.COLORS))
00137
00138 if options.mode in ['3d', 'scatter']:
00139
00140
00141
00142 if len(print_topic_list) < 2 or len(print_topic_list) > 3:
00143 parser.error("You may only specific 2 or 3 topics with '3d' or 'scatter'.\nWhen 2 topics are provided, time is used as the third axis.")
00144
00145 topic_list = [[x] for x in print_topic_list]
00146
00147 print("plotting topics", ', '.join(print_topic_list))
00148
00149 rxtools.rxplot.rxplot_app(topic_list, options)