Go to the documentation of this file.00001 import os
00002 import rospy
00003 import rospkg
00004 import rosservice
00005
00006 import rsv_balance_msgs.srv
00007
00008 from qt_gui.plugin import Plugin
00009 from python_qt_binding import loadUi
00010 from python_qt_binding.QtGui import QWidget
00011
00012
00013 class BalanceModeWidget(Plugin):
00014 def __init__(self, context):
00015 super(BalanceModeWidget, self).__init__(context)
00016
00017 self.setObjectName('BalanceMode')
00018
00019
00020 from argparse import ArgumentParser
00021 parser = ArgumentParser()
00022
00023 parser.add_argument("-q", "--quiet", action="store_true",
00024 dest="quiet",
00025 help="Put plugin in silent mode")
00026 args, unknowns = parser.parse_known_args(context.argv())
00027 if not args.quiet:
00028 print 'arguments: ', args
00029 print 'unknowns: ', unknowns
00030
00031
00032 self._widget = QWidget()
00033
00034 ui_file = os.path.join(rospkg.RosPack().get_path('rsv_balance_rqt'), 'resource', 'BalanceModeWidget.ui')
00035
00036 loadUi(ui_file, self._widget)
00037
00038 self._widget.setObjectName('BalanceModeWidgetUI')
00039
00040 if context.serial_number() > 1:
00041 self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))
00042
00043 context.add_widget(self._widget)
00044
00045 self._widget.set_park.clicked[bool].connect(self.on_set_park_button)
00046 self._widget.set_tractor.clicked[bool].connect(self.on_set_tractor_button)
00047 self._widget.set_balance.clicked[bool].connect(self.on_set_balance_button)
00048
00049 self._widget.topic_line_edit.textChanged.connect(self.on_topic_changed)
00050
00051
00052 self.set_mode_srv = None
00053 self.on_topic_changed()
00054
00055 def shutdown_plugin(self):
00056 pass
00057
00058 def save_settings(self, plugin_settings, instance_settings):
00059 instance_settings.set_value('topic', self._widget.topic_line_edit.text())
00060
00061 def restore_settings(self, plugin_settings, instance_settings):
00062 value = instance_settings.value('topic', "/set_mode")
00063 self._widget.topic_line_edit.setText(value)
00064
00065 def on_set_park_button(self):
00066 try:
00067 self.set_mode_srv(rsv_balance_msgs.srv.SetModeRequest.PARK)
00068 except rospy.ServiceException, e:
00069 rospy.logwarn("Service call failed: %s" % e)
00070
00071 def on_set_tractor_button(self):
00072 try:
00073 self.set_mode_srv(rsv_balance_msgs.srv.SetModeRequest.TRACTOR)
00074 except rospy.ServiceException, e:
00075 rospy.logwarn("Service call failed: %s" % e)
00076
00077 def on_set_balance_button(self):
00078 try:
00079 self.set_mode_srv(rsv_balance_msgs.srv.SetModeRequest.BALANCE)
00080 except rospy.ServiceException, e:
00081 rospy.logwarn("Service call failed: %s" % e)
00082
00083 def on_topic_changed(self):
00084
00085
00086
00087
00088 topic = self._widget.topic_line_edit.text()
00089
00090 if self.set_mode_srv is not None:
00091 self.set_mode_srv.close()
00092 self.set_mode_srv = None
00093
00094 if not topic == "":
00095
00096
00097
00098
00099
00100
00101
00102
00103 self.set_mode_srv = rospy.ServiceProxy(topic, rsv_balance_msgs.srv.SetMode)