Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 import roslib
00034 roslib.load_manifest('turtlebot_dashboard')
00035
00036 import wx
00037 import rospy
00038 import string
00039 import turtlebot_node.srv
00040
00041 from status_control import StatusControl
00042
00043 from os import path
00044
00045 breaker_prefixes = ("digitalzero", "digitalone", "digitaltwo")
00046
00047 class BreakerControl(StatusControl):
00048 def __init__(self, parent, id, breaker_index, breaker_name, icons_path):
00049 StatusControl.__init__(self, parent, id, icons_path, breaker_prefixes[breaker_index], True)
00050
00051 self.Bind(wx.EVT_BUTTON, self.on_click)
00052 self._index = breaker_index
00053 self._name = breaker_name
00054 self.raw_byte = 0
00055 self._breaker_state = 0
00056 self._power_control = rospy.ServiceProxy('turtlebot_node/set_digital_outputs', turtlebot_node.srv.SetDigitalOutputs)
00057 self.digital_outs =[0,0,0]
00058
00059
00060
00061 def on_click(self, evt):
00062 self.control(0)
00063 return True
00064
00065 def control(self, cmd):
00066 if (not self._breaker_state):
00067 wx.MessageBox("Cannot control breakers until we have received a power board state message", "Error", wx.OK|wx.ICON_ERROR)
00068 return False
00069
00070 try:
00071 tmp = self._raw_byte
00072 for i in range(0,3):
00073 self.digital_outs[i]=tmp%2
00074 tmp = tmp >> 1
00075 self.digital_outs[self._index] = not self.digital_outs[self._index]
00076 power_cmd = turtlebot_node.srv.SetDigitalOutputsRequest(self.digital_outs[0], self.digital_outs[1], self.digital_outs[2])
00077
00078 self._power_control(power_cmd)
00079
00080 return True
00081 except rospy.ServiceException, e:
00082 wx.MessageBox("Service call failed with error: %s"%(e), "Error", wx.OK|wx.ICON_ERROR)
00083 return False
00084
00085 return False
00086
00087
00088 def set_breaker_state(self, msg):
00089 self._breaker_state = True
00090 self._raw_byte = string.atoi(msg['Raw Byte'])
00091 tmp = self._raw_byte
00092 for i in range(0,3):
00093 self.digital_outs[i]=tmp%2
00094 tmp = tmp >> 1
00095
00096 if(self.digital_outs[self._index]==0):
00097 self.set_error()
00098 status_msg = "Disabled"
00099 else:
00100 self.set_ok()
00101 status_msg = "Enabled"
00102
00103
00104 def reset(self):
00105 self.set_stale()
00106 self.SetToolTip(wx.ToolTip("%s: Stale"%(self._name)))