joy_gui.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
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 sensor_msgs.msg import Joy
00017 from auv_msgs.msg import NavSts
00018            
00019 class JoyGui(QtGui.QWidget):
00020    
00021     def __init__(self):
00022         #Init the base class
00023         QtGui.QWidget.__init__(self)
00024 
00025     def setup(self, name, ros):
00026         self.setObjectName(name)
00027         self.setWindowTitle(name)
00028         self._setup();
00029         self._connect_signals(ros)   
00030     
00031     def unload(self):
00032         pass
00033     
00034     def _connect_signals(self, ros):
00035         self.surgeSlider.valueChanged.connect(ros.onSurgeChanged)
00036         self.swaySlider.valueChanged.connect(ros.onSwayChanged)
00037         self.torqueSlider.valueChanged.connect(ros.onTorqueChanged)
00038         self.stopButton.clicked.connect(self.onStop)
00039         
00040            
00041     @QtCore.pyqtSlot()   
00042     def onStop(self):
00043         self.surgeSlider.setValue(0)
00044         self.swaySlider.setValue(0)
00045         self.torqueSlider.setValue(0)
00046                                  
00047     def _setup(self):
00048         pass
00049 
00050 class JoyGuiROS(QtCore.QObject):
00051             
00052         def __init__(self):
00053             QtCore.QObject.__init__(self)
00054             
00055             self.joyPub = rospy.Publisher("joy", Joy)
00056             self.joyOut = Joy()
00057             self.joyOut.axes = [0,0,0,0,0,0]
00058         
00059         def setup(self, gui):
00060             self._connect_signals(gui)
00061             self._subscribe()
00062             pass
00063         
00064         @QtCore.pyqtSlot(int)
00065         def onSurgeChanged(self, value):
00066             self.joyOut.axes[1] = value/100.0;
00067             
00068         @QtCore.pyqtSlot(int)
00069         def onSwayChanged(self, value):
00070             self.joyOut.axes[0] = -value/100.0;
00071             
00072         @QtCore.pyqtSlot(int)
00073         def onTorqueChanged(self, value):
00074             self.joyOut.axes[2] = -value/100.0;
00075             
00076         def publish(self):
00077             self.joyPub.publish(self.joyOut)            
00078         
00079         def unload(self):
00080             self.state.unregister();e
00081             self.joyPub.unregister();
00082             pass
00083 
00084         def _connect_signals(self, gui):
00085             pass
00086         
00087         def onNavSts(self,data):
00088             self.publish()
00089             
00090         def _subscribe(self):
00091             self.state = rospy.Subscriber("stateHat",NavSts,self.onNavSts)
00092             pass
00093                                             
00094         def _unsubscribe(self):
00095             pass
00096 
00097 
00098 class JoyRqt(Plugin):
00099     def __init__(self, context):
00100         name = "Joy"
00101         resource = os.path.join(os.path.dirname(
00102                         os.path.realpath(__file__)), 
00103                         "resource/" + name + ".ui")
00104         GuiT = JoyGui
00105         RosT = JoyGuiROS
00106         
00107         super(JoyRqt, self).__init__(context)
00108         self.setObjectName(name)
00109 
00110         from argparse import ArgumentParser
00111         parser = ArgumentParser()
00112         parser.add_argument("-q", "--quiet", action="store_true",
00113                       dest="quiet",
00114                       help="Put plugin in silent mode")
00115         args, unknowns = parser.parse_known_args(context.argv())
00116         if not args.quiet:
00117             print("arguments: ", args)
00118             print("unknowns: ", unknowns)
00119 
00120         # Create QWidget
00121         self._gui = GuiT()
00122         self._ros = RosT()
00123 
00124         loadUi(resource, self._gui)
00125         self._ros.setup(self._gui)
00126         self._gui.setup(name + "Rqt", self._ros)
00127 
00128         if context.serial_number() > 1:
00129             self._widget.setWindowTitle(self._widget.windowTitle() + 
00130                                         (" (%d)" % context.serial_number()))
00131         context.add_widget(self._gui) 
00132 
00133 if __name__ == '__main__':
00134     from labust_rqt import rqt_plugin_meta
00135     name = "Joy"
00136     resource = rqt_plugin_meta.resource_rpath(name, __file__)
00137     rqt_plugin_meta.launch_standalone(name = name,
00138                     GuiT = JoyGui,
00139                     RosT = JoyROS,
00140                     resource = resource);     


labust_gui
Author(s): Gyula Nagy
autogenerated on Sun Mar 1 2015 12:12:46