pr2_dashboard.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2012, Willow Garage, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of Willow Garage, Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 
33 import argparse
34 import roslib
35 roslib.load_manifest('rqt_pr2_dashboard')
36 import rospy
37 
38 from pr2_msgs.msg import PowerBoardState, DashboardState
39 import std_srvs.srv
40 
41 from rqt_robot_dashboard.dashboard import Dashboard
42 from rqt_robot_dashboard.monitor_dash_widget import MonitorDashWidget
43 from rqt_robot_dashboard.console_dash_widget import ConsoleDashWidget
44 
45 from python_qt_binding.QtCore import QSize
46 try:
47  from python_qt_binding.QtGui import QMessageBox
48 except:
49  from python_qt_binding.QtWidgets import QMessageBox
50 
51 from .pr2_breaker import PR2BreakerButton
52 from .pr2_battery import PR2Battery
53 from .pr2_motors import PR2Motors
54 from .pr2_runstop import PR2Runstops
55 
56 
58  """
59  Dashboard for PR2s
60 
61  :param context: the plugin context
62  :type context: qt_gui.plugin.Plugin
63  """
64  def setup(self, context):
65  self.name = 'PR2 Dashboard'
66  self.max_icon_size = QSize(50, 30)
67  self.message = None
68 
69  parser = argparse.ArgumentParser(prog='pr2_dashboard', add_help=False)
70  PR2Dashboard.add_arguments(parser)
71  args = parser.parse_args(context.argv())
72  self._motor_namespace = args.motor_namespace
73 
74  self._dashboard_message = None
76 
77  self._raw_byte = None
78  self.digital_outs = [0, 0, 0]
79 
80  self._console = ConsoleDashWidget(self.context, minimal=False)
82  self._motors = PR2Motors(self.on_reset_motors, self.on_halt_motors)
83  self._breakers = [PR2BreakerButton('Left Arm', 0),
84  PR2BreakerButton('Base', 1),
85  PR2BreakerButton('Right Arm', 2)]
86 
87  self._runstop = PR2Runstops('RunStops')
88  self._batteries = [PR2Battery(self.context)]
89 
90  self._dashboard_agg_sub = rospy.Subscriber('dashboard_agg', DashboardState, self.dashboard_callback)
91 
92  def get_widgets(self):
93  return [[self._monitor, self._console, self._motors], self._breakers, [self._runstop], self._batteries]
94 
95  def dashboard_callback(self, msg):
96  """
97  callback to process dashboard_agg messages
98 
99  :param msg: dashboard_agg DashboardState message
100  :type msg: pr2_msgs.msg.DashboardState
101  """
102  self._dashboard_message = msg
103  self._last_dashboard_message_time = rospy.get_time()
104 
105  if (msg.motors_halted_valid):
106  if (not msg.motors_halted.data):
107  self._motors.set_ok()
108  self._motors.setToolTip(self.tr("Motors: Running"))
109  else:
110  self._motors.set_error()
111  self._motors.setToolTip(self.tr("Motors: Halted"))
112  else:
113  self._motors.set_stale()
114  self._motors.setToolTip(self.tr("Motors: Stale"))
115 
116  if (msg.power_state_valid):
117  self._batteries[0].set_power_state(msg.power_state)
118  else:
119  self._batteries[0].set_stale()
120 
121  if (msg.power_board_state_valid):
122  [breaker.set_power_board_state_msg(msg.power_board_state) for breaker in self._breakers]
123  if msg.power_board_state.run_stop:
124  self._runstop.set_ok()
125  self._runstop.setToolTip(self.tr("Physical Runstop: OK\nWireless Runstop: OK"))
126  elif msg.power_board_state.wireless_stop:
127  self._runstop.set_physical_engaged()
128  self._runstop.setToolTip(self.tr("Physical Runstop: Pressed\nWireless Runstop: OK"))
129  if not msg.power_board_state.wireless_stop:
130  self._runstop.set_wireless_engaged()
131  self._runstop.setToolTip(self.tr("Physical Runstop: Unknown\nWireless Runstop: Pressed"))
132  else:
133  [breaker.reset() for breaker in self._breakers]
134  self._runstop.set_stale()
135  self._runstop.setToolTip(self.tr("Physical Runstop: Stale\nWireless Runstop: Stale"))
136 
137  def on_reset_motors(self):
138  # if any of the breakers is not enabled ask if they'd like to enable them
139  if (self._dashboard_message is not None and self._dashboard_message.power_board_state_valid):
140  all_breakers_enabled = reduce(lambda x, y: x and y, [state == PowerBoardState.STATE_ON for state in self._dashboard_message.power_board_state.circuit_state])
141  if (not all_breakers_enabled):
142  if(QMessageBox.question(self._breakers[0], self.tr('Enable Breakers?'), self.tr("Resetting the motors may not work because not all breakers are enabled. Enable all the breakers first?"), QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) == QMessageBox.Yes):
143  [breaker.set_enable() for breaker in self._breakers]
144  reset = rospy.ServiceProxy("{}/reset_motors".format(self._motor_namespace), std_srvs.srv.Empty)
145  try:
146  reset()
147  except rospy.ServiceException, e:
148  QMessageBox.critical(self._breakers[0], "Error", "Failed to reset the motors: service call failed with error: %s" % (e))
149 
150  def on_halt_motors(self):
151  halt = rospy.ServiceProxy("{}/halt_motors".format(self._motor_namespace), std_srvs.srv.Empty)
152  try:
153  halt()
154  except rospy.ServiceException, e:
155  QMessageBox.critical(self._motors, "Error", "Failed to halt the motors: service call failed with error: %s" % (e))
156 
158  self._dashboard_agg_sub.unregister()
159 
160  @staticmethod
161  def add_arguments(parser):
162  group = parser.add_argument_group('Options for pr2_dashboard')
163  group.add_argument(
164  '--motor-namespace', dest='motor_namespace',
165  type=str, default='pr2_ethercat')
166 
167  def save_settings(self, plugin_settings, instance_settings):
168  self._console.save_settings(plugin_settings, instance_settings)
169  self._monitor.save_settings(plugin_settings, instance_settings)
170 
171  def restore_settings(self, plugin_settings, instance_settings):
172  self._console.restore_settings(plugin_settings, instance_settings)
173  self._monitor.restore_settings(plugin_settings, instance_settings)
def save_settings(self, plugin_settings, instance_settings)
def restore_settings(self, plugin_settings, instance_settings)


rqt_pr2_dashboard
Author(s): Aaron Blasdel
autogenerated on Fri Dec 11 2020 03:39:03