Der Autopilot läuft soweit stop pause resume noch zu testen

This commit is contained in:
jens 2022-11-10 21:42:49 +01:00
parent d57c712016
commit 0d9bb5a0a1
5 changed files with 403 additions and 20 deletions

48
gui2.py
View File

@ -14,7 +14,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object): class Ui_MainWindow(object):
def setupUi(self, MainWindow): def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow") MainWindow.setObjectName("MainWindow")
MainWindow.resize(1071, 869) MainWindow.resize(1071, 868)
self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget") self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget) self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
@ -837,6 +837,45 @@ class Ui_MainWindow(object):
spacerItem4 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) spacerItem4 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_19.addItem(spacerItem4) self.horizontalLayout_19.addItem(spacerItem4)
self.gridLayout_4.addLayout(self.horizontalLayout_19, 2, 0, 1, 1) self.gridLayout_4.addLayout(self.horizontalLayout_19, 2, 0, 1, 1)
self.horizontalLayout_20 = QtWidgets.QHBoxLayout()
self.horizontalLayout_20.setObjectName("horizontalLayout_20")
self.label_28 = QtWidgets.QLabel(self.rheo)
self.label_28.setMaximumSize(QtCore.QSize(80, 16777215))
self.label_28.setObjectName("label_28")
self.horizontalLayout_20.addWidget(self.label_28)
self.start_flow_EDIT = QtWidgets.QLineEdit(self.rheo)
self.start_flow_EDIT.setMaximumSize(QtCore.QSize(50, 16777215))
self.start_flow_EDIT.setObjectName("start_flow_EDIT")
self.horizontalLayout_20.addWidget(self.start_flow_EDIT)
self.label_29 = QtWidgets.QLabel(self.rheo)
self.label_29.setObjectName("label_29")
self.horizontalLayout_20.addWidget(self.label_29)
self.init_BOX = QtWidgets.QCheckBox(self.rheo)
self.init_BOX.setText("")
self.init_BOX.setObjectName("init_BOX")
self.horizontalLayout_20.addWidget(self.init_BOX)
self.label_30 = QtWidgets.QLabel(self.rheo)
self.label_30.setObjectName("label_30")
self.horizontalLayout_20.addWidget(self.label_30)
self.time_wait_EDIT = QtWidgets.QLineEdit(self.rheo)
self.time_wait_EDIT.setMaximumSize(QtCore.QSize(50, 16777215))
self.time_wait_EDIT.setObjectName("time_wait_EDIT")
self.horizontalLayout_20.addWidget(self.time_wait_EDIT)
self.start_auto_BTN = QtWidgets.QPushButton(self.rheo)
self.start_auto_BTN.setObjectName("start_auto_BTN")
self.horizontalLayout_20.addWidget(self.start_auto_BTN)
self.stop_auto_BTN = QtWidgets.QPushButton(self.rheo)
self.stop_auto_BTN.setObjectName("stop_auto_BTN")
self.horizontalLayout_20.addWidget(self.stop_auto_BTN)
self.pause_auto_BTN = QtWidgets.QPushButton(self.rheo)
self.pause_auto_BTN.setObjectName("pause_auto_BTN")
self.horizontalLayout_20.addWidget(self.pause_auto_BTN)
self.resume_auto_BTN = QtWidgets.QPushButton(self.rheo)
self.resume_auto_BTN.setObjectName("resume_auto_BTN")
self.horizontalLayout_20.addWidget(self.resume_auto_BTN)
spacerItem5 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_20.addItem(spacerItem5)
self.gridLayout_4.addLayout(self.horizontalLayout_20, 3, 0, 1, 1)
self.tabWidget.addTab(self.rheo, "") self.tabWidget.addTab(self.rheo, "")
self.tab = QtWidgets.QWidget() self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab") self.tab.setObjectName("tab")
@ -962,6 +1001,13 @@ class Ui_MainWindow(object):
self.pushButton_3.setText(_translate("MainWindow", "Home")) self.pushButton_3.setText(_translate("MainWindow", "Home"))
self.label_26.setText(_translate("MainWindow", "left")) self.label_26.setText(_translate("MainWindow", "left"))
self.pushButton_4.setText(_translate("MainWindow", "inject..")) self.pushButton_4.setText(_translate("MainWindow", "inject.."))
self.label_28.setText(_translate("MainWindow", "level for start flow"))
self.label_29.setText(_translate("MainWindow", "init System"))
self.label_30.setText(_translate("MainWindow", "sec between Messurement"))
self.start_auto_BTN.setText(_translate("MainWindow", "Auto Start"))
self.stop_auto_BTN.setText(_translate("MainWindow", "Stop"))
self.pause_auto_BTN.setText(_translate("MainWindow", "Pause"))
self.resume_auto_BTN.setText(_translate("MainWindow", "Resume"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.rheo), _translate("MainWindow", "Counter")) self.tabWidget.setTabText(self.tabWidget.indexOf(self.rheo), _translate("MainWindow", "Counter"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "Doku")) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "Doku"))
self.menuFile.setTitle(_translate("MainWindow", "File")) self.menuFile.setTitle(_translate("MainWindow", "File"))

101
gui2.ui
View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1071</width> <width>1071</width>
<height>869</height> <height>868</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -1562,6 +1562,105 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_20">
<item>
<widget class="QLabel" name="label_28">
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>level for start flow</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="start_flow_EDIT">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_29">
<property name="text">
<string>init System</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="init_BOX">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_30">
<property name="text">
<string>sec between Messurement</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="time_wait_EDIT">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="start_auto_BTN">
<property name="text">
<string>Auto Start</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="stop_auto_BTN">
<property name="text">
<string>Stop</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pause_auto_BTN">
<property name="text">
<string>Pause</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="resume_auto_BTN">
<property name="text">
<string>Resume</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">

View File

@ -4,6 +4,7 @@ import sys, time, os
import serial import serial
from PyQt5 import QtCore, QtWidgets from PyQt5 import QtCore, QtWidgets
import pyqtgraph as pg import pyqtgraph as pg
from enum import Enum
class MainWindow2( MainWindow): class MainWindow2( MainWindow):
@ -71,6 +72,26 @@ class MainWindow2( MainWindow):
self.ui.pushButton_3.setEnabled(False) self.ui.pushButton_3.setEnabled(False)
self.ui.pushButton_4.setEnabled(False) self.ui.pushButton_4.setEnabled(False)
### Autopilot
self.ui.init_BOX.stateChanged.connect(self.init)
self.startflow = 0
self.timewait = 0
#self.startauto = False
self.ui.start_auto_BTN.clicked.connect(self.start_auto)
self.ui.stop_auto_BTN.clicked.connect(self.stop_auto)
self.ui.pause_auto_BTN.clicked.connect(self.pause_auto)
self.ui.resume_auto_BTN.clicked.connect(self.resume_auto)
self.ui.stop_auto_BTN.setEnabled(False)
self.ui.pause_auto_BTN.setEnabled(False)
self.ui.resume_auto_BTN.setEnabled(False)
self.auto_signals = AutoAff_Signals()
self.auto_signals.rheoleft.connect(self.setwhatsleft)
self.ui.start_flow_EDIT.textChanged.connect(self.startflowedit)
self.ui.time_wait_EDIT.textChanged.connect(self.dotimewait)
################### ESP32 ################### ESP32
def connectESP32(self): def connectESP32(self):
@ -181,7 +202,7 @@ class MainWindow2( MainWindow):
self.ui.checkBox_3.setEnabled(True) self.ui.checkBox_3.setEnabled(True)
self.ui.checkBox_3.setCheckState(False) self.ui.checkBox_3.setCheckState(False)
self.ui.pushButton_3.setEnabled(True) self.ui.pushButton_3.setEnabled(True)
self.ui.pushButton_4.setEnabled(False) self.ui.pushButton_4.setEnabled(False) #zum testen sonst False
time.sleep(1) time.sleep(1)
self.statusBar().showMessage("Successfully connected to Rheo board.") self.statusBar().showMessage("Successfully connected to Rheo board.")
self.getFromRheo() self.getFromRheo()
@ -219,9 +240,17 @@ class MainWindow2( MainWindow):
left = x1 - xx left = x1 - xx
if ( left < 10): if ( left < 10):
self.statusBar().showMessage(f"Inject {xx} left {left} is to small !!") self.statusBar().showMessage(f"Inject {xx} left {left} is to small !!")
self.auto_signals.finished.emit(0)
self.startcounter(0)
return return
if (xx > 7) or (xx<0): if (xx > 7) or (xx<0):
self.ui.checkBox_3.setChecked(False) ## set to load
self.ui.checkBox_3.setChecked(True)
## start pump
#self.ui.send_all_BTN.clicked.emit()
self.ui.run_BTN.clicked.emit()
## enable stop flow
self.ui.checkBox_2.setChecked(True)
time.sleep(1) time.sleep(1)
self.ui.pushButton_4.setEnabled(False) self.ui.pushButton_4.setEnabled(False)
cmd=str(xx)+'\r\n' cmd=str(xx)+'\r\n'
@ -254,6 +283,7 @@ class MainWindow2( MainWindow):
self.ui.label_26.setText(f'left {xx}') self.ui.label_26.setText(f'left {xx}')
self.ui.pushButton_4.setEnabled(True) self.ui.pushButton_4.setEnabled(True)
def sendRheo(self, sendStr): def sendRheo(self, sendStr):
#time.sleep(1) ## functioniert leider nicht #time.sleep(1) ## functioniert leider nicht
self.rheo_serial.flushInput() self.rheo_serial.flushInput()
@ -261,14 +291,13 @@ class MainWindow2( MainWindow):
def getFromRheo(self): def getFromRheo(self):
cmd = "" cmd = ""
thread = Thread(self.getRheoVolume,cmd) self.thread = Thread(self.getRheoVolume,cmd)
thread.signals.finished.connect(lambda:self.thread_finished(thread)) self.thread.signals.finished.connect(lambda:self.thread_finished(self.thread))
thread.signals.result.connect(self.setwhatsleft) #self.threadx[2].signals.result.connect(self.setwhatsleft)
self.threadpool.start(thread) self.threadpool.start(self.thread)
def getRheoVolume(self,cmd): def getRheoVolume(self,cmd):
time.sleep(0.1) time.sleep(0.1)
self.rheo_serial.flushOutput()
self.rheo_serial.flushInput() self.rheo_serial.flushInput()
cmd = str(5)+'\r\n' cmd = str(5)+'\r\n'
self.rheo_serial.write(cmd.encode('utf-8')) self.rheo_serial.write(cmd.encode('utf-8'))
@ -281,17 +310,17 @@ class MainWindow2( MainWindow):
if inp[0] == 60 and inp[-3] == 62 : if inp[0] == 60 and inp[-3] == 62 :
inp = inp[1:-3] inp = inp[1:-3]
y = float(inp.decode('utf-8')) y = float(inp.decode('utf-8'))
self.auto_signals.rheoleft.emit(y)
return y return y
except IndexError: except IndexError:
pass pass
if cnt > 100: #warten bis der Motor steht und der Arduino antwortet if cnt > 100: #warten bis der Motor steht und der Arduino antwortet
return 0 return 0
def startflowedit(self,xx):
self.startflow = float(self.ui.start_flow_EDIT.text())
print(f" startFlow {self.startflow}")
def checkForStopFlow(self):
if self.checkForStopFlow :
if self.y[-1] > self.stopFlowLimit :
self.ui.pause_BTN.clicked.emit()
def updateData(self,x,y): def updateData(self,x,y):
self.x.append(x) self.x.append(x)
@ -299,9 +328,15 @@ class MainWindow2( MainWindow):
self.data_line.setData(self.x,self.y) self.data_line.setData(self.x,self.y)
if self.wait2Stopflow == True: if self.wait2Stopflow == True:
if (self.y[-1] >= self.stopFlowLimit): if (self.y[-1] >= self.stopFlowLimit):
self.ui.pause_BTN.clicked.emit() self.auto_signals.startflow.emit(self.y[-1])
self.ui.stop_BTN.clicked.emit()
self.wait2Stopflow = False self.wait2Stopflow = False
self.ui.checkBox_2.setChecked(False) self.ui.checkBox_2.setChecked(False)
if self.startflow > 0 :
if self.y[-1] < self.startflow :
#print("kann los")
self.auto_signals.endflow.emit(self.y[-1])
def clearPlot(self): def clearPlot(self):
self.x.clear() self.x.clear()
@ -312,6 +347,201 @@ class MainWindow2( MainWindow):
self.esp32_serial.write(sendStr.encode()) self.esp32_serial.write(sendStr.encode())
self.esp32_serial.flushInput() self.esp32_serial.flushInput()
def init(self,state):
if state == QtCore.Qt.Checked:
self.ui.p1_activate_CHECKBOX.setChecked(True)
self.ui.p2_activate_CHECKBOX.setChecked(True)
self.ui.p3_activate_CHECKBOX.setChecked(True)
self.ui.p1_amount_INPUT.setValue(5)
self.ui.p2_amount_INPUT.setValue(5)
self.ui.p3_amount_INPUT.setValue(5)
self.ui.run_BTN.clicked.emit()
self.ui.lineEdit_2.setText("1200")
self.ui.start_flow_EDIT.setText("600")
self.ui.checkBox_2.setChecked(True)
self.ui.lineEdit_3.setText("40")
self.ui.time_wait_EDIT.setText("10")
self.ui.start_BTN.clicked.emit()
else:
self.ui.stop_BTN.clicked.emit()
def setRheoVentil(self,state):
self.ui.checkBox_3.setChecked(state)
def setinit(self,state):
self.ui.init_BOX.setChecked(state)
def startmotor(self,state):
if state == 1:
print("start motor ")
self.ui.run_BTN.clicked.emit()
else :
print("stop motor")
self.ui.stop_BTN.clicked.emit()
def startcounter(self,state):
print(f"start counter {state} ")
if state == 1:
self.ui.start_btn.clicked.emit()
else:
self.ui.stop_btn.clicked.emit()
def checkflow(self,state):
self.ui.checkBox_2.setChecked(state)
def dotimewait(self,xx):
self.timewait = int(self.ui.time_wait_EDIT.text())
print(f" timewait {self.timewait}")
self.auto_signals.timewait.emit(self.timewait)
def start_auto(self):
##
print(f" endflow {self.startflow} ")
self.ui.stop_auto_BTN.setEnabled(True)
self.ui.pause_auto_BTN.setEnabled(True)
self.ui.resume_auto_BTN.setEnabled(False)
self.ui.start_auto_BTN.setEnabled(False)
self.threadx[2] = AutoP()
self.threadx[2].signal.rheoStart.connect(self.sendRheoInject)
self.threadx[2].signal.systeminit.connect(self.setinit)
self.threadx[2].signal.rheoventil.connect(self.setRheoVentil)
self.auto_signals.rheoleft.connect(self.set_volume)
self.auto_signals.startflow.connect(self.set_startflow)
self.auto_signals.endflow.connect(self.set_endflow)
self.auto_signals.finished.connect(self.set_finished)
self.auto_signals.timewait.connect(self.set_timewait)
self.threadx[2].signal.motorstart.connect(self.startmotor)
self.threadx[2].signal.checkflow.connect(self.checkflow)
self.dotimewait(1)
self.threadpool.start(self.threadx[2])
#self.threadx[2].signals.datasignal.connect(self.updateData)
def stop_auto(self):
self.threadx[2].kill()
self.ui.stop_auto_BTN.setEnabled(False)
self.ui.pause_auto_BTN.setEnabled(False)
self.ui.resume_auto_BTN.setEnabled(False)
self.ui.start_auto_BTN.setEnabled(True)
def pause_auto(self):
self.threadx[2].pause()
self.ui.pause_auto_BTN.setEnabled(False)
self.ui.resume_auto_BTN.setEnabled(True)
def resume_auto(self):
self.threadx[2].resume()
self.ui.pause_auto_BTN.setEnabled(True)
self.ui.resume_auto_BTN.setEnabled(False)
def set_volume(self,xx):
self.threadx[2].setvolume(xx)
def set_startflow(self,xx):
self.threadx[2].setstartflow(xx)
def set_endflow(self,xx):
#print(f" got {xx}")
self.threadx[2].setendflow(xx)
def set_finished(self,xx):
self.threadx[2].finished(xx)
def set_timewait(self,xx):
self.threadx[2].settimewait(xx)
class AutoAff_Signals(QtCore.QObject):
rheoleft = QtCore.pyqtSignal(float)
startflow = QtCore.pyqtSignal(float)
endflow = QtCore.pyqtSignal(float)
finished = QtCore.pyqtSignal(int)
timewait = QtCore.pyqtSignal(int)
class AutoEff_Signals(QtCore.QObject):
rheoStart = QtCore.pyqtSignal(int)
systeminit = QtCore.pyqtSignal(int)
rheoventil = QtCore.pyqtSignal(int)
motorstart = QtCore.pyqtSignal(int)
checkflow = QtCore.pyqtSignal(int)
#checkcounter = QtCore.pyqtSignal(int)
class AutoP(QtCore.QRunnable):
def __init__(self):
super().__init__()
self.is_paused = False
self.is_killed = False
self.signal = AutoEff_Signals()
self.status = 'start'
def run(self):
self.waittime = 5
while True :
#print(f" now waiting {self.status}")
time.sleep(0.1)
if self.status == 'flow':
time.sleep(1)
if self.status == 'idle':
time.sleep(1)
if self.status == 'start':
print(f" status {self.status}")
self.signal.checkflow.emit(False)
self.signal.motorstart.emit(1)
time.sleep(self.waittime)
self.status = 'load'
if self.status == 'load':
print(f" status {self.status}")
self.signal.rheoStart.emit(1)
self.status = 'idle'
if self.status == 'inject':
print(f" status {self.status}")
time.sleep(5)
self.signal.checkflow.emit(True)
self.signal.rheoventil.emit(False)
time.sleep(5)
#self.signal.rheoventil.emit(True)
self.status = 'idle'
while self.is_paused:
self.signal.motorstart.emit(0)
time.sleep(0)
if self.is_killed:
self.signal.motorstart.emit(0)
raise WorkerKilledException
def setvolume(self,xx):
print(f"----- volume {xx}")
self.status = 'inject'
def settimewait(self,xx):
print(f"----- wait for {xx}")
self.waittime = xx
def setstartflow(self,xx):
print(f" start flow {xx}")
self.status = 'flow'
def setendflow(self,xx):
#print(f" status {self.status}")
if self.status == 'flow':
print(f" end flow {xx}")
self.status = 'start'
def finished(self,xx):
self.signal.motorstart.emit(0)
self.is_killed=True
def pause(self):
self.is_paused=True
def resume(self):
self.signal.motorstart.emit(1)
self.is_paused = False
def kill(self):
self.is_killed = True
class WorkerKilledException(Exception): class WorkerKilledException(Exception):
pass pass
@ -342,8 +572,11 @@ class ThC(QtCore.QRunnable):
try: try:
if inp[0] == 62 and inp[-3] == 60 : if inp[0] == 62 and inp[-3] == 60 :
inp = inp[1:-3] inp = inp[1:-3]
y = float(inp.decode('utf-8')) try:
self.signals.datasignal.emit(cnt,y) y = float(inp.decode('utf-8'))
self.signals.datasignal.emit(cnt,y)
except ValueError:
pass
except IndexError: except IndexError:
pass pass
time.sleep(0.001) time.sleep(0.001)

5
poseidon/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

View File

@ -80,7 +80,7 @@ class Thread(QtCore.QRunnable):
self.signals.finished.emit() # Done self.signals.finished.emit() # Done
self.stop() self.stop()
print("Job completed") #print("Job completed")
def stop(self): def stop(self):
self.runs = False self.runs = False
@ -579,7 +579,7 @@ class MainWindow(QtWidgets.QMainWindow, gui2.Ui_MainWindow):
print("Sending JOG command..") print("Sending JOG command..")
thread = Thread(self.runTest, testData) thread = Thread(self.runTest, testData)
thread.fsignal.inished.connect(lambda:self.thread_finished(thread)) thread.signals.finished.connect(lambda:self.thread_finished(thread))
self.threadpool.start(thread) self.threadpool.start(thread)
print("JOG command sent.") print("JOG command sent.")
@ -590,7 +590,7 @@ class MainWindow(QtWidgets.QMainWindow, gui2.Ui_MainWindow):
print("Sending JOG command..") print("Sending JOG command..")
thread = Thread(self.runTest, testData) thread = Thread(self.runTest, testData)
thread.fsignal.inished.connect(lambda:self.thread_finished(thread)) thread.signals.finished.connect(lambda:self.thread_finished(thread))
self.threadpool.start(thread) self.threadpool.start(thread)
print("JOG command sent.") print("JOG command sent.")
else: else: