上位机添加了调试模式,可以显示原始文本数据。更新了物料清单里面的电机购买链接

master
zrg 2021-12-21 16:16:10 +08:00
parent 3b5ff6d51c
commit f69c3008c8
6 changed files with 98 additions and 28 deletions

View File

@ -135,10 +135,14 @@ void setup() {
ESP.restart(); ESP.restart();
} }
// eeprom 读取 // eeprom 读取
int k,j;
float nan = EEPROM.readFloat(0); j = 0;
if(isnan(nan)) for(k=0;k<=24;k=k+4)
{
float nan = EEPROM.readFloat(k);
if(isnan(nan))
{ {
j = 1;
Serial.println("frist write"); Serial.println("frist write");
EEPROM.writeFloat(0, target_angle); delay(10);EEPROM.commit(); EEPROM.writeFloat(0, target_angle); delay(10);EEPROM.commit();
EEPROM.writeFloat(4, swing_up_voltage); delay(10);EEPROM.commit(); EEPROM.writeFloat(4, swing_up_voltage); delay(10);EEPROM.commit();
@ -148,8 +152,9 @@ if(isnan(nan))
EEPROM.writeFloat(20, v_p_2); delay(10);EEPROM.commit(); EEPROM.writeFloat(20, v_p_2); delay(10);EEPROM.commit();
EEPROM.writeFloat(24, v_i_2); delay(10);EEPROM.commit(); EEPROM.writeFloat(24, v_i_2); delay(10);EEPROM.commit();
} }
else }
{ if(j == 0)
{
target_angle = EEPROM.readFloat(0); target_angle = EEPROM.readFloat(0);
swing_up_voltage = EEPROM.readFloat(4); swing_up_voltage = EEPROM.readFloat(4);
swing_up_angle = EEPROM.readFloat(8); swing_up_angle = EEPROM.readFloat(8);
@ -159,7 +164,7 @@ if(isnan(nan))
v_i_2 = EEPROM.readFloat(24); v_i_2 = EEPROM.readFloat(24);
motor.PID_velocity.P = v_p_1; motor.PID_velocity.P = v_p_1;
motor.PID_velocity.I = v_i_1; motor.PID_velocity.I = v_i_1;
} }
//命令设置 //命令设置
comm.add("TA",do_TA); comm.add("TA",do_TA);
comm.add("START",do_START); comm.add("START",do_START);
@ -364,12 +369,14 @@ if (abs(pendulum_angle) < swing_up_angle) // if angle small enough stabilize 0.5
Serial.print(pitch);Serial.print("\t"); Serial.print(pitch);Serial.print("\t");
Serial.print(kalAngleZ);Serial.print("\t"); Serial.print(kalAngleZ);Serial.print("\t");
// 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");
// Serial.print(target_angle);Serial.print("\t"); Serial.print(motor.voltage.q);Serial.print("\t");
// Serial.print(pendulum_angle);Serial.print("\t");
// Serial.print(gyroZrate);Serial.print("\t"); Serial.print(target_angle);Serial.print("\t");
Serial.print(pendulum_angle);Serial.print("\t");
Serial.print(gyroZrate);Serial.print("\t");
Serial.print("\r\n"); Serial.print("\r\n");
#endif #endif
// motor.move(target_velocity); // motor.move(target_velocity);

View File

@ -1,5 +1,6 @@
import sys import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
from PyQt5.QtGui import QTextCursor
from main_ui import * from main_ui import *
from wifi_udp import * from wifi_udp import *
import threading #引入并行 import threading #引入并行
@ -7,12 +8,13 @@ import numpy as np
import pyqtgraph as pg import pyqtgraph as pg
import re import re
from sharedcomponets import GUIToolKit from sharedcomponets import GUIToolKit
import copy
class MyWindow(QMainWindow, Ui_MainWindow): class MyWindow(QMainWindow, Ui_MainWindow):
signalColors = [GUIToolKit.RED_COLOR, GUIToolKit.BLUE_COLOR, GUIToolKit.PURPLE_COLOR, GUIToolKit.YELLOW_COLOR, signalColors = [GUIToolKit.RED_COLOR, GUIToolKit.BLUE_COLOR, GUIToolKit.PURPLE_COLOR, GUIToolKit.YELLOW_COLOR,
GUIToolKit.MAROON_COLOR, GUIToolKit.ORANGE_COLOR, GUIToolKit.GREEN_COLOR] GUIToolKit.MAROON_COLOR, GUIToolKit.ORANGE_COLOR, GUIToolKit.GREEN_COLOR]
signalIcons = ['reddot', 'bluedot', 'purpledot', 'yellowdot', 'maroondot', 'orangedot', 'greendot'] signalIcons = ['reddot', 'bluedot', 'purpledot', 'yellowdot', 'maroondot', 'orangedot', 'greendot']
textColors = ['FF5C5C','398AD9','5BEC8D','FD42AC','FF33FF','4B8200','DE87B8']
def __init__(self, parent=None): def __init__(self, parent=None):
super(MyWindow, self).__init__(parent) super(MyWindow, self).__init__(parent)
self.setupUi(self) self.setupUi(self)
@ -23,8 +25,6 @@ class MyWindow(QMainWindow, Ui_MainWindow):
# self.CreateItems() # self.CreateItems()
# 设置信号与槽 # 设置信号与槽
self.CreateSignalSlot() self.CreateSignalSlot()
# 设置信号与槽 # 设置信号与槽
def CreateSignalSlot(self): def CreateSignalSlot(self):
self.horizontalSlider_1.valueChanged.connect(self.horizontalSlider_1_valueChanged) self.horizontalSlider_1.valueChanged.connect(self.horizontalSlider_1_valueChanged)
@ -41,6 +41,25 @@ class MyWindow(QMainWindow, Ui_MainWindow):
self.VI1_pushButton.clicked.connect(self.VI1_pushButton_clicked) self.VI1_pushButton.clicked.connect(self.VI1_pushButton_clicked)
self.VP2_pushButton.clicked.connect(self.VP2_pushButton_clicked) self.VP2_pushButton.clicked.connect(self.VP2_pushButton_clicked)
self.VI2_pushButton.clicked.connect(self.VI2_pushButton_clicked) self.VI2_pushButton.clicked.connect(self.VI2_pushButton_clicked)
self.raw_pushButton.clicked.connect(self.raw_pushButton_clicked)
self.wave_pushButton.clicked.connect(self.wave_pushButton_clicked)
def raw_pushButton_clicked(self):
self.change_state = 1
self.stackedWidget.setCurrentIndex(1)
# for i in range(self.gridLayout.count()):
# self.gridLayout.removeWidget(self.gridLayout.itemAt(i).widget())
# self.gridLayout.addWidget(self.raw_line)
def wave_pushButton_clicked(self):
self.change_state = 0
self.stackedWidget.setCurrentIndex(0)
# for i in range(self.gridLayout.count()):
# self.gridLayout.removeWidget(self.gridLayout.itemAt(i).widget())
#
#
# self.gridLayout.addWidget(self.plotWidget)
# 设置实例 # 设置实例
def CreateItems(self): def CreateItems(self):
# 定时器-绘图刷新 # 定时器-绘图刷新
@ -54,7 +73,9 @@ class MyWindow(QMainWindow, Ui_MainWindow):
# wifi变量 # wifi变量
self.wifi_recv_flag = 0 self.wifi_recv_flag = 0
self.close_flag = 1 self.close_flag = 1
self.change_state = 0
self.re_item = [] self.re_item = []
self.raw_roll = 0
def plot_init(self): def plot_init(self):
# 绘图对象 # 绘图对象
pg.setConfigOptions(antialias=True) pg.setConfigOptions(antialias=True)
@ -81,8 +102,16 @@ class MyWindow(QMainWindow, Ui_MainWindow):
self.signalPlotFlags.append(True) self.signalPlotFlags.append(True)
# add callback # add callback
checkBox.stateChanged.connect(self.signalPlotFlagUpdate) checkBox.stateChanged.connect(self.signalPlotFlagUpdate)
self.gridLayout.addWidget(self.plotWidget) self.stackedWidget = QtWidgets.QStackedWidget()
self.gridLayout.addWidget(self.stackedWidget)
self.raw_line = QtWidgets.QTextEdit()
self.raw_line.setStyleSheet('background: rgb(0, 0, 0)')
self.stackedWidget.addWidget(self.plotWidget)
self.stackedWidget.addWidget(self.raw_line)
self.tool_layout.addWidget(self.controlPlotWidget) self.tool_layout.addWidget(self.controlPlotWidget)
# checkbox # checkbox
def signalPlotFlagUpdate(self): def signalPlotFlagUpdate(self):
for i, (checkBox, plotFlag) in enumerate(zip(self.controlPlotWidget.signalCheckBox, self.signalPlotFlags)): for i, (checkBox, plotFlag) in enumerate(zip(self.controlPlotWidget.signalCheckBox, self.signalPlotFlags)):
@ -178,16 +207,23 @@ class MyWindow(QMainWindow, Ui_MainWindow):
recv_data = recv_data.split(',') recv_data = recv_data.split(',')
"""处理接受的信息""" """处理接受的信息"""
# print(recv_data) # print(recv_data)
self.re_text = ''
for i, data in enumerate(recv_data): for i, data in enumerate(recv_data):
if self.signalPlotFlags[i]: if self.signalPlotFlags[i]:
self.re_item.append(''.join(re.split(r'[^A-Za-z]', data))) # self.re_item.append(''.join(re.split(r'[^A-Za-z]', data)))
data = data.replace(self.re_item[i],'') data = data.replace(self.re_item[i],'')
if self.change_state:
self.re_text += '<font color=\"#{1}\">{0}\t</font>'.format(data,self.textColors[i])
else:
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
def update_plot(self): def update_plot(self):
if self.wifi_recv_flag: if self.wifi_recv_flag:
if self.change_state:
self.raw_line.append(self.re_text)
if self.raw_roll:
self.raw_line.moveCursor(QTextCursor.End)
else:
for i, plotFlag in enumerate(self.signalPlotFlags): for i, plotFlag in enumerate(self.signalPlotFlags):
if plotFlag: if plotFlag:
self.signalPlots[i].setData(self.timeArray, self.signalDataArrays[i]) self.signalPlots[i].setData(self.timeArray, self.signalDataArrays[i])
@ -196,6 +232,7 @@ class MyWindow(QMainWindow, Ui_MainWindow):
def closeEvent(self, a0: QtGui.QCloseEvent) -> None: def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
print("关闭") print("关闭")
self.udp.send_message('START')
self.close_flag = 0 self.close_flag = 0
self.udp.udpClientSocket.close() self.udp.udpClientSocket.close()
@ -247,6 +284,9 @@ class ControlPlotPanel(QtWidgets.QWidget):
self.signalCheckBox.append(checkBox) self.signalCheckBox.append(checkBox)
self.horizontalLayout1.addWidget(checkBox) self.horizontalLayout1.addWidget(checkBox)
def zoomAllPlot(self): def zoomAllPlot(self):
if self.controlledPlot.change_state:
self.controlledPlot.raw_roll = ~self.controlledPlot.raw_roll
else:
self.controlledPlot.plotWidget.enableAutoRange() self.controlledPlot.plotWidget.enableAutoRange()
def wifi_recv_open_pushButton_clicked(self): def wifi_recv_open_pushButton_clicked(self):
if self.controlledPlot.wifi_recv_flag == 0: if self.controlledPlot.wifi_recv_flag == 0:

View File

@ -54,6 +54,12 @@ class Ui_MainWindow(object):
self.tool_layout_2 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_6) self.tool_layout_2 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_6)
self.tool_layout_2.setContentsMargins(0, 0, 0, 0) self.tool_layout_2.setContentsMargins(0, 0, 0, 0)
self.tool_layout_2.setObjectName("tool_layout_2") self.tool_layout_2.setObjectName("tool_layout_2")
self.wave_pushButton = QtWidgets.QPushButton(self.horizontalLayoutWidget_6)
self.wave_pushButton.setObjectName("wave_pushButton")
self.tool_layout_2.addWidget(self.wave_pushButton)
self.raw_pushButton = QtWidgets.QPushButton(self.horizontalLayoutWidget_6)
self.raw_pushButton.setObjectName("raw_pushButton")
self.tool_layout_2.addWidget(self.raw_pushButton)
self.groupBox_3 = QtWidgets.QGroupBox(self.centralwidget) self.groupBox_3 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_3.setGeometry(QtCore.QRect(10, 10, 291, 381)) self.groupBox_3.setGeometry(QtCore.QRect(10, 10, 291, 381))
self.groupBox_3.setObjectName("groupBox_3") self.groupBox_3.setObjectName("groupBox_3")
@ -354,6 +360,8 @@ class Ui_MainWindow(object):
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.groupBox_2.setTitle(_translate("MainWindow", "可视化图表")) self.groupBox_2.setTitle(_translate("MainWindow", "可视化图表"))
self.wave_pushButton.setText(_translate("MainWindow", "波形图"))
self.raw_pushButton.setText(_translate("MainWindow", "原始数据"))
self.groupBox_3.setTitle(_translate("MainWindow", "command命令")) self.groupBox_3.setTitle(_translate("MainWindow", "command命令"))
self.wifi_command_pushButton_1.setText(_translate("MainWindow", "发送")) self.wifi_command_pushButton_1.setText(_translate("MainWindow", "发送"))
self.wifi_command_pushButton_2.setText(_translate("MainWindow", "发送")) self.wifi_command_pushButton_2.setText(_translate("MainWindow", "发送"))

View File

@ -99,7 +99,22 @@
<height>31</height> <height>31</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="tool_layout_2"/> <layout class="QHBoxLayout" name="tool_layout_2">
<item>
<widget class="QPushButton" name="wave_pushButton">
<property name="text">
<string>波形图</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="raw_pushButton">
<property name="text">
<string>原始数据</string>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</widget> </widget>
<widget class="QGroupBox" name="groupBox_3"> <widget class="QGroupBox" name="groupBox_3">

Binary file not shown.