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 roslib.scriptutil
00049 import rospy
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("-b", "--buffer", type="int",
00070 dest="buffer", default=-1,
00071 help="set size of buffer in seconds (default of -1 keeps all data)")
00072 parser.add_option("-r", "--refresh_rate", type="float",
00073 dest="refresh_rate", default=2,
00074 help="set refresh rate (default 2hz)")
00075 parser.add_option("-P", "--pause", action="store_true",
00076 dest="start_paused",
00077 help="start in paused state")
00078 parser.add_option("-M", "--mode",
00079 dest="mode", default="2d",
00080 help="options: \"2d\", \"3d\", or \"scatter\" [default=%default]. "
00081 "Use \"2d\" to plot all topics vs. time. "
00082 "Use \"3d\" or \"scatter\" to plot in 3D using mplot3d. "
00083 "Both \"3d\" and \"scatter\" plot against time if 2 topics"
00084 "are provided, and against third topic if 3 are provided. "
00085 )
00086 options, topics = parser.parse_args(rospy.myargv()[1:])
00087
00088 if not topics:
00089 parser.error("Please specify a topic field")
00090 if options.mode not in ['2d', '3d', 'scatter']:
00091 parser.error("invalid mode: %s\nValid modes are 2d, 3d, and scatter"%(options.mode))
00092
00093 topic_list = []
00094 for t in topics:
00095
00096 c_topics = []
00097
00098 for sub_t in [x for x in t.split(',') if x]:
00099
00100 if ':' in sub_t:
00101 base = sub_t[:sub_t.find(':')]
00102
00103 c_topics.append(base)
00104 if not '/' in base:
00105 parser.error("%s must contain a topic and field name"%sub_t)
00106 base = base[:base.rfind('/')]
00107
00108
00109 fields = sub_t.split(':')[1:]
00110 c_topics.extend(["%s/%s"%(base, f) for f in fields if f])
00111 else:
00112 c_topics.append(sub_t)
00113
00114
00115 c_topics = [roslib.scriptutil.script_resolve_name('rxplot', n) for n in c_topics]
00116
00117 topic_list.append(c_topics)
00118
00119
00120 print_topic_list = []
00121 for l in topic_list:
00122 if type(l) == list:
00123 print_topic_list.extend(l)
00124 else:
00125 print_topic_list.append(l)
00126
00127
00128
00129 if len(print_topic_list) > len(rxtools.rxplot.COLORS):
00130 parser.error("maximum number of topics that can be plotted is %d"%len(rxtools.rxplot.COLORS))
00131
00132 if options.mode in ['3d', 'scatter']:
00133
00134
00135
00136 if len(print_topic_list) < 2 or len(print_topic_list) > 3:
00137 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.")
00138
00139 topic_list = [[x] for x in print_topic_list]
00140
00141 print("plotting topics", ', '.join(print_topic_list))
00142
00143 rxtools.rxplot.rxplot_app(topic_list, options)