parent
73a0223a69
commit
6abe1792c4
|
@ -260,7 +260,7 @@ void loop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if 0
|
#if 1
|
||||||
Serial.print(target_voltage);Serial.print("\t");
|
Serial.print(target_voltage);Serial.print("\t");
|
||||||
Serial.print(target_velocity);Serial.print("\t");
|
Serial.print(target_velocity);Serial.print("\t");
|
||||||
Serial.print(motor.shaft_velocity);Serial.print("\t");
|
Serial.print(motor.shaft_velocity);Serial.print("\t");
|
||||||
|
|
|
@ -5,7 +5,7 @@ from wifi_udp import *
|
||||||
import threading #引入并行
|
import threading #引入并行
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
|
import re
|
||||||
|
|
||||||
RED_COLOR = (255, 92, 92)
|
RED_COLOR = (255, 92, 92)
|
||||||
GREEN_COLOR = (57, 217, 138)
|
GREEN_COLOR = (57, 217, 138)
|
||||||
|
@ -25,8 +25,7 @@ class MyWindow(QMainWindow, Ui_MainWindow):
|
||||||
self.CreateItems()
|
self.CreateItems()
|
||||||
# 设置信号与槽
|
# 设置信号与槽
|
||||||
self.CreateSignalSlot()
|
self.CreateSignalSlot()
|
||||||
# 图表初始化
|
|
||||||
self.plot_init()
|
|
||||||
|
|
||||||
# 设置信号与槽
|
# 设置信号与槽
|
||||||
def CreateSignalSlot(self):
|
def CreateSignalSlot(self):
|
||||||
|
@ -50,21 +49,21 @@ class MyWindow(QMainWindow, Ui_MainWindow):
|
||||||
self.target_velocity = 0
|
self.target_velocity = 0
|
||||||
self.now_velocity = 0
|
self.now_velocity = 0
|
||||||
self.close_flag = 1
|
self.close_flag = 1
|
||||||
|
self.re_item = []
|
||||||
def plot_init(self):
|
def plot_init(self):
|
||||||
# 绘图对象
|
# 绘图对象
|
||||||
self.plotWidget = pg.PlotWidget()
|
self.plotWidget = pg.PlotWidget()
|
||||||
self.plotWidget.showGrid(x=True, y=True, alpha=0.5)
|
self.plotWidget.showGrid(x=True, y=True, alpha=0.5)
|
||||||
# 图表可视化数组
|
# 图表可视化数组
|
||||||
self.signals = ['now_Angle', 'tag_Angle']
|
signalColors = [RED_COLOR, BLUE_COLOR, PURPLE_COLOR, YELLOW_COLOR,
|
||||||
self.signal_tooltip = ['now_Angle ', 'tag_Angle']
|
MAROON_COLOR, ORANGE_COLOR, GREEN_COLOR]
|
||||||
self.signalColors = [RED_COLOR, BLUE_COLOR]
|
signalIcons = ['reddot', 'bluedot', 'purpledot', 'yellowdot', 'maroondot', 'orangedot', 'greendot']
|
||||||
self.signalIcons = ['reddot', 'bluedot']
|
|
||||||
self.numberOfSamples = 300
|
self.numberOfSamples = 300
|
||||||
self.signalDataArrays = []
|
self.signalDataArrays = []
|
||||||
self.signalPlots = []
|
self.signalPlots = []
|
||||||
self.signalPlotFlags = []
|
self.signalPlotFlags = []
|
||||||
self.timeArray = np.arange(-self.numberOfSamples, 0, 1)
|
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
|
# define signal plot data array
|
||||||
self.signalDataArrays.append(np.zeros(self.numberOfSamples))
|
self.signalDataArrays.append(np.zeros(self.numberOfSamples))
|
||||||
# configure signal plot parameters
|
# configure signal plot parameters
|
||||||
|
@ -88,6 +87,17 @@ class MyWindow(QMainWindow, Ui_MainWindow):
|
||||||
try:
|
try:
|
||||||
print(self.wifi_IP_lineEdit.text(),type(self.wifi_IP_lineEdit.text()))
|
print(self.wifi_IP_lineEdit.text(),type(self.wifi_IP_lineEdit.text()))
|
||||||
self.udp.udpClientSocket.bind((self.wifi_IP_lineEdit.text(), 2333))
|
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 = threading.Thread(target=self.udp_recv)
|
||||||
t1.start()
|
t1.start()
|
||||||
self.wifi_recv_open_pushButton.setEnabled(True)
|
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 = self.udp.udpClientSocket.recv(1024)
|
||||||
recv_data = recv_data.decode('utf-8')
|
recv_data = recv_data.decode('utf-8')
|
||||||
recv_data = recv_data[:-1]
|
recv_data = recv_data[:-1]
|
||||||
self.udp_data = recv_data.split(',')
|
recv_data = recv_data.split(',')
|
||||||
"""处理接受的信息"""
|
"""处理接受的信息"""
|
||||||
print(len(self.udp_data))
|
print(recv_data)
|
||||||
for i, data in enumerate(self.udp_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)
|
# print(i,data)
|
||||||
|
|
||||||
# self.signalDataArrays[i] = np.roll(self.signalDataArrays[i], -1)
|
self.signalDataArrays[i] = np.roll(self.signalDataArrays[i], -1)
|
||||||
# self.signalDataArrays[i][-1] = data
|
self.signalDataArrays[i][-1] = data[0]
|
||||||
pass
|
pass
|
||||||
def update_plot(self):
|
def update_plot(self):
|
||||||
pass
|
if self.wifi_recv_flag:
|
||||||
# if self.wifi_recv_flag:
|
for i, plotFlag in enumerate(self.signalPlotFlags):
|
||||||
# for i, plotFlag in enumerate(self.signalPlotFlags):
|
self.signalPlots[i].setData(self.timeArray, self.signalDataArrays[i])
|
||||||
# self.signalPlots[i].setData(self.timeArray, self.signalDataArrays[i])
|
self.signalPlots[i].updateItems()
|
||||||
# self.signalPlots[i].updateItems()
|
self.signalPlots[i].sigPlotChanged.emit(self.signalPlots[i])
|
||||||
# self.signalPlots[i].sigPlotChanged.emit(self.signalPlots[i])
|
|
||||||
|
|
||||||
def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
|
def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
|
||||||
self.close_flag = 0
|
self.close_flag = 0
|
||||||
|
|
|
@ -17,12 +17,6 @@ class Ui_MainWindow(object):
|
||||||
MainWindow.resize(800, 749)
|
MainWindow.resize(800, 749)
|
||||||
self.centralwidget = QtWidgets.QWidget(MainWindow)
|
self.centralwidget = QtWidgets.QWidget(MainWindow)
|
||||||
self.centralwidget.setObjectName("centralwidget")
|
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 = QtWidgets.QGroupBox(self.centralwidget)
|
||||||
self.groupBox.setGeometry(QtCore.QRect(20, 420, 241, 61))
|
self.groupBox.setGeometry(QtCore.QRect(20, 420, 241, 61))
|
||||||
self.groupBox.setObjectName("groupBox")
|
self.groupBox.setObjectName("groupBox")
|
||||||
|
@ -39,10 +33,6 @@ class Ui_MainWindow(object):
|
||||||
self.wifi_config_pushButton = QtWidgets.QPushButton(self.horizontalLayoutWidget)
|
self.wifi_config_pushButton = QtWidgets.QPushButton(self.horizontalLayoutWidget)
|
||||||
self.wifi_config_pushButton.setObjectName("wifi_config_pushButton")
|
self.wifi_config_pushButton.setObjectName("wifi_config_pushButton")
|
||||||
self.horizontalLayout.addWidget(self.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 = QtWidgets.QWidget(self.centralwidget)
|
||||||
self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(570, 440, 104, 31))
|
self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(570, 440, 104, 31))
|
||||||
self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2")
|
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 = QtWidgets.QLineEdit(self.horizontalLayoutWidget_3)
|
||||||
self.angle_lineEdit.setObjectName("angle_lineEdit")
|
self.angle_lineEdit.setObjectName("angle_lineEdit")
|
||||||
self.horizontalLayout_3.addWidget(self.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)
|
MainWindow.setCentralWidget(self.centralwidget)
|
||||||
self.menubar = QtWidgets.QMenuBar(MainWindow)
|
self.menubar = QtWidgets.QMenuBar(MainWindow)
|
||||||
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
|
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.groupBox.setTitle(_translate("MainWindow", "wifi_IP"))
|
||||||
self.wifi_IP_lineEdit.setText(_translate("MainWindow", "192.168.4.2"))
|
self.wifi_IP_lineEdit.setText(_translate("MainWindow", "192.168.4.2"))
|
||||||
self.wifi_config_pushButton.setText(_translate("MainWindow", "设置"))
|
self.wifi_config_pushButton.setText(_translate("MainWindow", "设置"))
|
||||||
self.wifi_recv_open_pushButton.setText(_translate("MainWindow", "打开"))
|
|
||||||
self.label.setText(_translate("MainWindow", "速度:"))
|
self.label.setText(_translate("MainWindow", "速度:"))
|
||||||
self.velocity_lineEdit.setText(_translate("MainWindow", "0"))
|
self.velocity_lineEdit.setText(_translate("MainWindow", "0"))
|
||||||
self.label_2.setText(_translate("MainWindow", "目标角度:"))
|
self.label_2.setText(_translate("MainWindow", "目标角度:"))
|
||||||
self.angle_lineEdit.setText(_translate("MainWindow", "149"))
|
self.angle_lineEdit.setText(_translate("MainWindow", "149"))
|
||||||
|
self.groupBox_2.setTitle(_translate("MainWindow", "GroupBox"))
|
||||||
|
self.wifi_recv_open_pushButton.setText(_translate("MainWindow", "打开"))
|
||||||
|
|
|
@ -14,17 +14,6 @@
|
||||||
<string>MainWindow</string>
|
<string>MainWindow</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget">
|
<widget class="QWidget" name="centralwidget">
|
||||||
<widget class="QWidget" name="gridLayoutWidget">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>180</x>
|
|
||||||
<y>20</y>
|
|
||||||
<width>581</width>
|
|
||||||
<height>361</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="gridLayout"/>
|
|
||||||
</widget>
|
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
|
@ -67,22 +56,6 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QPushButton" name="wifi_recv_open_pushButton">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>180</x>
|
|
||||||
<y>380</y>
|
|
||||||
<width>93</width>
|
|
||||||
<height>28</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>打开</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QWidget" name="horizontalLayoutWidget_2">
|
<widget class="QWidget" name="horizontalLayoutWidget_2">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
|
@ -160,6 +133,46 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QGroupBox" name="groupBox_2">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>190</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>601</width>
|
||||||
|
<height>391</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="title">
|
||||||
|
<string>GroupBox</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="gridLayoutWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>10</x>
|
||||||
|
<y>20</y>
|
||||||
|
<width>581</width>
|
||||||
|
<height>361</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout"/>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<widget class="QPushButton" name="wifi_recv_open_pushButton">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>190</x>
|
||||||
|
<y>390</y>
|
||||||
|
<width>93</width>
|
||||||
|
<height>28</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>打开</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenuBar" name="menubar">
|
<widget class="QMenuBar" name="menubar">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
import socket
|
a = [1,2]
|
||||||
|
b = [4,5,6,4]
|
||||||
try:
|
c = [7,8,9,10]
|
||||||
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
for i,j,k in zip(a,b,c):
|
||||||
s.connect(('8.8.8.8',80))
|
print(i,j,k)
|
||||||
ip = s.getsockname()[0]
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
print(ip)
|
|
Loading…
Reference in New Issue