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)
81  self._console._show_console()
82 
84  self._monitor._show_monitor()
85 
87  self._breakers = [PR2BreakerButton('Left Arm', 0),
88  PR2BreakerButton('Base', 1),
89  PR2BreakerButton('Right Arm', 2)]
90 
91  self._runstop = PR2Runstops('RunStops')
92  self._batteries = [PR2Battery(self.context)]
93 
94  self._dashboard_agg_sub = rospy.Subscriber('dashboard_agg', DashboardState, self.dashboard_callback)
95 
96  def get_widgets(self):
97  return [[self._monitor, self._console, self._motors], self._breakers, [self._runstop], self._batteries]
98 
99  def dashboard_callback(self, msg):
100  """
101  callback to process dashboard_agg messages
102 
103  :param msg: dashboard_agg DashboardState message
104  :type msg: pr2_msgs.msg.DashboardState
105  """
106  self._dashboard_message = msg
107  self._last_dashboard_message_time = rospy.get_time()
108 
109  if (msg.motors_halted_valid):
110  if (not msg.motors_halted.data):
111  self._motors.set_ok()
112  self._motors.setToolTip(self.tr("Motors: Running"))
113  else:
114  self._motors.set_error()
115  self._motors.setToolTip(self.tr("Motors: Halted"))
116  else:
117  self._motors.set_stale()
118  self._motors.setToolTip(self.tr("Motors: Stale"))
119 
120  if (msg.power_state_valid):
121  self._batteries[0].set_power_state(msg.power_state)
122  else:
123  self._batteries[0].set_stale()
124 
125  if (msg.power_board_state_valid):
126  [breaker.set_power_board_state_msg(msg.power_board_state) for breaker in self._breakers]
127  if msg.power_board_state.run_stop:
128  self._runstop.set_ok()
129  self._runstop.setToolTip(self.tr("Physical Runstop: OK\nWireless Runstop: OK"))
130  elif msg.power_board_state.wireless_stop:
131  self._runstop.set_physical_engaged()
132  self._runstop.setToolTip(self.tr("Physical Runstop: Pressed\nWireless Runstop: OK"))
133  if not msg.power_board_state.wireless_stop:
134  self._runstop.set_wireless_engaged()
135  self._runstop.setToolTip(self.tr("Physical Runstop: Unknown\nWireless Runstop: Pressed"))
136  else:
137  [breaker.reset() for breaker in self._breakers]
138  self._runstop.set_stale()
139  self._runstop.setToolTip(self.tr("Physical Runstop: Stale\nWireless Runstop: Stale"))
140 
141  def on_reset_motors(self):
142  # if any of the breakers is not enabled ask if they'd like to enable them
143  if (self._dashboard_message is not None and self._dashboard_message.power_board_state_valid):
144  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])
145  if (not all_breakers_enabled):
146  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):
147  [breaker.set_enable() for breaker in self._breakers]
148  reset = rospy.ServiceProxy("{}/reset_motors".format(self._motor_namespace), std_srvs.srv.Empty)
149  try:
150  reset()
151  except rospy.ServiceException as e:
152  QMessageBox.critical(self._breakers[0], "Error", "Failed to reset the motors: service call failed with error: %s" % (e))
153 
154  def on_halt_motors(self):
155  halt = rospy.ServiceProxy("{}/halt_motors".format(self._motor_namespace), std_srvs.srv.Empty)
156  try:
157  halt()
158  except rospy.ServiceException as e:
159  QMessageBox.critical(self._motors, "Error", "Failed to halt the motors: service call failed with error: %s" % (e))
160 
162  self._dashboard_agg_sub.unregister()
163 
164  @staticmethod
165  def add_arguments(parser):
166  group = parser.add_argument_group('Options for pr2_dashboard')
167  group.add_argument(
168  '--motor-namespace', dest='motor_namespace',
169  type=str, default='pr2_ethercat')
170 
171  def save_settings(self, plugin_settings, instance_settings):
172  self._console.save_settings(plugin_settings, instance_settings)
173  self._monitor.save_settings(plugin_settings, instance_settings)
174 
175  def restore_settings(self, plugin_settings, instance_settings):
176  self._console.restore_settings(plugin_settings, instance_settings)
177  self._monitor.restore_settings(plugin_settings, instance_settings)
rqt_pr2_dashboard.pr2_runstop.PR2Runstops
Definition: pr2_runstop.py:37
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard.on_reset_motors
def on_reset_motors(self)
Definition: pr2_dashboard.py:141
rqt_robot_dashboard::dashboard
rqt_robot_dashboard::console_dash_widget::ConsoleDashWidget
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard._motor_namespace
_motor_namespace
Definition: pr2_dashboard.py:72
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard._runstop
_runstop
Definition: pr2_dashboard.py:91
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard._breakers
_breakers
Definition: pr2_dashboard.py:87
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard.digital_outs
digital_outs
Definition: pr2_dashboard.py:78
rqt_robot_dashboard::monitor_dash_widget
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard.save_settings
def save_settings(self, plugin_settings, instance_settings)
Definition: pr2_dashboard.py:171
rqt_pr2_dashboard.pr2_battery.PR2Battery
Definition: pr2_battery.py:39
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard.dashboard_callback
def dashboard_callback(self, msg)
Definition: pr2_dashboard.py:99
rqt_robot_dashboard::dashboard::Dashboard::context
context
rqt_robot_dashboard::dashboard::Dashboard
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard.on_halt_motors
def on_halt_motors(self)
Definition: pr2_dashboard.py:154
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard.restore_settings
def restore_settings(self, plugin_settings, instance_settings)
Definition: pr2_dashboard.py:175
rqt_pr2_dashboard.pr2_breaker.PR2BreakerButton
Definition: pr2_breaker.py:47
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard.shutdown_dashboard
def shutdown_dashboard(self)
Definition: pr2_dashboard.py:161
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard._raw_byte
_raw_byte
Definition: pr2_dashboard.py:77
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard._motors
_motors
Definition: pr2_dashboard.py:86
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard.setup
def setup(self, context)
Definition: pr2_dashboard.py:64
rqt_robot_dashboard::dashboard::Dashboard::name
name
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard.get_widgets
def get_widgets(self)
Definition: pr2_dashboard.py:96
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard.add_arguments
def add_arguments(parser)
Definition: pr2_dashboard.py:165
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard._dashboard_agg_sub
_dashboard_agg_sub
Definition: pr2_dashboard.py:94
rqt_robot_dashboard::console_dash_widget
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard._batteries
_batteries
Definition: pr2_dashboard.py:92
rqt_robot_dashboard::dashboard::Dashboard::max_icon_size
max_icon_size
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard._dashboard_message
_dashboard_message
Definition: pr2_dashboard.py:74
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard
Definition: pr2_dashboard.py:57
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard.message
message
Definition: pr2_dashboard.py:67
rqt_robot_dashboard::monitor_dash_widget::MonitorDashWidget
rqt_pr2_dashboard.pr2_motors.PR2Motors
Definition: pr2_motors.py:37
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard._last_dashboard_message_time
_last_dashboard_message_time
Definition: pr2_dashboard.py:75
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard._monitor
_monitor
Definition: pr2_dashboard.py:83
rqt_pr2_dashboard.pr2_dashboard.PR2Dashboard._console
_console
Definition: pr2_dashboard.py:80


rqt_pr2_dashboard
Author(s): Aaron Blasdel
autogenerated on Fri Jul 26 2024 02:34:09