Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tombshaw committed Nov 29, 2018
2 parents d3f2cbe + 0d3b141 commit e258b73
Show file tree
Hide file tree
Showing 23 changed files with 966 additions and 129,640 deletions.
497 changes: 497 additions & 0 deletions GUI/GUIFunctions.py

Large diffs are not rendered by default.

143 changes: 100 additions & 43 deletions gui/GUI_final.py → GUI/GUI_final.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@
import GUIFunctions
# import SpliceDataFunctions
# import Learn
# import Learn_original
import sys
from parameterGUI import Ui_parameterSelection
import multi_param_learn
import Learn_original
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from splicing import Ui_Splicing_mode_Dialog

# **************************** My import *********************************

# **************************** Class Canvas *****************************
class Figure_Canvas(FigureCanvas): # 通过继承FigureCanvas类,使得该类既是一个PyQt5的Qwidget,又是一个matplotlib的FigureCanvas,这是连接pyqt5与matplot lib的关键
class Figure_Canvas(FigureCanvas):

def __init__(self, parent=None, width=3.28, height=2, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi) # 创建一个Figure,注意:该Figure为matplotlib下的figure,不是matplotlib.pyplot下面的figure
fig = Figure(figsize=(width, height), dpi=dpi)

FigureCanvas.__init__(self, fig) # 初始化父类
FigureCanvas.__init__(self, fig) #
FigureCanvas.updateGeometry(self)
self.setParent(parent)

# Figure_Canvas.set_window_title(self,"hello")

self.axes = fig.add_subplot(111) # 调用figure下面的add_subplot方法,类似于matplotlib.pyplot下面的subplot方法
self.axes = fig.add_subplot(111)

def test(self,a):
self.axes.plot(a)
Expand Down Expand Up @@ -168,6 +169,7 @@ def setupUi(self):
self.tab.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(DroneGUI)


# **************************** My Code_Multi-selectionmode *****************
self.listWidget.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
self.listWidget_2.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
Expand Down Expand Up @@ -301,15 +303,15 @@ def show_parameter(self):


def confirmed(self):
self.para_dic2={"Pitch":"test_mavlink_ahrs3_t_pitch",
self.para_dic2={"Pitch":"mavlink_ahrs3_t_pitch",
"Yaw":"mavlink_ahrs3_t_yaw","Pitch rate":"mavlink_attitude_t_pitch rate",
"Roll rate":"mavlink_attitude_t_roll rate",
"Yaw angle":"mavlink_attitude_t_yaw angle" ,"Roll":"mavlink_nav_controller_output_t_nav_roll",
"Altitude":"mavlink_ahrs2_t_altitude","X Accel":"mavlink_raw_imu_t_Xaccel",
"Yaw angle":"mavlink_attitude_t_yaw angle" ,"Roll":"mavlink_ahrs3_t_roll",
"Altitude":"mavlink_ahrs3_t_altitude","X Accel":"mavlink_raw_imu_t_Xaccel",
"X Gyro": "mavlink_raw_imu_t_XGyro","X Mag": "mavlink_raw_imu_t_XMag",
"Y Accel":"mavlink_raw_imu_t_Yaccel", "Y Gyro":"mavlink_raw_imu_t_YGyro", "Y Mag": "mavlink_raw_imu_t_YMag",
"Z Accel":"mavlink_raw_imu_t_Zaccel","Z Gyro":"mavlink_raw_imu_t_ZGyro","Z Mag:":"mavlink_raw_imu_t_ZMag",
"Z vibration":"mavlink_vibration_t_vibration_z"}
"Z Accel":"mavlink_raw_imu_t_Zaccel","Z Gyro":"mavlink_raw_imu_t_ZGyro","Z Mag":"mavlink_raw_imu_t_ZMag",
"Z vibration":"mavlink_vibration_t_vibration_z","Yaw rate":"mavlink_attitude_t_yaw rate"}
self.para_dic = {"Pitch": "pitch",
"Yaw": "yaw", "Pitch rate": "pitch rate",
"Roll rate": "roll rate",
Expand All @@ -320,8 +322,8 @@ def confirmed(self):
"Y Accel": "Yaccel", "Y Gyro": "YGyro",
"Y Mag": "YMag",
"Z Accel": "Zaccel", "Z Gyro": "ZGyro",
"Z Mag:": "ZMag",
"Z vibration": "vibration_z"}
"Z Mag": "ZMag",
"Z vibration": "vibration_z","Yaw rate":"yaw rate"}

global selection
global selection_name
Expand Down Expand Up @@ -379,6 +381,9 @@ def confirmed(self):
if self.ui.Z_vibration.isChecked():
# self.selection.append("mavlink_vibration_t_vibration_z")
self.selection_name.append("Z vibration")
if self.ui.Yaw_rate.isChecked():
# self.selection.append("mavlink_vibration_t_vibration_z")
self.selection_name.append("Yaw rate")
self.parameter.close()


Expand Down Expand Up @@ -411,62 +416,114 @@ def datasplicing_mode_selection(self):
# self.ui.Confirmation_buttonBox.accepted.connect(self.confirmed)

def datasplicing(self):
self.tab.setCurrentIndex(2)
self.para_selection = []
self.para_selection2 = []
self.para_selection_name = []
self.x_test_final = []

for i in range(self.listWidget_3.count()):
self.para_selection_name.append(self.listWidget_3.item(i).text())
self.para_selection.append(self.para_dic[self.listWidget_3.item(i).text()])
self.para_selection2.append(self.para_dic2[self.listWidget_3.item(i).text()])
self.readedFileList = [self.listWidget_2.item(i).text() for i in range(self.listWidget_2.count())]
# print (self.readedFileList,self.para_selection,self.para_selection_name,self.para_selection2)

if self.ui2.radioButton.isChecked():
self.tab.setCurrentIndex(2)
self.para_selection = []
self.para_selection2=[]
self.para_selection_name = []
for i in range(self.listWidget_3.count()):
self.para_selection_name.append(self.listWidget_3.item(i).text())
self.para_selection.append(self.para_dic[self.listWidget_3.item(i).text()])
self.para_selection2.append(self.para_dic2[self.listWidget_3.item(i).text()])
print("Selected parameters are:", self.para_selection_name)

print("Selected parameters are:", self.para_selection_name)

self.readedFileList = [self.listWidget_2.item(i).text() for i in range(self.listWidget_2.count())]
print (self.readedFileList,self.para_selection,self.para_selection_name,self.para_selection2)

GUIFunctions.main(self.readedFileList[0],self.para_selection[0],self.para_selection_name[0])
if self.ui2.radioButton.isChecked(): #manual
self.b = GUIFunctions.main(self.readedFileList[0], self.para_selection[0], self.para_selection_name[0])
self.x_test_final.append(self.b[4])
self.check = 0

for i in range (1,len(self.para_selection)):

self.x_test=GUIFunctions.main3(self.readedFileList[0],self.para_selection[i],self.b[3])
self.x_test_final.append(self.x_test)


# self.train_data_name = SpliceDataFunctions.main(self.readedFileList[0], self.para_selection[0],
# self.para_selection_name[0])
if self.ui2.radioButton_2.isChecked(): #automatic
self.check=1
self.b = GUIFunctions.main2(self.readedFileList[0], self.para_selection[0])
self.x_test_final.append(self.b[3])

# Make Canvas
self.dr = Figure_Canvas()
a=GUIFunctions.csvParaExtract(self.readedFileList[0],self.para_selection[0])[0]
for i in range(1, len(self.para_selection)):
# GUIFunctions.main3(self.readedFileList[0],self.para_selection[i],self.b[1])
self.x_test2=GUIFunctions.main4(self.readedFileList[0], self.para_selection[i], self.b[1])

# a = SpliceDataFunctions.getTSData(self.readedFileList[0])
self.dr.test(a)
self.graphicscene = QtWidgets.QGraphicsScene() # 第三步,创建一个QGraphicsScene,因为加载的图形(FigureCanvas)不能直接放到graphicview控件中,必须先放到graphicScene,然后再把graphicscene放到graphicview中
self.graphicscene.addWidget(self.dr) # 第四步,把图形放到QGraphicsScene中,注意:图形是作为一个QWidget放到QGraphicsScene中的
self.graphicsView.setScene(self.graphicscene) # 第五步,把QGraphicsScene放入QGraphicsView
self.graphicsView.show() # 最后,调用show方法呈现图形!Voila!!
# self.graphicsView.setAutoFillBackground()
self.x_test_final.append(self.x_test2)

# self.setCentralWidget(self.graphicsView)
# self.graphicsView.setFixedSize(100, 600)
self.dr = Figure_Canvas()

# a = GUIFunctions.csvParaExtract(self.readedFileList[0], self.para_selection[0])[0]

# a = SpliceDataFunctions.getTSData(self.readedFileList[0])
self.dr.test(self.b[0])
self.graphicscene = QtWidgets.QGraphicsScene() #
self.graphicscene.addWidget(self.dr) #
self.graphicsView.setScene(self.graphicscene) #
self.graphicsView.show() #
# self.graphicsView.setAutoFillBackground()

# self.setCentralWidget(self.graphicsView)
# self.graphicsView.setFixedSize(100, 600)


# **************************** My Code_data splice ********************

# **************************** My Code_display prediction ****************
def machinelearning(self):
Learn_original.learn(self.para_selection2[0],self.para_selection_name)

text, ok = QInputDialog.getText(self, 'Input Dialog',
'Enter K value: ')
if ok:
self.k_value=int(text)
# print (self.k_value)


self.learning = multi_param_learn.multi_param_learn(self.para_selection2,None,'Data/')


# self.label_result=Learn_original.machine_learning(self.learning[0],self.learning[1],self.learning[2],self.learning[3])
self.label_result = multi_param_learn.machine_learning(self.x_test_final, self.learning[1], self.learning[2],self.learning[3],self.learning[4],self.learning[5],self.learning[6],self.k_value)

print ("detection result: ",self.label_result[0])

print("majority voting result: ",self.label_result[1])


multi_param_learn.test_data_plot(self.para_selection_name[0],self.x_test_final[0])
# print (self.label_result)
if self.check==0:
GUIFunctions.distLabel(self.b[0],self.b[1],self.label_result[1],self.para_selection_name[0])
if self.check==1:
GUIFunctions.distLabelAuto(self.b[0],self.b[1],self.label_result[1],self.para_selection_name[0])
else:
pass



# **************************** My Code_display prediction ****************


# **************************** My Code_display training data ************
def traning_data_display(self):
multi_param_learn.multi_param_learn(self.para_selection2, None, self.para_selection_name)
learning = multi_param_learn.multi_param_learn(self.para_selection2,None,'Data/')
print (self.para_selection_name[0])
# print (learning[1][0])
# print (learning[2][0])
# print (learning[3][0])
multi_param_learn.training_data_plot(self.para_selection_name[0],learning[1][0],learning[2][0],learning[3])

# **************************** My Code_display training data ************

# **************************** My Code_display test data ************
def test_data_display(self):
a= GUIFunctions.csvParaExtract(self.readedFileList[0],self.para_selection[0])[0]
self.a= GUIFunctions.csvParaExtract(self.readedFileList[0],self.para_selection[0])[0]
# a= SpliceDataFunctions.getTSData(self.readedFileList[0])
GUIFunctions.plotTSData(a,self.para_selection_name[0])
GUIFunctions.plotTSData(self.a,self.para_selection_name[0])
# SpliceDataFunctions.plotTSData()
# **************************** My Code_display test data ************
if __name__ == "__main__":
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit e258b73

Please sign in to comment.