压力监视等待初版

This commit is contained in:
2026-09-14 17:08:21 +08:00
parent 96c5fab758
commit 0bc587e989
5 changed files with 95 additions and 14 deletions
+41
View File
@@ -0,0 +1,41 @@
#include "PressureMonitor.h"
#include <cmath>
PressureMonitor::PressureMonitor()
: m_stableTickCount(0)
{
}
bool PressureMonitor::tick(float realtimePressure, float calibratedPressure)
{
if (calibratedPressure <= 0.0f) {
m_stableTickCount = 0;
return false;
}
float upperBound = calibratedPressure + 10.0f;
float lowerBound = calibratedPressure - 10.0f;
if (realtimePressure >= lowerBound && realtimePressure <= upperBound) {
m_stableTickCount++;
} else {
m_stableTickCount = 0;
}
return m_stableTickCount >= REQUIRED_STABLE_TICKS;
}
void PressureMonitor::reset()
{
m_stableTickCount = 0;
}
bool PressureMonitor::isCurrentlyInRange() const
{
return m_stableTickCount > 0;
}
int PressureMonitor::stableTickCount() const
{
return m_stableTickCount;
}
+29
View File
@@ -0,0 +1,29 @@
#ifndef PRESSUREMONITOR_H
#define PRESSUREMONITOR_H
class PressureMonitor
{
public:
PressureMonitor();
// 每个100ms tick 调用一次
// realtimePressure: 实时压力 (sysPara->status.PRESSURE)
// calibratedPressure: 标定压力 (sysPara->para.pressure)
// 返回 true 表示压力已持续稳定 3 秒
bool tick(float realtimePressure, float calibratedPressure);
// 重置监测器状态
void reset();
// 当前压力是否在 ±10% 范围内
bool isCurrentlyInRange() const;
// 当前连续稳定的 tick 计数
int stableTickCount() const;
private:
int m_stableTickCount;
static const int REQUIRED_STABLE_TICKS = 30; // 3秒 / 100ms = 30 ticks
};
#endif // PRESSUREMONITOR_H
+3 -1
View File
@@ -96,6 +96,7 @@ HEADERS += Public.h \
# ParaSettingUI.h \
DevOp.h \
posix_qextserialport.h \
PressureMonitor.h \
rfid/sm4.h \
rfid/sm3.h \
rfid/rfidfunction.h \
@@ -254,6 +255,7 @@ SOURCES +=\
# ParaSettingUI.cpp \
DevOp.cpp \
posix_qextserialport.cpp \
PressureMonitor.cpp \
rfid/sm4.cpp \
rfid/sm3.cpp \
rfid/rfidfunction.cpp \
@@ -395,4 +397,4 @@ if(contains(DEFINES,__2451WIFI__))
#SOURCES += /home/student/newDisk/2451_linux/wpa_supplicant_hostapd/wpa_supplicant_hostapd-0.8/src/common/wpa_ctrl.c
#INCLUDEPATH += /home/student/newDisk/2451_linux/wpa_supplicant_hostapd/wpa_supplicant_hostapd-0.8/src
#INCLUDEPATH += /home/student/newDisk/2451_linux/wpa_supplicant_hostapd/wpa_supplicant_hostapd-0.8/src/utils
}
}
+19 -13
View File
@@ -129,6 +129,8 @@ void MainWidget::init()
airPushTimer = new QTimer(this);
connect(airPushTimer, SIGNAL(timeout()), this, SLOT(airPushingProcess()));
m_pressureMonitor = new PressureMonitor();
timerPowerOff = new QTimer(this);
connect(timerPowerOff,SIGNAL(timeout()),this,SLOT(sendPowerOffCmd()));
@@ -1221,18 +1223,6 @@ void MainWidget::airPushingProcess()
sysPara->saveParaToFile();
}
// 延迟 半秒后才开回收槽,正式结束排气阶段
if(sysPara->status.airPushingOnTime >= sysPara->para.airPushDurationSec * 1000 + 500){
//qDebug()<< "start stop";
reclaimTanOpen();
sysPara->status.airPushingDone = 1;
sysPara->status.airPushing = 0;
sysPara->status.airPushingOnTime = 0;
airPushTimer->stop();
setRunStatus(tr("喷嘴开启中"));
return;
}
if(sysPara->status.airPushingOnTime >= sysPara->para.airPushDurationSec * 1000){
sysPara->devOp->controlViscosityPump(false);
sysPara->devOp->controlCycleValve(false);
@@ -1240,6 +1230,21 @@ void MainWidget::airPushingProcess()
if(!sysPara->devOp->isReclaimPumpOpen())
sysPara->devOp->controlReclaimPump(true, false);
// 切换回自动模式
sysPara->status.isPumpValveControledByHand = false;
setRunStatus(tr("等待压力稳定..."));
// 调用压力检测器,监测压力持续3秒波动范围不超过标定值的+-10%
if(m_pressureMonitor->tick((float)sysPara->status.PRESSURE, (float)sysPara->para.pressure)) {
reclaimTanOpen();
sysPara->status.airPushingDone = 1;
sysPara->status.airPushing = 0;
sysPara->status.airPushingOnTime = 0;
airPushTimer->stop();
m_pressureMonitor->reset();
setRunStatus(tr("喷嘴开启中"));
}
return;
}
}
@@ -1431,6 +1436,7 @@ void MainWidget::on_m_RightBtn_clicked()
sysPara->status.airPushingOnTime = 0;
airPushTimer->start(100); // 100ms
m_pressureMonitor->reset();
}
}
else {
@@ -2698,4 +2704,4 @@ void MainWidget::UpdateUIVersion(){
QString Mac = QString::number(sysPara->status.machineMac);
LogInfo::setRunStatusText(QString("Mac:%1").arg(Mac));
LogInfo::showVerionInformation(Mac,VernonBach,fpgaVersion,STM32Ver);
}
}
+3
View File
@@ -30,6 +30,7 @@
#include "setnumdlg.h"
#include "PrintSetting.h"
#include "PressureMonitor.h"
class MainWidget : public QWidget
{
@@ -165,6 +166,8 @@ private:
int r_ExpiryDay;
QTimer *airPushTimer;
PressureMonitor *m_pressureMonitor = nullptr;
PicScene *pPicScene = nullptr;
QGraphicsView *view;
PrintSettingModel printSettingsModel;