$search
00001 # Software License Agreement (BSD License) 00002 # 00003 # Copyright (c) 2009, Willow Garage, Inc. 00004 # All rights reserved. 00005 # 00006 # Redistribution and use in source and binary forms, with or without 00007 # modification, are permitted provided that the following conditions 00008 # are met: 00009 # 00010 # * Redistributions of source code must retain the above copyright 00011 # notice, this list of conditions and the following disclaimer. 00012 # * Redistributions in binary form must reproduce the above 00013 # copyright notice, this list of conditions and the following 00014 # disclaimer in the documentation and/or other materials provided 00015 # with the distribution. 00016 # * Neither the name of Willow Garage, Inc. nor the names of its 00017 # contributors may be used to endorse or promote products derived 00018 # from this software without specific prior written permission. 00019 # 00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00031 # POSSIBILITY OF SUCH DAMAGE. 00032 # 00033 # Revision $Id$ 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 # TODO: poll for rospy.is_shutdown() 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 # c_topics is the list of topics to plot together 00096 c_topics = [] 00097 # compute combined topic list, t == '/foo/bar1,/baz/bar2' 00098 for sub_t in [x for x in t.split(',') if x]: 00099 # check for shorthand '/foo/field1:field2:field3' 00100 if ':' in sub_t: 00101 base = sub_t[:sub_t.find(':')] 00102 # the first prefix includes a field name, so save then strip it off 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 # compute the rest of the field names 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 # #1053: resolve command-line topic names 00115 c_topics = [roslib.scriptutil.script_resolve_name('rxplot', n) for n in c_topics] 00116 00117 topic_list.append(c_topics) 00118 00119 #flatten for printing 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 # constrain the number of things we plot by len(COLORS). this is an artificial 00128 # performance hack. 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 #TODO: need a better spec on what the 3d topic args are. It 00134 #would be nice if the 3d plot were as robust as the normal 00135 #rxplot with respect to having more plots. 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 # for now, cannot multigraph, so unify representation going into plot call 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)