plot_tcat_state.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # ####################################################################
00004 # Copyright (c) 2013, Shadow Robot Company, All rights reserved.
00005 #
00006 # This library is free software; you can redistribute it and/or
00007 # modify it under the terms of the GNU Lesser General Public
00008 # License as published by the Free Software Foundation; either
00009 # version 3.0 of the License, or (at your option) any later version.
00010 #
00011 # This library is distributed in the hope that it will be useful,
00012 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00014 # Lesser General Public License for more details.
00015 #
00016 # You should have received a copy of the GNU Lesser General Public
00017 # License along with this library.
00018 # ####################################################################
00019 
00020 import rospy
00021 from sr_ronex_msgs.msg import TCATState
00022 # from PyQt4.QtCore import *
00023 from PyQt4.QtGui import QMainWindow, QApplication, QWidget, QVBoxLayout
00024 
00025 import numpy
00026 from std_msgs.msg import Int8
00027 import sys
00028 
00029 import matplotlib
00030 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
00031 from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
00032 from matplotlib.figure import Figure
00033 
00034 import ctypes
00035 from math import sqrt
00036 
00037 
00038 class PlotWindow(QMainWindow):
00039     def __init__(self, parent=None):
00040         QMainWindow.__init__(self, parent)
00041         self.setWindowTitle('Impulse Responses')
00042         self.create_main_frame()
00043 
00044         self.setMinimumSize(1600, 900)
00045 
00046         self.on_draw()
00047 
00048     def save_plot(self):
00049         pass
00050 
00051     def on_about(self):
00052         pass
00053 
00054     def on_pick(self, event):
00055         pass
00056 
00057     def on_draw(self):
00058         for ax in self.axes:
00059             ax.clear()
00060             ax.grid(True)
00061         self.canvas.draw()
00062 
00063     def create_main_frame(self):
00064         self.main_frame = QWidget()
00065         self.dpi = 100
00066         self.fig = Figure((5.0, 4.0), dpi=self.dpi)
00067         self.canvas = FigureCanvas(self.fig)
00068         self.canvas.setParent(self.main_frame)
00069         self.axes = []
00070         for i in range(1, 5):
00071             self.axes.append(self.fig.add_subplot(4, 1, i))
00072         self.canvas.mpl_connect('pick_event', self.on_pick)
00073         self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame)
00074         vbox = QVBoxLayout()
00075         vbox.addWidget(self.canvas)
00076         vbox.addWidget(self.mpl_toolbar)
00077         self.main_frame.setLayout(vbox)
00078         self.setCentralWidget(self.main_frame)
00079 
00080 
00081 class TCATPlot(PlotWindow):
00082     def __init__(self):
00083         PlotWindow.__init__(self)
00084 
00085         self.window_size = 20
00086 
00087         rospy.init_node('visualizer', anonymous=True)
00088         self.subscriber = rospy.Subscriber("/ronex/tcat/1394812611/state", TCATState, self.plotResults, queue_size=1)
00089 
00090     def plotResults(self, data):
00091         receiver_index = 0
00092 
00093         print
00094         base = [r.timestamp_ns - (r.FPI - r.first_sample_number) for r in data.received_data]
00095         base_min = min(base)
00096         print base, base_min
00097 
00098         base = [b - base_min for b in base]
00099         print base
00100 
00101         for receiver, ax in zip(data.received_data, self.axes):
00102             ax.clear()
00103             ax.set_xlim([0, 64])
00104             # ax.set_ylim([-32768,32768])
00105             y1 = []
00106             y2 = []
00107             y3 = []
00108             x = []
00109             x_value = base[receiver_index]
00110 
00111             for impulse in receiver.impulse_response:
00112                 y1.append(impulse.real)
00113                 y2.append(impulse.imaginary)
00114                 y3.append(sqrt(impulse.real**2 + impulse.imaginary**2))
00115                 x.append(x_value)
00116                 x_value = x_value + 1
00117 
00118             # x = range(receiver*10, len(y1)+(receiver*10))
00119             # x = range(0, len(y1))
00120             ax.set_ylim([min(min(y2), min(y1)), max(y3)])
00121             self.line1 = ax.plot(x, y1, c='#A0A0FF', label="real")
00122             self.line1 = ax.plot(x, y2, c='#A0FFA0', label="imag")
00123             self.line1 = ax.plot(x, y3, c='#A00000', label="magn")
00124             ax.legend(loc=0, scatterpoints=1)
00125             # ax.set_title("Impulse Response["+str(receiver_index)+"]")
00126             receiver_index += 1
00127 
00128         self.canvas.draw()
00129 
00130 if __name__ == "__main__":
00131     app = QApplication(sys.argv)
00132     window = TCATPlot()
00133     window.show()
00134     app.exec_()


sr_ronex_utilities
Author(s): Ugo Cupcic, Toni Oliver, Mark Pitchless
autogenerated on Thu Jun 6 2019 21:21:58