TrackerBaseUi.py
Go to the documentation of this file.
00001 import os
00002 import rospy
00003 import rospkg
00004 import math
00005 
00006 from PyQt4 import QtGui, QtCore
00007 from qt_gui.plugin import Plugin
00008 from python_qt_binding import loadUi
00009 from python_qt_binding.QtCore import QEvent, QModelIndex, QObject, Qt, QTimer, Signal, Slot
00010 from python_qt_binding.QtGui import QShortcut, QTableWidgetItem, QWidget, QLCDNumber, QItemDelegate, QAbstractItemView
00011 from rospy import Time
00012 from std_msgs.msg import Bool
00013 from std_msgs.msg import Float64, Float32, Empty
00014 
00015 
00016 class TrackerBaseUi(QObject):
00017     _update_task_delegates = Signal()
00018     
00019     def __init__(self, context):
00020         QObject.__init__(self, context)
00021         self.setObjectName('TrackerBaseUi')
00022 
00023         # setup publisher
00024         self._WhiteLightPublisher = rospy.Publisher('/light', Bool)
00025         self._BlueLightPublisher = rospy.Publisher('/bluelight', Bool)
00026         self._EmptyPublisher = rospy.Publisher('/init_flipper', Empty)
00027 
00028         self._FlipperStateSubsciber = rospy.Subscriber('/flipper_control/state', Float64, self._on_flipper_state)
00029 
00030         # setup main widget
00031         self._widget = QWidget()
00032         ui_file = os.path.join(rospkg.RosPack().get_path('tracker_base_ui'), 'lib', 'TrackerBaseUi.ui')
00033         loadUi(ui_file, self._widget)
00034         self._widget.setObjectName('TrackerBaseUi')
00035 
00036         #set connections
00037         self._widget.white_checkBox.stateChanged.connect(self._on_white_changed)
00038         self._widget.blue_checkBox.stateChanged.connect(self._on_blue_changed)
00039 
00040         # Show _widget.windowTitle on left-top of each plugin (when 
00041         # it's set in _widget). This is useful when you open multiple 
00042         # plugins at once. Also if you open multiple instances of your 
00043         # plugin at once, these lines add number to make it easy to 
00044         # tell from pane to pane.
00045         if context.serial_number() > 1:
00046             self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))
00047         # Add widget to the user interface
00048         context.add_widget(self._widget)
00049 
00050         # setup subscribers  
00051         self._trackerSupplySubscriber = rospy.Subscriber("/supply_voltage", Float32, self._on_tracker_supply)
00052         
00053 
00054         # connect Signal Slot
00055         self._update_task_delegates.connect(self._on_update_task_delegates)
00056         self._widget.empty_button.pressed.connect(self._on_empty_pressed) 
00057         self.supply = -1
00058         self._widget.supply_lineEdit.setText('unknown')
00059         # init percept model
00060 
00061         self.flipper_scene = QtGui.QGraphicsScene(self)
00062         self.flipper_scene.setSceneRect(QtCore.QRectF(-200, -200, 200, 200))
00063 
00064         self._widget.graphicsView_Flipper.setScene(self.flipper_scene)
00065         self.flipper_state = 0;
00066         rospy.Timer(rospy.Duration(0.1), self.draw_flipper_state)
00067         
00068     def _on_tracker_supply(self, message):
00069         self.supply = message.data
00070         self._update_task_delegates.emit()
00071 
00072     def _on_flipper_state(self, message):
00073         self.flipper_state = message.data
00074 
00075     def shutdown_plugin(self):
00076         # TODO unregister all publishers here
00077         pass
00078 
00079     def save_settings(self, plugin_settings, instance_settings):
00080         # TODO save intrinsic configuration, usually using:
00081         # instance_settings.set_value(k, v)
00082         pass
00083 
00084     def restore_settings(self, plugin_settings, instance_settings):
00085         # TODO restore intrinsic configuration, usually using:
00086         # v = instance_settings.value(k)
00087         pass
00088    
00089     def _on_white_changed(self,value):
00090         self._WhiteLightPublisher.publish(value)
00091 
00092     def _on_blue_changed(self,value):
00093         self._BlueLightPublisher.publish(value)
00094 
00095     def _on_empty_pressed(self):
00096         self._EmptyPublisher.publish(Empty())
00097     
00098 
00099     def _on_update_task_delegates(self):
00100         if (self.supply == -1) :
00101             self._widget.supply_lineEdit.setText('unknown')
00102         else:
00103             self._widget.supply_lineEdit.setText(str(self.supply))
00104 
00105     def draw_flipper_state(self, event):
00106 
00107         length = 100
00108         y = length * math.cos(-self.flipper_state)
00109         x = length * math.sin(-self.flipper_state)
00110 
00111         self.flipper_scene.clear()
00112 
00113         item = QtGui.QGraphicsEllipseItem(-25, -25, 50, 50)
00114         self.flipper_scene.addItem(item)
00115 
00116         item = QtGui.QGraphicsLineItem(0, 0, -y, x)
00117         self.flipper_scene.addItem(item)
00118 
00119         self._widget.graphicsView_Flipper.show()
00120 
00121         item = QtGui.QGraphicsLineItem(0, 0, -100, 10)
00122         #self.flipper_scene.addItem(item)
00123 
00124         item = QtGui.QGraphicsLineItem(0, 0, -100, -10)
00125         #self.flipper_scene.addItem(item)
00126 
00127 
00128 


tracker_base_ui
Author(s):
autogenerated on Thu Aug 27 2015 13:22:47