Rev 709 | Rev 718 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 709 | Rev 717 | ||
---|---|---|---|
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 |
Line 4... | Line 4... | ||
4 | 4 | ||
5 | # |
5 | # |
6 | # Mikrokopter VibrationTest Rev: $Rev: 709 $ |
6 | # Mikrokopter VibrationTest Rev: $Rev: 717 $ |
7 | # |
7 | # |
8 | # Author: Frederic Goddeeris (frederic@rc-flight.be) |
8 | # Author: Frederic Goddeeris (frederic@rc-flight.be) |
Line 9... | Line 9... | ||
9 | # |
9 | # |
10 | 10 | ||
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 |
|
Line 15... | Line 16... | ||
15 | import ConfigParser |
16 | import math |
16 | import math |
17 | import copy |
17 | 18 | ||
18 | import wx |
19 | import wx |
Line 26... | Line 27... | ||
26 | 27 | ||
27 | 28 | ||
Line 28... | Line 29... | ||
28 | CHANNEL_NAMES = ["GyroYaw", "GyroRoll", "GyroNick", "Pressure", "Batt", "AccTop", "AccRoll", "AccNick"] |
29 | CHANNEL_NAMES = ["GyroYaw", "GyroRoll", "GyroNick", "Pressure", "Batt", "AccTop", "AccRoll", "AccNick"] |
29 | MOTOR_MAX = 16 |
30 | MOTOR_MAX = 16 |
30 | 31 | ||
31 | FS = 20 |
32 | FS = 18.0 |
Line 32... | Line 33... | ||
32 | pi = 3.14 |
33 | pi = 3.14 |
Line 629... | Line 630... | ||
629 | self.copyGraphButton.Disable() |
630 | self.copyGraphButton.Disable() |
630 | vibTest = self.app.getTest(self.activeTestId) |
631 | vibTest = self.app.getTest(self.activeTestId) |
631 | nb = vibTest.getDataLen() |
632 | nb = vibTest.getDataLen() |
Line 632... | Line 633... | ||
632 | 633 | ||
633 | if self.graphTypeChoice.GetSelection() == 0: |
634 | if self.graphTypeChoice.GetSelection() == 0: |
634 | xydata = _Numeric.linspace(0,0.09*nb,2*nb) |
635 | xydata = _Numeric.linspace(0,(1/FS)*nb,2*nb) |
635 | xydata.shape = (nb, 2) |
636 | xydata.shape = (nb, 2) |
636 | xydata[:,1] = vibTest.getRawData() |
637 | xydata[:,1] = vibTest.getRawData() |
Line 637... | Line 638... | ||
637 | line = wx.lib.plot.PolyLine(xydata, legend= 'Raw Data', colour='red', width=2) |
638 | line = wx.lib.plot.PolyLine(xydata, legend= 'Raw Data', colour='red', width=2) |
638 | 639 | ||
639 | title = "Raw Signal: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed) |
640 | title = "Raw Signal: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed) |
640 | self.graphCtrl.setLogScale((False,False)) |
641 | self.graphCtrl.setLogScale((False,False)) |
641 | self.graphCtrl.Draw(wx.lib.plot.PlotGraphics([line], title, "Time (ms)", "Acc"), yAxis= (-y/2,y/2)) |
642 | self.graphCtrl.Draw(wx.lib.plot.PlotGraphics([line], title, "Time (s)", "Angle"), yAxis= (-y/2,y/2)) |
Line 642... | Line 643... | ||
642 | self.graphCtrl.SetEnableGrid('Horizontal') |
643 | self.graphCtrl.SetEnableGrid('Horizontal') |
643 | self.graphCtrl.SetEnableLegend(False) |
644 | self.graphCtrl.SetEnableLegend(False) |
644 | 645 | ||
645 | 646 | ||
646 | if self.graphTypeChoice.GetSelection() == 1: |
647 | if self.graphTypeChoice.GetSelection() == 1: |
Line 647... | Line 648... | ||
647 | xydata = _Numeric.linspace(0,0.09*nb,2*nb) |
648 | xydata = _Numeric.linspace(0,(1/FS)*nb,2*nb) |
648 | xydata.shape = (nb, 2) |
649 | xydata.shape = (nb, 2) |
649 | xydata[:,1] = vibTest.getFilteredData() |
650 | xydata[:,1] = vibTest.getFilteredData() |
650 | line = wx.lib.plot.PolyLine(xydata, legend= 'Raw Data', colour='red', width=2) |
651 | line = wx.lib.plot.PolyLine(xydata, legend= 'Raw Data', colour='red', width=2) |
651 | 652 | ||
Line 652... | Line 653... | ||
652 | title = "Filtered Signal: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed) |
653 | title = "Filtered Signal: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed) |
653 | self.graphCtrl.setLogScale((False,False)) |
654 | self.graphCtrl.setLogScale((False,False)) |
Line 823... | Line 824... | ||
823 | def onAbout(self, event): # wxGlade: MainFrame.<event_handler> |
824 | def onAbout(self, event): # wxGlade: MainFrame.<event_handler> |
824 | # First we create and fill the info object |
825 | # First we create and fill the info object |
825 | print "about" |
826 | print "about" |
826 | info = wx.AboutDialogInfo() |
827 | info = wx.AboutDialogInfo() |
827 | info.Name = "MK Vibration Test - " |
828 | info.Name = "MK Vibration Test - " |
828 | info.Version = "v1.2 ($Rev: 709 $)".replace("$","") |
829 | info.Version = "v1.2 ($Rev: 717 $)".replace("$","") |
829 | info.Copyright = "" |
830 | info.Copyright = "" |
830 | info.Developers=["Frederic Goddeeris (Frederic@rc-flight.be)"] |
831 | info.Developers=["Frederic Goddeeris (Frederic@rc-flight.be)"] |
831 | info.Description = "Please consult the WIKI page for a complete description of the tool:" |
832 | 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") |
833 | info.WebSite = ("http://www.mikrokopter.de/ucwiki/en/VibrationTest", "VibrationTest WIKI page") |
833 | wx.AboutBox(info) |
834 | wx.AboutBox(info) |
Line 910... | Line 911... | ||
910 | 911 | ||
911 | try: |
912 | try: |
912 | self._sendEvent("Opening SerialPort \"%s\"" % self.param.serialPort) |
913 | self._sendEvent("Opening SerialPort \"%s\"" % self.param.serialPort) |
Line 913... | Line 914... | ||
913 | self.mk.open(comPort=self.param.serialPort) |
914 | self.mk.open(comPort=self.param.serialPort) |
914 | 915 | ||
915 | print "Sending FC->NC forwarding", |
916 | # print "Sending FC->NC forwarding", |
Line 916... | Line 917... | ||
916 | self.mk.sendNCRedirectUartFromFC() |
917 | # self.mk.sendNCRedirectUartFromFC() |
917 | print "Done" |
918 | # print "Done" |
918 | 919 | ||
Line 934... | Line 935... | ||
934 | nbCells = 3 |
935 | nbCells = 3 |
935 | # Set minimum and maximum voltages |
936 | # Set minimum and maximum voltages |
936 | if self.param.minVoltage > 0: |
937 | if self.param.minVoltage > 0: |
937 | minVoltage = self.param.minVoltage |
938 | minVoltage = self.param.minVoltage |
938 | else: |
939 | else: |
939 | minVoltage = nbCells*3.5 # auto |
940 | minVoltage = nbCells*3 # auto |
940 | if self.param.maxVoltage > 0: |
941 | if self.param.maxVoltage > 0: |
941 | maxVoltage = self.param.maxVoltage |
942 | maxVoltage = self.param.maxVoltage |
942 | else: |
943 | else: |
943 | maxVoltage = nbCells*3.9 |
944 | maxVoltage = nbCells*4 |
Line 944... | Line 945... | ||
944 | 945 | ||
945 | self._sendEvent("Voltage: %2.1fV" % voltage) |
946 | self._sendEvent("Voltage: %2.1fV" % voltage) |
Line 946... | Line 947... | ||
946 | self._sendEvent("Min/Max Voltage: %2.1fV-%2.1fV" % (minVoltage, maxVoltage), parVoltage=(minVoltage, maxVoltage, voltage)) |
947 | self._sendEvent("Min/Max Voltage: %2.1fV-%2.1fV" % (minVoltage, maxVoltage), parVoltage=(minVoltage, maxVoltage, voltage)) |
947 | 948 | ||
948 | msg = self.mk.getDebugMsg() |
- | |
949 | voltage = msg.getVoltage() |
- | |
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) |
- | |
Line -... | Line 949... | ||
- | 949 | msg = self.mk.getDebugMsg() |
|
- | 950 | voltage = msg.getVoltage() |
|
- | 951 | ||
- | 952 | for I in self.param.speeds: |
|
- | 953 | self._sendEvent("TestSettings I=%d" % I) |
|
- | 954 | orgSetting = self.mk.getSettingsMsg() |
|
- | 955 | testSettings = copy.deepcopy(orgSetting) |
|
- | 956 | ||
- | 957 | # testSettings.setSetting(MkProtocol.SettingsMsg.IDX_GYRO_P, I) |
|
- | 958 | # testSettings.setSetting(MkProtocol.SettingsMsg.IDX_GYRO_I, 65) |
|
- | 959 | ||
- | 960 | testSettings.setSetting(MkProtocol.SettingsMsg.IDX_GYRO_P, 0) |
|
- | 961 | testSettings.setSetting(MkProtocol.SettingsMsg.IDX_GYRO_I, I) |
|
- | 962 | ||
- | 963 | self.mk.sendSettings(testSettings.getSettings()) |
|
- | 964 | ||
- | 965 | #time.sleep(3) |
|
- | 966 | ||
- | 967 | ## DISTURB |
|
- | 968 | msg = MkProtocol.MkMsg(address=2, cmd='f', data=[7, 50]) |
|
- | 969 | self.mk.sendMsg(msg) |
|
- | 970 | time.sleep(.1) |
|
- | 971 | ||
- | 972 | #data = self.mk.doVibrationTest(1000, channel) |
|
- | 973 | messages = self.mk.recordDbgMsg(0.05, 20*5) |
|
- | 974 | data = [] |
|
- | 975 | for msg in messages: |
|
- | 976 | data.append(msg.getAngleRoll()) |
|
- | 977 | print data |
|
- | 978 | ||
- | 979 | vt = VibTest(self.param.descr, voltage, self.param.motors, I, "AngleRoll", data) |
|
- | 980 | evt = MeasDataEvent(vibTest = vt) |
|
- | 981 | wx.PostEvent(self.evtConsumer, evt) |
|
- | 982 | ||
- | 983 | self._sendEvent("Original Settings") |
|
959 | evt = MeasDataEvent(vibTest = vt) |
984 | self.mk.sendSettings(orgSetting.getSettings()) |
960 | wx.PostEvent(self.evtConsumer, evt) |
985 | time.sleep(1) |
Line 961... | Line 986... | ||
961 | 986 | ||
962 | if voltage<minVoltage: |
987 | if voltage<minVoltage: |
963 | raise Exception("Voltage too low") |
988 | raise Exception("Voltage too low") |
964 | 989 | ||
Line 965... | Line 990... | ||
965 | self._sendEvent("Done !", parVoltage=(minVoltage, maxVoltage, voltage)) |
990 | self._sendEvent("Done !", parVoltage=(minVoltage, maxVoltage, voltage)) |
966 | 991 | ||
Line 1036... | Line 1061... | ||
1036 | 1061 | ||
Line 1037... | Line 1062... | ||
1037 | return self.filteredData |
1062 | return self.filteredData |
1038 | 1063 | ||
- | 1064 | def getVibValue(self): |
|
1039 | def getVibValue(self): |
1065 | if self.vibValue == None: |
1040 | if self.vibValue == None: |
1066 | fd = self.getRawData() |
1041 | fd = self.getFilteredData()[100:-100]; |
1067 | #fd = self.getFilteredData()[100:-100]; |
1042 | if self.useRms: |
1068 | if self.useRms: |
1043 | print "RMS" |
1069 | print "RMS" |
1044 | self.vibValue = math.sqrt(sum([x*x for x in fd])/len(fd))*2*math.sqrt(2) |
1070 | self.vibValue = math.sqrt(sum([x*x for x in fd])/len(fd))*2*math.sqrt(2) |
Line 1241... | Line 1267... | ||
1241 | if __name__ == "__main__": |
1267 | if __name__ == "__main__": |
Line 1242... | Line 1268... | ||
1242 | 1268 | ||
Line 1243... | Line 1269... | ||
1243 | rootPath = os.path.abspath(os.path.dirname(sys.argv[0])) |
1269 | rootPath = os.path.abspath(os.path.dirname(sys.argv[0])) |
1244 | 1270 | ||
1245 | print rootPath |
1271 | print rootPath |
1246 | 1272 |