Rev 647 | Rev 649 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 647 | Rev 648 | ||
---|---|---|---|
Line 11... | Line 11... | ||
11 | import sys |
11 | import sys |
12 | import os |
12 | import os |
13 | import time |
13 | import time |
14 | import thread |
14 | import thread |
15 | import ConfigParser |
15 | import ConfigParser |
- | 16 | import math |
|
Line 16... | Line 17... | ||
16 | 17 | ||
17 | import wx |
18 | import wx |
18 | import wx.lib |
19 | import wx.lib |
19 | import wx.lib.plot |
20 | import wx.lib.plot |
Line 509... | Line 510... | ||
509 | self.TestListCtrl.SetStringItem(index, 0, test.descr) |
510 | self.TestListCtrl.SetStringItem(index, 0, test.descr) |
510 | self.TestListCtrl.SetStringItem(index, 1, "%.1f V" %test.voltage) |
511 | self.TestListCtrl.SetStringItem(index, 1, "%.1f V" %test.voltage) |
511 | self.TestListCtrl.SetStringItem(index, 2, str(test.speed)) |
512 | self.TestListCtrl.SetStringItem(index, 2, str(test.speed)) |
512 | self.TestListCtrl.SetStringItem(index, 3, test.channel) |
513 | self.TestListCtrl.SetStringItem(index, 3, test.channel) |
Line 513... | Line 514... | ||
513 | 514 | ||
514 | vv = int(test.getVibValue(self.app.settings["hpf"].value, self.app.settings["lpf"].value)) |
515 | vv = test.getVibValue(self.app.settings["hpf"].value, self.app.settings["lpf"].value) |
515 | vvs = "|%s| (%d)" % ("----------------------------------------------------------------------------------------------------"[0:min(vv/2,100)], vv) |
516 | vvs = "|%s| (%.1f)" % ("----------------------------------------------------------------------------------------------------"[0:min(int(vv+1)/2,100)], vv) |
Line 516... | Line 517... | ||
516 | self.TestListCtrl.SetStringItem(index, 4, vvs) |
517 | self.TestListCtrl.SetStringItem(index, 4, vvs) |
517 | 518 | ||
518 | def refreshData(self): |
519 | def refreshData(self): |
Line 673... | Line 674... | ||
673 | style=wx.DEFAULT_DIALOG_STYLE, # & ~wx.CLOSE_BOX |
674 | style=wx.DEFAULT_DIALOG_STYLE, # & ~wx.CLOSE_BOX |
674 | ) |
675 | ) |
675 | dlg.CenterOnScreen() |
676 | dlg.CenterOnScreen() |
676 | val = dlg.ShowModal() # this does not return until the dialog is closed. |
677 | val = dlg.ShowModal() # this does not return until the dialog is closed. |
677 | dlg.Destroy() |
678 | dlg.Destroy() |
678 | self.app.onSettingsChanged() |
679 | self.app.onSettingsChanged(True) |
Line 679... | Line 680... | ||
679 | 680 | ||
680 | def onStartMeasure(self, event): # wxGlade: MainFrame.<event_handler> |
681 | def onStartMeasure(self, event): # wxGlade: MainFrame.<event_handler> |
681 | # Collect measure parameters |
682 | # Collect measure parameters |
Line 761... | Line 762... | ||
761 | 762 | ||
762 | def onAbout(self, event): # wxGlade: MainFrame.<event_handler> |
763 | def onAbout(self, event): # wxGlade: MainFrame.<event_handler> |
763 | # First we create and fill the info object |
764 | # First we create and fill the info object |
764 | print "about" |
765 | print "about" |
765 | info = wx.AboutDialogInfo() |
766 | info = wx.AboutDialogInfo() |
766 | info.Name = "MK Vibration Test" |
767 | info.Name = "- MK Vibration Test - " |
767 | info.Version = "0.9" |
768 | info.Version = "v0.9 RC1" |
768 | info.Copyright = "" |
769 | info.Copyright = "" |
769 | info.Developers=["Frederic Goddeeris Frederic@rc-flight.be"] |
770 | info.Developers=["Frederic Goddeeris Frederic@rc-flight.be"] |
770 | info.Description = "Please consult the WIKI page for a complete description of the tool:" |
771 | info.Description = "Please consult the WIKI page for a complete description of the tool:" |
771 | info.WebSite = ("http://www.mikrokopter.de/ucwiki/en/VibrationTest", "VibrationTest WIKI page") |
772 | info.WebSite = ("http://www.mikrokopter.de/ucwiki/en/VibrationTest", "VibrationTest WIKI page") |
Line 923... | Line 924... | ||
923 | self.running = False |
924 | self.running = False |
924 | self._sendEvent("", speed = 0) |
925 | self._sendEvent("", speed = 0) |
Line 925... | Line 926... | ||
925 | 926 | ||
- | 927 | ||
- | 928 | class VibTest: |
|
926 | 929 | useRms = True |
|
927 | class VibTest: |
930 | |
928 | def __init__(self, descr, voltage, motor, speed, channel, rawData): |
931 | def __init__(self, descr, voltage, motor, speed, channel, rawData): |
929 | self.descr = descr |
932 | self.descr = descr |
930 | self.voltage = voltage |
933 | self.voltage = voltage |
Line 958... | Line 961... | ||
958 | 961 | ||
959 | def getSpectrum(self): |
962 | def getSpectrum(self): |
960 | if self.spectrum == None: |
963 | if self.spectrum == None: |
961 | self.spectrum = _Numeric.absolute(self.fft[1:self.dataLen/2+1]) / (self.dataLen/2) |
964 | self.spectrum = _Numeric.absolute(self.fft[1:self.dataLen/2+1]) / (self.dataLen/2) |
- | 965 | return self.spectrum |
|
- | 966 | ||
- | 967 | def refresh(self): |
|
- | 968 | self.filteredData = None |
|
Line 962... | Line 969... | ||
962 | return self.spectrum |
969 | self.vibValue = None |
963 | 970 | ||
964 | def getFilteredData(self, fc1, fc2): |
971 | def getFilteredData(self, fc1, fc2): |
Line 981... | Line 988... | ||
981 | 988 | ||
Line 982... | Line 989... | ||
982 | return self.filteredData |
989 | return self.filteredData |
983 | 990 | ||
984 | def getVibValue(self, fc1, fc2): |
991 | def getVibValue(self, fc1, fc2): |
- | 992 | if self.fc1 != fc1 or self.fc2 != fc2: |
|
985 | if self.fc1 != fc1 or self.fc2 != fc2: |
993 | self.vibValue = None |
986 | self.vibValue = None |
994 | |
- | 995 | if self.vibValue == None: |
|
- | 996 | fd = self.getFilteredData(fc1, fc2)[100:-100]; |
|
- | 997 | if self.useRms: |
|
- | 998 | print "RMS" |
|
- | 999 | self.vibValue = math.sqrt(sum([x*x for x in fd])/len(fd))*2*math.sqrt(2) |
|
987 | if self.vibValue == None: |
1000 | else: |
988 | fd = self.getFilteredData(fc1, fc2)[100:-100]; |
1001 | print "PP" |
Line 989... | Line 1002... | ||
989 | self.vibValue = max(fd)-min(fd) |
1002 | self.vibValue = max(fd)-min(fd) |
Line 1005... | Line 1018... | ||
1005 | self.settings["startupspeed"] = Setting("Motor Startup Speed", 25) |
1018 | self.settings["startupspeed"] = Setting("Motor Startup Speed", 25) |
1006 | self.settings["startupsettling"] = Setting("Motor Startup Setting time (s)", 3) |
1019 | self.settings["startupsettling"] = Setting("Motor Startup Setting time (s)", 3) |
1007 | self.settings["serialport"] = Setting("Serial Port", "COM1") |
1020 | self.settings["serialport"] = Setting("Serial Port", "COM1") |
1008 | self.settings["hpf"] = Setting("HP Filter cutoff (Hz)", 40) |
1021 | self.settings["hpf"] = Setting("HP Filter cutoff (Hz)", 40) |
1009 | self.settings["lpf"] = Setting("LP Filter cutoff (Hz)", 400) |
1022 | self.settings["lpf"] = Setting("LP Filter cutoff (Hz)", 400) |
- | 1023 | self.settings["calcmethod"] = Setting("Calculation Method", "rms") |
|
1010 | self.settings["minvoltage"] = Setting("Minimum Bettery Voltage (0=Automatic) (V) ", 0) |
1024 | self.settings["minvoltage"] = Setting("Minimum Bettery Voltage (0=Automatic) (V) ", 0) |
1011 | self.settings["maxvoltage"] = Setting("Maximum Bettery Voltage (0=Automatic) (V) ", 0) |
1025 | self.settings["maxvoltage"] = Setting("Maximum Bettery Voltage (0=Automatic) (V) ", 0) |
Line 1012... | Line 1026... | ||
1012 | 1026 | ||
Line 1029... | Line 1043... | ||
1029 | self.settings[setting[0]].set(setting[1]) |
1043 | self.settings[setting[0]].set(setting[1]) |
1030 | except: |
1044 | except: |
1031 | print "WARNING, unknown setting" |
1045 | print "WARNING, unknown setting" |
1032 | except: |
1046 | except: |
1033 | print "ERROR reading settingsfile" |
1047 | print "ERROR reading settingsfile" |
1034 | - | ||
- | 1048 | self.onSettingsChanged(False) |
|
Line 1035... | Line 1049... | ||
1035 | 1049 | ||
1036 | def storeSettings(self): |
1050 | def storeSettings(self): |
Line 1037... | Line 1051... | ||
1037 | print "Storing settings" |
1051 | print "Storing settings" |
Line 1043... | Line 1057... | ||
1043 | file = open("%s/%s" % (rootPath, App.SETTINGSFILE), "w") |
1057 | file = open("%s/%s" % (rootPath, App.SETTINGSFILE), "w") |
1044 | cp.write(file) |
1058 | cp.write(file) |
1045 | file.close() |
1059 | file.close() |
Line 1046... | Line 1060... | ||
1046 | 1060 | ||
- | 1061 | ||
1047 | 1062 | def onSettingsChanged(self, store): |
|
- | 1063 | if store: |
|
- | 1064 | self.storeSettings() |
|
- | 1065 | if self.settings["calcmethod"].value == "rms": |
|
- | 1066 | VibTest.useRms = True |
|
- | 1067 | else: |
|
- | 1068 | VibTest.useRms = False |
|
1048 | def onSettingsChanged(self): |
1069 | for test in self.VibTests: |
Line 1049... | Line 1070... | ||
1049 | self.storeSettings() |
1070 | test.refresh() |
1050 | self.frame_1.refreshData() |
1071 | self.frame_1.refreshData() |
1051 | 1072 |