pr2_power_board_panel.py
Go to the documentation of this file.
1 
2 #!/usr/bin/env python
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2008, Willow Garage, Inc.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 # * Neither the name of the Willow Garage nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 #
35 
36 PKG = 'pr2_power_board'
37 
38 import roslib
39 roslib.load_manifest(PKG)
40 
41 import sys
42 import re
43 import rospy
44 from diagnostic_msgs.msg import *
45 from pr2_power_board.srv import *
46 
47 WXVER = '2.8'
48 import wxversion
49 if wxversion.checkInstalled(WXVER):
50  wxversion.select(WXVER)
51 else:
52  print('This application requires wxPython version %s' % (WXVER), file=sys.stderr)
53  sys.exit(1)
54 
55 import wx
56 from wx import xrc
57 
58 import threading, time
59 
60 class PowerBoardPanel(wx.Panel):
61  def __init__(self, parent):
62  wx.Panel.__init__(self, parent, wx.ID_ANY)
63 
64  self._mutex = threading.Lock()
65 
66  xrc_path = roslib.packages.get_pkg_dir(PKG) + '/ui/pr2_power_board_panel.xrc'
67 
68  self._xrc = xrc.XmlResource(xrc_path)
69  self._real_panel = self._xrc.LoadPanel(self, 'PowerBoardPanel')
70 
71  serialBoxSizer = wx.BoxSizer(wx.HORIZONTAL)
72  self.myList = wx.ComboBox(self, -1, size=(150,30), style=wx.CB_READONLY)
73  self.Bind(wx.EVT_COMBOBOX, lambda e: self.chooseBoard(self.myList.GetValue()))
74  serialBoxSizer.Add( wx.StaticText( self, -1, "Board ") )
75  serialBoxSizer.Add( self.myList )
76  serialBoxSizer.Add( wx.StaticText( self, -1, "Serial ") )
77  self.serialText = wx.TextCtrl( self, -1, size=(150,30))
78  self.serialText.SetEditable(False)
79  self.boardList = dict();
80  serialBoxSizer.Add( self.serialText )
81 
82  sizer = wx.BoxSizer(wx.VERTICAL)
83  sizer.Add( serialBoxSizer, 0, wx.TOP)
84  sizer.Add(self._real_panel, 0, wx.BOTTOM)
85  self.SetSizer(sizer)
86 
87  self._real_panel.Bind(wx.EVT_BUTTON, self.EnableCB0, id=xrc.XRCID('m_button1'))
88  self._real_panel.Bind(wx.EVT_BUTTON, self.EnableCB1, id=xrc.XRCID('m_button11'))
89  self._real_panel.Bind(wx.EVT_BUTTON, self.EnableCB2, id=xrc.XRCID('m_button12'))
90 
91  self._real_panel.Bind(wx.EVT_BUTTON, self.StandbyCB0, id=xrc.XRCID('m_button2'))
92  self._real_panel.Bind(wx.EVT_BUTTON, self.StandbyCB1, id=xrc.XRCID('m_button21'))
93  self._real_panel.Bind(wx.EVT_BUTTON, self.StandbyCB2, id=xrc.XRCID('m_button22'))
94 
95  self._real_panel.Bind(wx.EVT_BUTTON, self.ResetCB0, id=xrc.XRCID('m_button3'))
96  self._real_panel.Bind(wx.EVT_BUTTON, self.ResetCB1, id=xrc.XRCID('m_button31'))
97  self._real_panel.Bind(wx.EVT_BUTTON, self.ResetCB2, id=xrc.XRCID('m_button32'))
98 
99  self._real_panel.Bind(wx.EVT_BUTTON, self.DisableCB0, id=xrc.XRCID('cb0_disable'))
100  self._real_panel.Bind(wx.EVT_BUTTON, self.DisableCB1, id=xrc.XRCID('cb1_disable'))
101  self._real_panel.Bind(wx.EVT_BUTTON, self.DisableCB2, id=xrc.XRCID('cb2_disable'))
102 
103  self._real_panel.Bind(wx.EVT_BUTTON, self.ResetCurrent, id=xrc.XRCID('button_reset_current'))
104  self._real_panel.Bind(wx.EVT_BUTTON, self.ResetTransitions, id=xrc.XRCID('button_reset_transitions'))
105  rospy.Subscriber("/diagnostics", DiagnosticArray, self.diagnostics_callback)
106 
107  self.power_control = rospy.ServiceProxy('power_board/control', PowerBoardCommand)
108 
109 
110  self.voltages = [0,0,0]
111  self.breaker_state = ["", "", ""]
112  self.estop_wireless_status = "uninitialized, no power_node sending data"
113  self.estop_button_status = "uninitialized"
114 
115  self.breaker0_status = xrc.XRCCTRL(self._real_panel, 'm_textCtrl1')
116  self.breaker1_status = xrc.XRCCTRL(self._real_panel, 'm_textCtrl11')
117  self.breaker2_status = xrc.XRCCTRL(self._real_panel, 'm_textCtrl12')
118 
119 
120  self.estop_status = xrc.XRCCTRL(self._real_panel, 'm_textCtrl9')
121 
122  self.breaker0_status.SetEditable(False)
123  self.breaker1_status.SetEditable(False)
124  self.breaker2_status.SetEditable(False)
125  self.estop_status.SetEditable(False)
126 
127  self.breaker0_status.SetEditable(False)
128  self.breaker1_status.SetEditable(False)
129  self.breaker2_status.SetEditable(False)
130  self.estop_status.SetEditable(False)
131 
132  self._messages = []
133 
134  self.myList.SetValue("none")
135  self.currentBoard = "none"
136 
137  def chooseBoard(self, board):
138  #rospy.logerr("choose: %s" %self.myList.GetValue())
139  self.currentBoard = board
140  self.serialText.Clear()
141  self.serialText.WriteText( str(self.boardList[self.currentBoard]) )
142 
143  def addBoard( self, status ):
144  name = str(status.name)
145  serial = int(0)
146  for strvals in status.values:
147  if (strvals.key == "Serial Number"):
148  serial = int(strvals.value)
149  rospy.logerr("Adding: %s serial=%d" %(name,serial))
150  self.myList.Append(name);
151  self.boardList[name] = serial
152 
153  if self.myList.Count == 1:
154  self.myList.SetSelection(0)
155  self.chooseBoard(name)
156 
157  def diagnostics_callback(self, message):
158  try:
159  self._mutex.acquire()
160  except:
161  return
162  self._messages.append(message)
163  self._mutex.release()
164 
165  wx.CallAfter(self.new_message)
166 
167  def new_message(self):
168 
169 
170  self._mutex.acquire()
171 
172 
173  for message in self._messages:
174  #rospy.logerr(message)
175  for status in message.status:
176  if( (status.name.startswith("Power board") & (self.myList.FindString( status.name ) == wx.NOT_FOUND)) ):
177  self.addBoard( status )
178 
179  if (status.name == self.currentBoard):
180 
181  if( status.level == 0 ):
182  self._real_panel.SetBackgroundColour("LIGHT_GREY")
183  self._real_panel.Enable(True)
184  elif (status.level == 0):
185  self._real_panel.SetBackgroundColour("Orange")
186  else:
187  self._real_panel.SetBackgroundColour("RED")
188  #self._real_panel.Enable(False)
189 
190  for value in status.values:
191  if (value.key == "Breaker 0 Voltage"):
192  self.voltages[0] = value.value
193  if (value.key == "Breaker 1 Voltage"):
194  self.voltages[1] = value.value
195  if (value.key == "Breaker 2 Voltage"):
196  self.voltages[2] = value.value
197  if (value.key == "RunStop Button Status"):
198  self.estop_wireless_status = value.value
199  if (value.key == "RunStop Status"):
200  self.estop_button_status = value.value
201 
202  for strvals in status.values:
203  if (re.match('Breaker 0',strvals.key,re.IGNORECASE)):
204  self.breaker_state[0] = strvals.value
205  if (re.match('Breaker 1',strvals.key,re.IGNORECASE)):
206  self.breaker_state[1] = strvals.value
207  if (re.match('Breaker 2',strvals.key,re.IGNORECASE)):
208  self.breaker_state[2] = strvals.value
209 
210 
211 
212  #rospy.logerr("Voltages: %.1f %.1f %.1f"%(self.voltages[0],self.voltages[1], self.voltages[2]))
213  #rospy.logerr("States: %s %s %s"%(self.breaker_state[0], self.breaker_state[1], self.breaker_state[2]))
214 
215  self.breaker0_status.SetValue("%s @ %sV"%(self.breaker_state[0], self.voltages[0]))
216  self.breaker1_status.SetValue("%s @ %sV"%(self.breaker_state[1], self.voltages[1]))
217  self.breaker2_status.SetValue("%s @ %sV"%(self.breaker_state[2], self.voltages[2]))
218  if self.breaker_state[0] == "Standby":
219  self.breaker0_status.SetBackgroundColour("Orange")
220  elif self.breaker_state[0] in ("On", "Enabled"):
221  self.breaker0_status.SetBackgroundColour("Light Green")
222  else:
223  self.breaker0_status.SetBackgroundColour("Red")
224 
225  if self.breaker_state[1] == "Standby":
226  self.breaker1_status.SetBackgroundColour("Orange")
227  elif self.breaker_state[1] in ("On", "Enabled"):
228  self.breaker1_status.SetBackgroundColour("Light Green")
229  else:
230  self.breaker1_status.SetBackgroundColour("Red")
231 
232  if self.breaker_state[2] == "Standby":
233  self.breaker2_status.SetBackgroundColour("Orange")
234  elif self.breaker_state[2] in ("On", "Enabled"):
235  self.breaker2_status.SetBackgroundColour("Light Green")
236  else:
237  self.breaker2_status.SetBackgroundColour("Red")
238 
239  if self.estop_button_status == "False" or self.estop_wireless_status == "False":
240  estop_status_temp = "Stop"
241  self.estop_status.SetBackgroundColour("Red")
242  else:
243  estop_status_temp = "Run"
244  self.estop_status.SetBackgroundColour("Light Green")
245 
246  self.estop_status.SetValue("RunStop Status: %s Button(%s) Wireless(%s)"%(estop_status_temp, self.estop_button_status, self.estop_wireless_status))
247 
248 
249  self._messages = []
250 
251  self._mutex.release()
252 
253  self.Refresh()
254 
255 
256 
257  def EnableCB0(self, event):
258  try:
259  self.power_control( self.boardList[self.currentBoard], 0, "start", 0)
260  except rospy.ServiceException as e:
261  rospy.logerr("Service Call Failed: %s"%e)
262  #rospy.logerr("Enable CB0")
263  def EnableCB1(self, event):
264  try:
265  self.power_control( self.boardList[self.currentBoard], 1, "start", 0)
266  except rospy.ServiceException as e:
267  rospy.logerr("Service Call Failed: %s"%e)
268  #rospy.logerr("Enable CB1")
269  def EnableCB2(self, event):
270  try:
271  self.power_control( self.boardList[self.currentBoard], 2, "start", 0)
272  except rospy.ServiceException as e:
273  rospy.logerr("Service Call Failed: %s"%e)
274  #rospy.logerr("Enable CB2")
275 
276  def StandbyCB0(self, event):
277  try:
278  self.power_control( self.boardList[self.currentBoard], 0, "stop", 0)
279  except rospy.ServiceException as e:
280  rospy.logerr("Service Call Failed: %s"%e)
281  #rospy.logerr("Standby CB0")
282  def StandbyCB1(self, event):
283  try:
284  self.power_control( self.boardList[self.currentBoard], 1, "stop", 0)
285  except rospy.ServiceException as e:
286  rospy.logerr("Service Call Failed: %s"%e)
287  #rospy.logerr("Standby CB1")
288  def StandbyCB2(self, event):
289  try:
290  self.power_control( self.boardList[self.currentBoard], 2, "stop", 0)
291  except rospy.ServiceException as e:
292  rospy.logerr("Service Call Failed: %s"%e)
293  #rospy.logerr("Standby CB2")
294 
295  def ResetCB0(self, event):
296  try:
297  self.power_control( self.boardList[self.currentBoard], 0, "reset", 0)
298  except rospy.ServiceException as e:
299  rospy.logerr("Service Call Failed: %s"%e)
300  #rospy.logerr("Reset CB0")
301  def ResetCB1(self, event):
302  try:
303  self.power_control( self.boardList[self.currentBoard], 1, "reset", 0)
304  except rospy.ServiceException as e:
305  rospy.logerr("Service Call Failed: %s"%e)
306  #rospy.logerr("Reset CB1")
307  def ResetCB2(self, event):
308  try:
309  self.power_control( self.boardList[self.currentBoard], 2, "reset", 0)
310  except rospy.ServiceException as e:
311  rospy.logerr("Service Call Failed: %s"%e)
312  #rospy.logerr("Reset CB2")
313 
314  def DisableCB0(self, event):
315  try:
316  self.power_control( self.boardList[self.currentBoard], 0, "disable", 0)
317  except rospy.ServiceException as e:
318  rospy.logerr("Service Call Failed: %s"%e)
319  #rospy.logerr("Disable CB0")
320  def DisableCB1(self, event):
321  try:
322  self.power_control( self.boardList[self.currentBoard], 1, "disable", 0)
323  except rospy.ServiceException as e:
324  rospy.logerr("Service Call Failed: %s"%e)
325  #rospy.logerr("Disable CB1")
326  def DisableCB2(self, event):
327  try:
328  self.power_control( self.boardList[self.currentBoard], 2, "disable", 0)
329  except rospy.ServiceException as e:
330  rospy.logerr("Service Call Failed: %s"%e)
331  #rospy.logerr("Disable CB2")
332 
333  def ResetCurrent(self, event):
334  try:
335  self.power_control( self.boardList[self.currentBoard], 0, "none", 1)
336  except rospy.ServiceException as e:
337  rospy.logerr("Service Call Failed: %s"%e)
338  def ResetTransitions(self, event):
339  try:
340  self.power_control( self.boardList[self.currentBoard], 0, "none", 2)
341  except rospy.ServiceException as e:
342  rospy.logerr("Service Call Failed: %s"%e)
343 
344 
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.addBoard
def addBoard(self, status)
Definition: pr2_power_board_panel.py:143
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.DisableCB1
def DisableCB1(self, event)
Definition: pr2_power_board_panel.py:320
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.serialText
serialText
Definition: pr2_power_board_panel.py:77
pr2_power_board.pr2_power_board_panel.PowerBoardPanel._mutex
_mutex
Definition: pr2_power_board_panel.py:64
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.ResetTransitions
def ResetTransitions(self, event)
Definition: pr2_power_board_panel.py:338
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.StandbyCB0
def StandbyCB0(self, event)
Definition: pr2_power_board_panel.py:276
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.ResetCB1
def ResetCB1(self, event)
Definition: pr2_power_board_panel.py:301
msg
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.breaker_state
breaker_state
Definition: pr2_power_board_panel.py:111
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.new_message
def new_message(self)
Definition: pr2_power_board_panel.py:167
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.estop_status
estop_status
Definition: pr2_power_board_panel.py:120
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.StandbyCB1
def StandbyCB1(self, event)
Definition: pr2_power_board_panel.py:282
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.chooseBoard
def chooseBoard(self, board)
Definition: pr2_power_board_panel.py:137
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.EnableCB1
def EnableCB1(self, event)
Definition: pr2_power_board_panel.py:263
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.boardList
boardList
Definition: pr2_power_board_panel.py:79
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.breaker1_status
breaker1_status
Definition: pr2_power_board_panel.py:116
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.currentBoard
currentBoard
Definition: pr2_power_board_panel.py:135
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.ResetCurrent
def ResetCurrent(self, event)
Definition: pr2_power_board_panel.py:333
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.breaker0_status
breaker0_status
Definition: pr2_power_board_panel.py:115
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.power_control
power_control
Definition: pr2_power_board_panel.py:107
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.DisableCB2
def DisableCB2(self, event)
Definition: pr2_power_board_panel.py:326
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.ResetCB2
def ResetCB2(self, event)
Definition: pr2_power_board_panel.py:307
pr2_power_board.pr2_power_board_panel.PowerBoardPanel
Definition: pr2_power_board_panel.py:60
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.ResetCB0
def ResetCB0(self, event)
Definition: pr2_power_board_panel.py:295
pr2_power_board.pr2_power_board_panel.PowerBoardPanel._xrc
_xrc
Definition: pr2_power_board_panel.py:68
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.EnableCB0
def EnableCB0(self, event)
Definition: pr2_power_board_panel.py:257
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.estop_button_status
estop_button_status
Definition: pr2_power_board_panel.py:113
pr2_power_board.pr2_power_board_panel.PowerBoardPanel._real_panel
_real_panel
Definition: pr2_power_board_panel.py:69
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.myList
myList
Definition: pr2_power_board_panel.py:72
pr2_power_board.pr2_power_board_panel.PowerBoardPanel._messages
_messages
Definition: pr2_power_board_panel.py:132
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.voltages
voltages
Definition: pr2_power_board_panel.py:110
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.diagnostics_callback
def diagnostics_callback(self, message)
Definition: pr2_power_board_panel.py:157
srv
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.__init__
def __init__(self, parent)
Definition: pr2_power_board_panel.py:61
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.StandbyCB2
def StandbyCB2(self, event)
Definition: pr2_power_board_panel.py:288
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.DisableCB0
def DisableCB0(self, event)
Definition: pr2_power_board_panel.py:314
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.EnableCB2
def EnableCB2(self, event)
Definition: pr2_power_board_panel.py:269
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.breaker2_status
breaker2_status
Definition: pr2_power_board_panel.py:117
pr2_power_board.pr2_power_board_panel.PowerBoardPanel.estop_wireless_status
estop_wireless_status
Definition: pr2_power_board_panel.py:112


pr2_power_board
Author(s): Curt Meyers, Blaise Gassend
autogenerated on Tue Mar 7 2023 03:19:35