balance_mode_widget.py
Go to the documentation of this file.
1 import os
2 import rospy
3 import rospkg
4 import rosservice
5 
6 import rsv_balance_msgs.srv
7 
8 from qt_gui.plugin import Plugin
9 from python_qt_binding import loadUi
10 from python_qt_binding.QtGui import QWidget
11 
12 
14  def __init__(self, context):
15  super(BalanceModeWidget, self).__init__(context)
16  # Give QObjects reasonable names
17  self.setObjectName('BalanceMode')
18 
19  # Process standalone plugin command-line arguments
20  from argparse import ArgumentParser
21  parser = ArgumentParser()
22  # Add argument(s) to the parser.
23  parser.add_argument("-q", "--quiet", action="store_true",
24  dest="quiet",
25  help="Put plugin in silent mode")
26  args, unknowns = parser.parse_known_args(context.argv())
27  if not args.quiet:
28  print 'arguments: ', args
29  print 'unknowns: ', unknowns
30 
31  # Create QWidget
32  self._widget = QWidget()
33  # Get path to UI file which should be in the "resource" folder of this package
34  ui_file = os.path.join(rospkg.RosPack().get_path('rsv_balance_rqt'), 'resource', 'BalanceModeWidget.ui')
35  # Extend the widget with all attributes and children from UI file
36  loadUi(ui_file, self._widget)
37  # Give QObjects reasonable names
38  self._widget.setObjectName('BalanceModeWidgetUI')
39  # Numerated windowTitle
40  if context.serial_number() > 1:
41  self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))
42  # Add widget to the user interface
43  context.add_widget(self._widget)
44 
45  self._widget.set_park.clicked[bool].connect(self.on_set_park_button)
46  self._widget.set_tractor.clicked[bool].connect(self.on_set_tractor_button)
47  self._widget.set_balance.clicked[bool].connect(self.on_set_balance_button)
48 
49  self._widget.topic_line_edit.textChanged.connect(self.on_topic_changed)
50 
51  # Set mode client
52  self.set_mode_srv = None
53  self.on_topic_changed()
54 
55  def shutdown_plugin(self):
56  pass
57 
58  def save_settings(self, plugin_settings, instance_settings):
59  instance_settings.set_value('topic', self._widget.topic_line_edit.text())
60 
61  def restore_settings(self, plugin_settings, instance_settings):
62  value = instance_settings.value('topic', "/set_mode")
63  self._widget.topic_line_edit.setText(value)
64 
65  def on_set_park_button(self):
66  try:
67  self.set_mode_srv(rsv_balance_msgs.srv.SetModeRequest.PARK)
68  except rospy.ServiceException, e:
69  rospy.logwarn("Service call failed: %s" % e)
70 
72  try:
73  self.set_mode_srv(rsv_balance_msgs.srv.SetModeRequest.TRACTOR)
74  except rospy.ServiceException, e:
75  rospy.logwarn("Service call failed: %s" % e)
76 
78  try:
79  self.set_mode_srv(rsv_balance_msgs.srv.SetModeRequest.BALANCE)
80  except rospy.ServiceException, e:
81  rospy.logwarn("Service call failed: %s" % e)
82 
83  def on_topic_changed(self):
84  # self._widget.set_park.setEnabled(False)
85  # self._widget.set_tractor.setEnabled(False)
86  # self._widget.set_balance.setEnabled(False)
87 
88  topic = self._widget.topic_line_edit.text()
89 
90  if self.set_mode_srv is not None:
91  self.set_mode_srv.close()
92  self.set_mode_srv = None
93 
94  if not topic == "":
95  # try:
96  # rospy.wait_for_service('/set_mode', 2)
97  # self._widget.set_park.setEnabled(True)
98  # self._widget.set_tractor.setEnabled(True)
99  # self._widget.set_balance.setEnabled(True)
100  # except rospy.ROSException, e:
101  # rospy.logwarn("Changing topic exception: %s" % e)
102 
103  self.set_mode_srv = rospy.ServiceProxy(topic, rsv_balance_msgs.srv.SetMode)
def restore_settings(self, plugin_settings, instance_settings)
def save_settings(self, plugin_settings, instance_settings)


rsv_balance_rqt
Author(s): Vitor Matos
autogenerated on Mon Jun 10 2019 15:04:12