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('lwr_dashboard')
00035
00036 import wx
00037
00038 from os import path
00039
00040 class RobotControl(wx.Window):
00041 def __init__(self, parent, id, icons_path):
00042 wx.Window.__init__(self, parent, id, wx.DefaultPosition, wx.Size(60, 50))
00043
00044 bitmap = wx.Bitmap(path.join(icons_path, "btn_motors.png"), wx.BITMAP_TYPE_PNG)
00045 self._state_bitmap = (bitmap.GetSubBitmap(wx.Rect(0, 0, 40, 40)),
00046 bitmap.GetSubBitmap(wx.Rect(40, 0, 40, 40)),
00047 bitmap.GetSubBitmap(wx.Rect(80, 0, 40, 40)),
00048 bitmap.GetSubBitmap(wx.Rect(120, 0, 40, 40)))
00049
00050 bitmap = wx.Bitmap(path.join(icons_path, "long_buttons.png"), wx.BITMAP_TYPE_PNG)
00051 self._screen_bitmap = (bitmap.GetSubBitmap(wx.Rect(0, 0, 80, 40)),
00052 bitmap.GetSubBitmap(wx.Rect( 80, 40, 80, 40)),
00053 bitmap.GetSubBitmap(wx.Rect( 0, 40, 80, 40)))
00054
00055 self._status = {}
00056 self._stale = True
00057
00058 self.SetSize(wx.Size(120, 40))
00059
00060 self.Bind(wx.EVT_PAINT, self.on_paint)
00061
00062 def on_paint(self, evt):
00063 dc = wx.BufferedPaintDC(self)
00064
00065 dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
00066 dc.Clear()
00067
00068
00069
00070
00071
00072
00073
00074
00075 strategy = "?"
00076
00077 allok = False
00078
00079 if (self._stale):
00080 dc.DrawBitmap(self._state_bitmap[3], 0, 0, True)
00081 dc.DrawBitmap(self._screen_bitmap[2], 40, 0, True)
00082 else:
00083 if (self._status["Error"] == "0000000" and self._status["Warning"] == "0000000"):
00084 allok = True
00085 else:
00086 allok = False
00087
00088 if (allok and self._status["Power"] == "1111111"):
00089 dc.DrawBitmap(self._state_bitmap[0], 0, 0, True)
00090
00091 if (allok and self._status["Power"] != "1111111"):
00092 dc.DrawBitmap(self._state_bitmap[1], 0, 0, True)
00093
00094 if (not allok):
00095 dc.DrawBitmap(self._state_bitmap[2], 0, 0, True)
00096
00097 if (self._status["Control Strategy"] == "Position"):
00098 strategy = "Pos"
00099 if (self._status["Control Strategy"] == "Joint impedance"):
00100 strategy = "J-imp"
00101 if (self._status["Control Strategy"] == "Cartesian impedance"):
00102 strategy = "C-imp"
00103 if (self._status["Control Strategy"] == "Invalid"):
00104 strategy = "Inv"
00105
00106 if (strategy != "Inv"):
00107 dc.DrawBitmap(self._screen_bitmap[0], 40, 0, True)
00108 else:
00109 dc.DrawBitmap(self._screen_bitmap[1], 40, 0, True)
00110
00111 fnt = dc.GetFont()
00112 fnt.SetPointSize(7)
00113 dc.SetFont(fnt)
00114 dc.DrawLabel("Control", wx.Rect(45, 5, 70, 32), wx.ALIGN_LEFT|wx.ALIGN_TOP)
00115
00116 fnt.SetPointSize(14)
00117 fnt.SetWeight(wx.FONTWEIGHT_BOLD)
00118 dc.SetFont(fnt)
00119 dc.DrawLabel("%s" % strategy, wx.Rect(45, 5, 70, 32), wx.ALIGN_RIGHT|wx.ALIGN_BOTTOM)
00120
00121 def set_state(self, msg):
00122 self._stale = False
00123 self._status = msg;
00124
00125 tooltip = ""
00126
00127 for key, value in msg.items():
00128 tooltip = tooltip + "%s: %s\n" % (key, value)
00129
00130 self.SetToolTip(wx.ToolTip(tooltip))
00131
00132 self.Refresh()
00133
00134 def set_stale(self):
00135 self.SetToolTip(wx.ToolTip("Robot: Stale"))
00136 self._stale = True
00137 self.Refresh()
00138