robot_control.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2008, Willow Garage, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of the Willow Garage nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
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 #    w = self.GetSize().GetWidth()
00069 #    h = self.GetSize().GetHeight()
00070 #
00071 #    qual = "?"
00072 #    rate = "?"
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 


lwr_dashboard
Author(s): Maciej StefaƄczyk
autogenerated on Mon Oct 6 2014 01:58:11