Subversion Repositories Projects

Rev

Rev 706 | Rev 717 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 706 Rev 709
Line 1... Line 1...
1
#!/usr/bin/env python
1
#!/usr/bin/env python
2
# -*- coding: iso-8859-15 -*-
2
# -*- coding: iso-8859-15 -*-
3
# generated by wxGlade 0.6.3 on Thu Sep 24 15:46:36 2009
3
# generated by wxGlade 0.6.3 on Thu Sep 24 15:46:36 2009
4
 
4
 
5
#
5
#
6
# Mikrokopter VibrationTest  Rev: $Rev: 701 $
6
# Mikrokopter VibrationTest  Rev: $Rev: 709 $
7
#
7
#
8
# Author: Frederic Goddeeris   (frederic@rc-flight.be) 
8
# Author: Frederic Goddeeris   (frederic@rc-flight.be) 
9
#
9
#
10
 
10
 
11
import sys
11
import sys
Line 26... Line 26...
26
 
26
 
27
 
27
 
28
CHANNEL_NAMES = ["GyroYaw", "GyroRoll", "GyroNick", "Pressure", "Batt", "AccTop", "AccRoll", "AccNick"]
28
CHANNEL_NAMES = ["GyroYaw", "GyroRoll", "GyroNick", "Pressure", "Batt", "AccTop", "AccRoll", "AccNick"]
29
MOTOR_MAX = 16
29
MOTOR_MAX = 16
30
 
30
 
31
FS = 11111
31
FS = 20
32
pi = 3.14
32
pi = 3.14
33
COLOR_YELLOW = wx.Colour(255, 240, 0)
33
COLOR_YELLOW = wx.Colour(255, 240, 0)
34
COLOR_BACKGROUND = wx.Colour(0x80, 0x80, 0x80)
34
COLOR_BACKGROUND = wx.Colour(0x80, 0x80, 0x80)
35
 
35
 
36
COLORS = [wx.RED, wx.GREEN, wx.BLUE, COLOR_YELLOW, COLOR_BACKGROUND, wx.BLACK,]*2
36
COLORS = [wx.RED, wx.GREEN, wx.BLUE, COLOR_YELLOW, COLOR_BACKGROUND, wx.BLACK,]*2
Line 330... Line 330...
330
        self.static_line_1 = wx.StaticLine(self, -1)
330
        self.static_line_1 = wx.StaticLine(self, -1)
331
        self.graphCtrl = wx.lib.plot.PlotCanvas(self, size=(800,300))
331
        self.graphCtrl = wx.lib.plot.PlotCanvas(self, size=(800,300))
332
        self.label_40 = wx.StaticText(self, -1, "Graph Type ")
332
        self.label_40 = wx.StaticText(self, -1, "Graph Type ")
333
        self.graphTypeChoice = wx.Choice(self, -1, choices=["Raw Signal", "Filtered Signal", "Spectrum"])
333
        self.graphTypeChoice = wx.Choice(self, -1, choices=["Raw Signal", "Filtered Signal", "Spectrum"])
334
        self.label_41 = wx.StaticText(self, -1, "Y Axis Range ")
334
        self.label_41 = wx.StaticText(self, -1, "Y Axis Range ")
335
        self.yAxisChoice = wx.Choice(self, -1, choices=["25", "50", "75", "100", "200"])
335
        self.yAxisChoice = wx.Choice(self, -1, choices=["10", "25", "50", "75", "100", "200", "500", "1000", "2000"])
336
        self.copyGraphButton = wx.Button(self, -1, "Copy Graph Data")
336
        self.copyGraphButton = wx.Button(self, -1, "Copy Graph Data")
337
        self.TestListCtrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
337
        self.TestListCtrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
338
 
338
 
339
        self.__set_properties()
339
        self.__set_properties()
340
        self.__do_layout()
340
        self.__do_layout()
Line 671... Line 671...
671
                 fc = self.app.settings["lpf"].value
671
                 fc = self.app.settings["lpf"].value
672
                 filterLine2 = wx.lib.plot.PolyLine(((fc,0),(fc,y)), legend='HP Filter', colour='Black', width=4)
672
                 filterLine2 = wx.lib.plot.PolyLine(((fc,0),(fc,y)), legend='HP Filter', colour='Black', width=4)
673
       
673
       
674
                 title = "Spectrum: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
674
                 title = "Spectrum: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
675
                 self.graphCtrl.setLogScale((True,False))
675
                 self.graphCtrl.setLogScale((True,False))
676
                 self.graphCtrl.Draw(wx.lib.plot.PlotGraphics([line,markers, filterLine1, filterLine2], title, "Freq (Hz)", "Acc"), xAxis=(20,500), yAxis= (0,y))
676
                 self.graphCtrl.Draw(wx.lib.plot.PlotGraphics([line,markers, filterLine1, filterLine2], title, "Freq (Hz)", "Acc"), xAxis=(0.1,20), yAxis= (0,y))
677
                 self.graphCtrl.SetEnableGrid(True)
677
                 self.graphCtrl.SetEnableGrid(True)
678
                 self.graphCtrl.SetEnableLegend(False)
678
                 self.graphCtrl.SetEnableLegend(False)
679
                 
679
                 
680
 
680
 
681
 
681
 
Line 823... Line 823...
823
    def onAbout(self, event): # wxGlade: MainFrame.<event_handler>
823
    def onAbout(self, event): # wxGlade: MainFrame.<event_handler>
824
         # First we create and fill the info object
824
         # First we create and fill the info object
825
        print "about"
825
        print "about"
826
        info = wx.AboutDialogInfo()
826
        info = wx.AboutDialogInfo()
827
        info.Name = "MK Vibration Test - "
827
        info.Name = "MK Vibration Test - "
828
        info.Version = "v1.2 ($Rev: 701 $)".replace("$","")
828
        info.Version = "v1.2 ($Rev: 709 $)".replace("$","")
829
        info.Copyright = ""
829
        info.Copyright = ""
830
        info.Developers=["Frederic Goddeeris  (Frederic@rc-flight.be)"]
830
        info.Developers=["Frederic Goddeeris  (Frederic@rc-flight.be)"]
831
        info.Description = "Please consult the WIKI page for a complete description of the tool:"
831
        info.Description = "Please consult the WIKI page for a complete description of the tool:"
832
        info.WebSite = ("http://www.mikrokopter.de/ucwiki/en/VibrationTest", "VibrationTest WIKI page")
832
        info.WebSite = ("http://www.mikrokopter.de/ucwiki/en/VibrationTest", "VibrationTest WIKI page")
833
        wx.AboutBox(info)
833
        wx.AboutBox(info)
Line 889... Line 889...
889
               
889
               
890
    def _sendEvent(self, msg=None, error=False, parVoltage=None, speed=None):
890
    def _sendEvent(self, msg=None, error=False, parVoltage=None, speed=None):
891
        evt = MeasStatusUpdateEvent(running=self.running, msg=msg, error=error, voltage=parVoltage, speed=speed)
891
        evt = MeasStatusUpdateEvent(running=self.running, msg=msg, error=error, voltage=parVoltage, speed=speed)
892
        wx.PostEvent(self.evtConsumer, evt)
892
        wx.PostEvent(self.evtConsumer, evt)
893
 
893
 
894
    def _setMotorSpeed(self, speed, settlingTime):
894
#    def _setMotorSpeed(self, speed, settlingTime):
895
        speeds = [0]*MOTOR_MAX
895
#        speeds = [0]*MOTOR_MAX
896
       
896
#        
897
        for motor in self.param.motors:
897
#        for motor in self.param.motors:
898
            speeds[motor-1] = speed
898
#            speeds[motor-1] = speed
899
        for i in range(int(settlingTime*10)):
899
#        for i in range(int(settlingTime*10)):
900
          self._testCancel()
900
#          self._testCancel()
901
          self.mk.setMotorTest(speeds)
901
#          self.mk.setMotorTest(speeds)
902
          time.sleep(.1)
902
#          time.sleep(.1)
903
        self.currSpeed = speed
903
#        self.currSpeed = speed
904
       
904
       
905
                   
905
                   
906
    def _run(self):
906
    def _run(self):
907
        self.running = True
907
        self.running = True
908
        self._sendEvent("Starting test \"%s\"" % self.param.descr)    
908
        self._sendEvent("Starting test \"%s\"" % self.param.descr)    
Line 942... Line 942...
942
              else:
942
              else:
943
                maxVoltage = nbCells*3.9  
943
                maxVoltage = nbCells*3.9  
944
               
944
               
945
            self._sendEvent("Voltage: %2.1fV" % voltage)
945
            self._sendEvent("Voltage: %2.1fV" % voltage)
946
            self._sendEvent("Min/Max Voltage: %2.1fV-%2.1fV" % (minVoltage, maxVoltage), parVoltage=(minVoltage, maxVoltage, voltage))
946
            self._sendEvent("Min/Max Voltage: %2.1fV-%2.1fV" % (minVoltage, maxVoltage), parVoltage=(minVoltage, maxVoltage, voltage))
947
           
947
 
948
            self._sendEvent("Starting motor(s) (speed=%d)... " % self.param.motorStartupSpeed, speed=self.param.motorStartupSpeed)
-
 
949
            self._setMotorSpeed(self.param.motorStartupSpeed, self.param.motorStartupSettlingTime)
-
 
950
         
-
 
951
            for speed in self.param.speeds:
-
 
952
                if speed != self.currSpeed:
-
 
953
                    self._sendEvent("Changing motor speed to %d... " % speed, speed=speed)
-
 
954
                    self._setMotorSpeed(speed, 1)
-
 
955
               
-
 
956
                for channel in self.param.channels:
-
 
957
                    self._setMotorSpeed(speed, .1)
-
 
958
                    msg = self.mk.getDebugMsg()
-
 
959
                    voltage = msg.getVoltage()
-
 
960
           
-
 
961
                    self._sendEvent("Getting data from channel %s" % CHANNEL_NAMES[channel], parVoltage=(minVoltage, maxVoltage, voltage))
-
 
962
                    data = self.mk.doVibrationTest(1000, channel)
-
 
963
                   
-
 
964
                    vt = VibTest(self.param.descr, voltage, self.param.motors, speed, CHANNEL_NAMES[channel], data)
-
 
965
                    evt = MeasDataEvent(vibTest = vt)
-
 
966
                    wx.PostEvent(self.evtConsumer, evt)
-
 
967
                   
-
 
968
                    if voltage<minVoltage:
-
 
969
                        raise Exception("Voltage too low")
-
 
970
           
-
 
971
           
-
 
972
            self._setMotorSpeed(speed, .1)    
-
 
973
            time.sleep(1)
-
 
974
            msg = self.mk.getDebugMsg()
948
            msg = self.mk.getDebugMsg()
975
            voltage = msg.getVoltage()
949
            voltage = msg.getVoltage()
976
           
950
   
-
 
951
            #data = self.mk.doVibrationTest(1000, channel)
-
 
952
            messages = self.mk.recordDbgMsg(0.05, 20*5)
-
 
953
            data = []
-
 
954
            for msg in messages:
-
 
955
                data.append(msg.getAngleRoll())
-
 
956
            print data
-
 
957
           
-
 
958
            vt = VibTest(self.param.descr, voltage, self.param.motors, 0, "AngleRoll", data)
-
 
959
            evt = MeasDataEvent(vibTest = vt)
-
 
960
            wx.PostEvent(self.evtConsumer, evt)
-
 
961
           
-
 
962
            if voltage<minVoltage:
-
 
963
                raise Exception("Voltage too low")
-
 
964
                         
977
            self._sendEvent("Done !", parVoltage=(minVoltage, maxVoltage, voltage))            
965
            self._sendEvent("Done !", parVoltage=(minVoltage, maxVoltage, voltage))            
978
           
966
           
979
        except Exception, e:
967
        except Exception, e:
980
            self._sendEvent("Exception \"%s\"" % e, error=True)  
968
            self._sendEvent("Exception \"%s\"" % e, error=True)  
981
       
969