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 WXVER = '2.8'
00036 import wxversion
00037 if wxversion.checkInstalled(WXVER):
00038 wxversion.select(WXVER)
00039 else:
00040 print >> sys.stderr, "This application requires wxPython version %s"%(WXVER)
00041 sys.exit(1)
00042 import wx
00043
00044 import roslib.scriptutil
00045 import rospy
00046
00047 import rxtools.rxplot
00048
00049
00050 def rxplot_main():
00051 from optparse import OptionParser
00052 parser = OptionParser(usage="usage: rxplot [options] /topic/field1 [/topic/field2] [topic/field1:field2:field3]")
00053 parser.add_option("-l", "--legend", type="string",
00054 dest="legend", default='',
00055 help="set the legend")
00056 parser.add_option("-p", "--period", type="int",
00057 dest="period", default=5,
00058 help="set period displayed in window")
00059 parser.add_option("-m", "--marker", type="string",
00060 dest="marker", default='None',
00061 help="set the line marker, e.g. o, ^, .")
00062 parser.add_option("-t", "--title", type="string",
00063 dest="title", default='RXPlot',
00064 help="set the title")
00065 parser.add_option("-b", "--buffer", type="int",
00066 dest="buffer", default=-1,
00067 help="set size of buffer in seconds (default of -1 keeps all data)")
00068 parser.add_option("-M", "--mode",
00069 dest="mode", default="2d",
00070 help="options: \"2d\", \"3d\", or \"scatter\" [default=%default]. "
00071 "Use \"2d\" to plot all topics vs. time. "
00072 "Use \"3d\" or \"scatter\" to plot in 3D using mplot3d. "
00073 "Both \"3d\" and \"scatter\" plot against time if 2 topics"
00074 "are provided, and against third topic if 3 are provided. "
00075 )
00076 options, topics = parser.parse_args(rospy.myargv()[1:])
00077
00078 if not topics:
00079 parser.error("Please specify a topic field")
00080 if options.mode not in ['2d', '3d', 'scatter']:
00081 parser.error("invalid mode: %s\nValid modes are 2d, 3d, and scatter"%(options.mode))
00082
00083 topic_list = []
00084 for t in topics:
00085
00086 c_topics = []
00087
00088 for sub_t in [x for x in t.split(',') if x]:
00089
00090 if ':' in sub_t:
00091 base = sub_t[:sub_t.find(':')]
00092
00093 c_topics.append(base)
00094 if not '/' in base:
00095 parser.error("%s must contain a topic and field name"%sub_t)
00096 base = base[:base.rfind('/')]
00097
00098
00099 fields = sub_t.split(':')[1:]
00100 c_topics.extend(["%s/%s"%(base, f) for f in fields if f])
00101 else:
00102 c_topics.append(sub_t)
00103
00104
00105 c_topics = [roslib.scriptutil.script_resolve_name('rxplot', n) for n in c_topics]
00106
00107 topic_list.append(c_topics)
00108
00109
00110 print_topic_list = []
00111 for l in topic_list:
00112 if type(l) == list:
00113 print_topic_list.extend(l)
00114 else:
00115 print_topic_list.append(l)
00116
00117
00118
00119 if len(print_topic_list) > len(rxtools.rxplot.COLORS):
00120 parser.error("maximum number of topics that can be plotted is %d"%len(rxtools.rxplot.COLORS))
00121
00122 if options.mode in ['3d', 'scatter']:
00123
00124
00125
00126 if len(print_topic_list) < 2 or len(print_topic_list) > 3:
00127 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.")
00128
00129 topic_list = [[x] for x in print_topic_list]
00130
00131 print "plotting topics", ', '.join(print_topic_list)
00132
00133 rxtools.rxplot.rxplot_app(topic_list, options)