34 from python_qt_binding.QtCore
import QSize
36 from pr2_msgs.msg
import PowerBoardState
37 from pr2_power_board.srv
import PowerBoardCommand, PowerBoardCommandRequest
42 from python_qt_binding.QtGui
import QMessageBox
44 from python_qt_binding.QtWidgets
import QMessageBox
49 Dashboard widget to display and interact with the PR2 Breaker state.
51 def __init__(self, breaker_name, breaker_index):
53 :param breaker_name: Name of the breaker
54 :type breaker_name: str
55 :param breaker_index: Index of the breaker
56 :type breaker_index: int
59 if breaker_name ==
'Left Arm':
60 breaker_icon =
'ic-larm.svg'
61 elif breaker_name ==
'Base':
62 breaker_icon =
'ic-base.svg'
63 elif breaker_name ==
'Right Arm':
64 breaker_icon =
'ic-rarm.svg'
66 breaker_icon =
'ic-breaker.svg'
68 ok_icon = [
'bg-green.svg', breaker_icon]
69 warn_icon = [
'bg-yellow.svg', breaker_icon,
'ol-warn-badge.svg']
70 err_icon = [
'bg-red.svg', breaker_icon,
'ol-err-badge.svg']
71 stale_icon = [
'bg-grey.svg', breaker_icon,
'ol-stale-badge.svg']
73 icons = [ok_icon, warn_icon, err_icon, stale_icon]
75 super(PR2BreakerButton, self).
__init__(
'Breaker:' + breaker_name, icons=icons, icon_paths=[[
'rqt_pr2_dashboard',
'images']])
78 self.setFixedSize(self._icons[0].actualSize(QSize(50, 30)))
88 self.
_power_control = rospy.ServiceProxy(
'power_board/control', PowerBoardCommand)
94 self.setToolTip(breaker_name)
98 Sends a PowerBoardCommand srv to the pr2
100 :param breaker: breaker index to send command to
102 :param cmd: command to be sent to the pr2 breaker
106 QMessageBox.critical(self,
"Error", self.tr(
"Cannot control breakers until we have received a power board state message"))
111 QMessageBox.critical(self,
"Error", self.tr(
"Breakers will not enable because one of the runstops is pressed"))
115 power_cmd = PowerBoardCommandRequest()
116 power_cmd.breaker_number = breaker
117 power_cmd.command = cmd
118 power_cmd.serial_number = self.
_serial
122 except rospy.ServiceException
as e:
123 QMessageBox.critical(self,
"Error",
"Service call failed with error: %s" % (e),
"Error")
187 Sets state of button based on msg
189 :param msg: message containing the PR2 powerboard state
190 :type msg: pr2_msgs.msg.PowerBoardState
192 last_voltage = msg.circuit_voltage[self.
_index]
199 if (msg.circuit_state[self.
_index] == PowerBoardState.STATE_DISABLED):
201 status_msg =
"Disabled"
202 elif (msg.circuit_state[self.
_index] == PowerBoardState.STATE_NOPOWER):
204 status_msg =
"No Power"
205 elif (msg.circuit_state[self.
_index] == PowerBoardState.STATE_STANDBY):
207 status_msg =
"Standby"
212 self.setToolTip(
"Breaker: %s \nVoltage: %.02f \nState: %s" % (self.
_name, msg.circuit_voltage[self.
_index], status_msg))
217 self.setToolTip(
"Breaker: %s (Stale)" % (self.
_name))