diff --git a/arduino/main/main.ino b/arduino/main/main.ino index 2cbf596..38ebedc 100644 --- a/arduino/main/main.ino +++ b/arduino/main/main.ino @@ -260,7 +260,7 @@ void loop() { } #endif -#if 0 +#if 1 Serial.print(target_voltage);Serial.print("\t"); Serial.print(target_velocity);Serial.print("\t"); Serial.print(motor.shaft_velocity);Serial.print("\t"); diff --git a/python_gui/gui/main.py b/python_gui/gui/main.py index 35d710c..9c6a04f 100644 --- a/python_gui/gui/main.py +++ b/python_gui/gui/main.py @@ -5,7 +5,7 @@ from wifi_udp import * import threading #引入并行 import numpy as np import pyqtgraph as pg - +import re RED_COLOR = (255, 92, 92) GREEN_COLOR = (57, 217, 138) @@ -25,8 +25,7 @@ class MyWindow(QMainWindow, Ui_MainWindow): self.CreateItems() # 设置信号与槽 self.CreateSignalSlot() - # 图表初始化 - self.plot_init() + # 设置信号与槽 def CreateSignalSlot(self): @@ -50,21 +49,21 @@ class MyWindow(QMainWindow, Ui_MainWindow): self.target_velocity = 0 self.now_velocity = 0 self.close_flag = 1 + self.re_item = [] def plot_init(self): # 绘图对象 self.plotWidget = pg.PlotWidget() self.plotWidget.showGrid(x=True, y=True, alpha=0.5) # 图表可视化数组 - self.signals = ['now_Angle', 'tag_Angle'] - self.signal_tooltip = ['now_Angle ', 'tag_Angle'] - self.signalColors = [RED_COLOR, BLUE_COLOR] - self.signalIcons = ['reddot', 'bluedot'] + signalColors = [RED_COLOR, BLUE_COLOR, PURPLE_COLOR, YELLOW_COLOR, + MAROON_COLOR, ORANGE_COLOR, GREEN_COLOR] + signalIcons = ['reddot', 'bluedot', 'purpledot', 'yellowdot', 'maroondot', 'orangedot', 'greendot'] self.numberOfSamples = 300 self.signalDataArrays = [] self.signalPlots = [] self.signalPlotFlags = [] self.timeArray = np.arange(-self.numberOfSamples, 0, 1) - for (sig, sigColor, tooltip) in zip(self.signals, self.signalColors, self.signal_tooltip): + for (sig, sigColor, tooltip) in zip(self.re_item, signalColors, self.re_item): # define signal plot data array self.signalDataArrays.append(np.zeros(self.numberOfSamples)) # configure signal plot parameters @@ -88,6 +87,17 @@ class MyWindow(QMainWindow, Ui_MainWindow): try: print(self.wifi_IP_lineEdit.text(),type(self.wifi_IP_lineEdit.text())) self.udp.udpClientSocket.bind((self.wifi_IP_lineEdit.text(), 2333)) + # 第一次接受数据,用于判断项目数, + recv_data = self.udp.udpClientSocket.recv(1024) + recv_data = recv_data.decode('utf-8') + recv_data = recv_data[:-1] + recv_data = recv_data.split(',') + """处理接受的信息""" + for i, data in enumerate(recv_data): + self.re_item.append(''.join(re.split(r'[^A-Za-z]', data))) + print(self.re_item) + # 图表初始化 + self.plot_init() t1 = threading.Thread(target=self.udp_recv) t1.start() self.wifi_recv_open_pushButton.setEnabled(True) @@ -106,22 +116,23 @@ class MyWindow(QMainWindow, Ui_MainWindow): recv_data = self.udp.udpClientSocket.recv(1024) recv_data = recv_data.decode('utf-8') recv_data = recv_data[:-1] - self.udp_data = recv_data.split(',') + recv_data = recv_data.split(',') """处理接受的信息""" - print(len(self.udp_data)) - for i, data in enumerate(self.udp_data): + print(recv_data) + for i, data in enumerate(recv_data): + self.re_item.append(''.join(re.split(r'[^A-Za-z]', data))) + data = re.findall(r"\d+\.?\d*", data) # print(i,data) - # self.signalDataArrays[i] = np.roll(self.signalDataArrays[i], -1) - # self.signalDataArrays[i][-1] = data + self.signalDataArrays[i] = np.roll(self.signalDataArrays[i], -1) + self.signalDataArrays[i][-1] = data[0] pass def update_plot(self): - pass - # if self.wifi_recv_flag: - # for i, plotFlag in enumerate(self.signalPlotFlags): - # self.signalPlots[i].setData(self.timeArray, self.signalDataArrays[i]) - # self.signalPlots[i].updateItems() - # self.signalPlots[i].sigPlotChanged.emit(self.signalPlots[i]) + if self.wifi_recv_flag: + for i, plotFlag in enumerate(self.signalPlotFlags): + self.signalPlots[i].setData(self.timeArray, self.signalDataArrays[i]) + self.signalPlots[i].updateItems() + self.signalPlots[i].sigPlotChanged.emit(self.signalPlots[i]) def closeEvent(self, a0: QtGui.QCloseEvent) -> None: self.close_flag = 0 diff --git a/python_gui/gui/main_ui.py b/python_gui/gui/main_ui.py index cbf40f1..7a06b4c 100644 --- a/python_gui/gui/main_ui.py +++ b/python_gui/gui/main_ui.py @@ -17,12 +17,6 @@ class Ui_MainWindow(object): MainWindow.resize(800, 749) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") - self.gridLayoutWidget = QtWidgets.QWidget(self.centralwidget) - self.gridLayoutWidget.setGeometry(QtCore.QRect(180, 20, 581, 361)) - self.gridLayoutWidget.setObjectName("gridLayoutWidget") - self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget) - self.gridLayout.setContentsMargins(0, 0, 0, 0) - self.gridLayout.setObjectName("gridLayout") self.groupBox = QtWidgets.QGroupBox(self.centralwidget) self.groupBox.setGeometry(QtCore.QRect(20, 420, 241, 61)) self.groupBox.setObjectName("groupBox") @@ -39,10 +33,6 @@ class Ui_MainWindow(object): self.wifi_config_pushButton = QtWidgets.QPushButton(self.horizontalLayoutWidget) self.wifi_config_pushButton.setObjectName("wifi_config_pushButton") self.horizontalLayout.addWidget(self.wifi_config_pushButton) - self.wifi_recv_open_pushButton = QtWidgets.QPushButton(self.centralwidget) - self.wifi_recv_open_pushButton.setEnabled(False) - self.wifi_recv_open_pushButton.setGeometry(QtCore.QRect(180, 380, 93, 28)) - self.wifi_recv_open_pushButton.setObjectName("wifi_recv_open_pushButton") self.horizontalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget) self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(570, 440, 104, 31)) self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2") @@ -75,6 +65,19 @@ class Ui_MainWindow(object): self.angle_lineEdit = QtWidgets.QLineEdit(self.horizontalLayoutWidget_3) self.angle_lineEdit.setObjectName("angle_lineEdit") self.horizontalLayout_3.addWidget(self.angle_lineEdit) + self.groupBox_2 = QtWidgets.QGroupBox(self.centralwidget) + self.groupBox_2.setGeometry(QtCore.QRect(190, 0, 601, 391)) + self.groupBox_2.setObjectName("groupBox_2") + self.gridLayoutWidget = QtWidgets.QWidget(self.groupBox_2) + self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 20, 581, 361)) + self.gridLayoutWidget.setObjectName("gridLayoutWidget") + self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget) + self.gridLayout.setContentsMargins(0, 0, 0, 0) + self.gridLayout.setObjectName("gridLayout") + self.wifi_recv_open_pushButton = QtWidgets.QPushButton(self.centralwidget) + self.wifi_recv_open_pushButton.setEnabled(False) + self.wifi_recv_open_pushButton.setGeometry(QtCore.QRect(190, 390, 93, 28)) + self.wifi_recv_open_pushButton.setObjectName("wifi_recv_open_pushButton") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26)) @@ -93,8 +96,9 @@ class Ui_MainWindow(object): self.groupBox.setTitle(_translate("MainWindow", "wifi_IP")) self.wifi_IP_lineEdit.setText(_translate("MainWindow", "192.168.4.2")) self.wifi_config_pushButton.setText(_translate("MainWindow", "设置")) - self.wifi_recv_open_pushButton.setText(_translate("MainWindow", "打开")) self.label.setText(_translate("MainWindow", "速度:")) self.velocity_lineEdit.setText(_translate("MainWindow", "0")) self.label_2.setText(_translate("MainWindow", "目标角度:")) self.angle_lineEdit.setText(_translate("MainWindow", "149")) + self.groupBox_2.setTitle(_translate("MainWindow", "GroupBox")) + self.wifi_recv_open_pushButton.setText(_translate("MainWindow", "打开")) diff --git a/python_gui/gui/main_ui.ui b/python_gui/gui/main_ui.ui index 40b32aa..d93d702 100644 --- a/python_gui/gui/main_ui.ui +++ b/python_gui/gui/main_ui.ui @@ -14,17 +14,6 @@ MainWindow - - - - 180 - 20 - 581 - 361 - - - - @@ -67,22 +56,6 @@ - - - false - - - - 180 - 380 - 93 - 28 - - - - 打开 - - @@ -160,6 +133,46 @@ + + + + 190 + 0 + 601 + 391 + + + + GroupBox + + + + + 10 + 20 + 581 + 361 + + + + + + + + false + + + + 190 + 390 + 93 + 28 + + + + 打开 + + diff --git a/python_gui/gui/test2.py b/python_gui/gui/test2.py index 9e74959..39db4ed 100644 --- a/python_gui/gui/test2.py +++ b/python_gui/gui/test2.py @@ -1,9 +1,5 @@ -import socket - -try: - s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) - s.connect(('8.8.8.8',80)) - ip = s.getsockname()[0] -finally: - s.close() -print(ip) \ No newline at end of file +a = [1,2] +b = [4,5,6,4] +c = [7,8,9,10] +for i,j,k in zip(a,b,c): + print(i,j,k) \ No newline at end of file