Go to the documentation of this file.00001
00002 '''
00003 Created on Sep 10, 2013
00004 \todo Add license information here
00005 @author: dnad
00006 '''
00007 from __future__ import print_function
00008 import os, sys
00009
00010 import rospy
00011 import labust_gui
00012
00013 from python_qt_binding import loadUi, QtCore, QtGui
00014 from qt_gui.plugin import Plugin
00015
00016 from navcon_msgs.srv import RegisterController_v3
00017 from navcon_msgs.srv import RegisterController_v3Response
00018 from navcon_msgs.msg import ControllerState
00019 from navcon_msgs.msg import ControllerInfo
00020
00021 from std_msgs.msg import String
00022
00023 class ConMonGui(QtGui.QWidget):
00024
00025 onSendState = QtCore.pyqtSignal(object, int, name='onSendState')
00026
00027 def __init__(self):
00028
00029 QtGui.QWidget.__init__(self)
00030
00031 self.parents = dict();
00032
00033 def setup(self, name, ros):
00034 self.setObjectName(name)
00035 self.setWindowTitle(name)
00036 self._setup();
00037 self._connect_signals(ros)
00038
00039 @QtCore.pyqtSlot(object)
00040 def onNewController(self, req):
00041 if not self.parents.has_key(req.parent):
00042 self.parents[req.parent] = QtGui.QTreeWidgetItem()
00043 self.parents[req.parent].setText(0, req.parent)
00044 self.controllerTree.addTopLevelItem(self.parents[req.parent])
00045
00046 item = QtGui.QTreeWidgetItem()
00047 item.setText(0, req.name)
00048 self.parents[req.parent].addChild(item)
00049
00050 @QtCore.pyqtSlot()
00051 def onSend(self):
00052 self.onSendState.emit(self.nameEdit.text(), self.stateCombo.currentIndex())
00053
00054 def unload(self):
00055 pass
00056
00057 def _connect_signals(self, ros):
00058 self.sendButton.clicked.connect(self.onSend)
00059 self.onSendState.connect(ros.onNewState)
00060 pass
00061
00062 def _setup(self):
00063 self.stateCombo.addItem("DISABLED")
00064 self.stateCombo.addItem("MANUAL")
00065 self.stateCombo.addItem("EXTERNAL")
00066 self.stateCombo.addItem("TRACKING")
00067 pass
00068
00069
00070 class ConMonROS(QtCore.QObject):
00071 onNewController = QtCore.pyqtSignal(object, name = "onNewController")
00072
00073 def __init__(self):
00074 QtCore.QObject.__init__(self)
00075
00076 def setup(self, gui):
00077 self._connect_signals(gui)
00078 self._subscribe()
00079 pass
00080
00081 def unload(self):
00082 pass
00083
00084 def _connect_signals(self, gui):
00085 self.onNewController.connect(gui.onNewController)
00086 pass
00087
00088 def onRegisterController(self, req):
00089 self.onNewController.emit(req)
00090 return RegisterController_v3Response()
00091
00092 @QtCore.pyqtSlot(object, int)
00093 def onNewState(self, name, state):
00094 out = ControllerState()
00095 out.name = [name];
00096 info = ControllerInfo()
00097 info.state = state
00098 out.info = [info]
00099 self.stateOut.publish(out)
00100
00101 def _subscribe(self):
00102 self.srv = rospy.Service('register_controller',
00103 RegisterController_v3,
00104 self.onRegisterController)
00105 self.stateOut = rospy.Publisher('controller_state',ControllerState)
00106
00107
00108 def _unsubscribe(self):
00109 pass
00110
00111
00112 class ConMonRqt(Plugin):
00113 def __init__(self, context):
00114 name = "ConMon"
00115 resource = os.path.join(os.path.dirname(
00116 os.path.realpath(__file__)),
00117 "resource/" + name + ".ui")
00118 GuiT = ConMonGui
00119 RosT = ConMonROS
00120
00121 super(ConMonRqt, self).__init__(context)
00122 self.setObjectName(name)
00123
00124 from argparse import ArgumentParser
00125 parser = ArgumentParser()
00126 parser.add_argument("-q", "--quiet", action="store_true",
00127 dest="quiet",
00128 help="Put plugin in silent mode")
00129 args, unknowns = parser.parse_known_args(context.argv())
00130 if not args.quiet:
00131 print("arguments: ", args)
00132 print("unknowns: ", unknowns)
00133
00134
00135 self._gui = GuiT()
00136 self._ros = RosT()
00137
00138 loadUi(resource, self._gui)
00139 self._ros.setup(self._gui)
00140 self._gui.setup(name + "Rqt", self._ros)
00141
00142 if context.serial_number() > 1:
00143 self._widget.setWindowTitle(self._widget.windowTitle() +
00144 (" (%d)" % context.serial_number()))
00145 context.add_widget(self._gui)
00146
00147 if __name__ == '__main__':
00148 from labust_rqt import rqt_plugin_meta
00149 name = "ConMon"
00150 resource = rqt_plugin_meta.resource_rpath(name, __file__)
00151 rqt_plugin_meta.launch_standalone(name = name,
00152 GuiT = IdentificationGui,
00153 RosT = IdentificationROS,
00154 resource = resource);