Forráskód Böngészése

加压调压过程修正, 外观检查项与电磁阀按钮缺陷修复

guoqiang 2 éve%!(EXTRA string=óta)
szülő
commit
f6170e79eb
8 módosított fájl, 263 hozzáadás és 74 törlés
  1. 14 34
      PageTest.qml
  2. 181 35
      TestService.cpp
  3. 2 0
      TestService.h
  4. 28 0
      UserTristate.qml
  5. 5 3
      ValveTest.pro.user
  6. 1 1
      main.cpp
  7. 31 1
      pid.cpp
  8. 1 0
      pid.h

+ 14 - 34
PageTest.qml

@@ -81,12 +81,6 @@ Item{
                         onCheckedChanged: {
                             //console.log("switch 1 onCheckedChanged")
                             switch1.text = switch1.checked ? "粗调阀1开":"粗调阀1关"
-
-
-                        }
-                        onClicked: {
-                            //console.log("switch 1 clicked")
-
                             if(switch1.checked){
                                 testService.valve_open(TestService.Valve_ID_ROUGH_0)
                             }else{
@@ -94,6 +88,7 @@ Item{
                             }
 
                         }
+
                     }
 
                     UserSwitch{
@@ -101,111 +96,96 @@ Item{
                         text: "粗调阀2关"
                         onCheckedChanged: {
                             switch2.text = switch2.checked ? "粗调阀2开":"粗调阀2关"
-
-                        }
-                        onClicked: {
                             if(switch2.checked){
                                 testService.valve_open(TestService.Valve_ID_ROUGH_1)
                             }else{
                                 testService.valve_close(TestService.Valve_ID_ROUGH_1)
                             }
                         }
+
                     }
                     UserSwitch{
                         id:switch3
                         text: "粗调阀3关"
                         onCheckedChanged: {
                             switch3.text = switch3.checked ? "粗调阀3开":"粗调阀3关"
-
-                        }
-
-                        onClicked: {
                             if(switch3.checked){
                                 testService.valve_open(TestService.Valve_ID_ROUGH_2)
                             }else{
                                 testService.valve_close(TestService.Valve_ID_ROUGH_2)
                             }
                         }
+
+
                     }
                     UserSwitch{
                         id:switch4
                         text: "校准阀 关"
                         onCheckedChanged: {
                             switch4.text = switch4.checked ? "校准阀 开":"校准阀 关"
-
-                        }
-
-                        onClicked: {
                             if(switch4.checked){
                                 testService.valve_open(TestService.Valve_ID_CALIBRATION)
                             }else{
                                 testService.valve_close(TestService.Valve_ID_CALIBRATION)
                             }
                         }
+
+
                     }
                     UserSwitch{
                         id:switch5
                         text: "传感阀 关"
                         onCheckedChanged: {
                             switch5.text = switch5.checked ? "传感阀 开":"传感阀 关"
-
-                        }
-
-                        onClicked: {
                             if(switch5.checked){
                                 testService.valve_open(TestService.Valve_ID_PRESSURESENSOR)
                             }else{
                                 testService.valve_close(TestService.Valve_ID_PRESSURESENSOR)
                             }
                         }
+
+
                     }
                     UserSwitch{
                         id:switch6
                         text: "真空阀 关"
                         onCheckedChanged: {
                             switch6.text = switch6.checked ? "真空阀 开":"真空阀 关"
-
-                        }
-
-                        onClicked: {
                             if(switch6.checked){
                                 testService.valve_open(TestService.Valve_ID_VACUUM)
                             }else{
                                 testService.valve_close(TestService.Valve_ID_VACUUM)
                             }
                         }
+
+
                     }
                     UserSwitch{
                         id:switch7
                         text: "泄气阀 关"
                         onCheckedChanged: {
                             switch7.text = switch7.checked ? "泄气阀 开":"泄气阀 关"
-
-                        }
-
-                        onClicked: {
                             if(switch7.checked){
                                 testService.valve_open(TestService.Valve_ID_VENT)
                             }else{
                                 testService.valve_close(TestService.Valve_ID_VENT)
                             }
                         }
+
+
                     }
                     UserSwitch{
                         id:switch8
                         text: "进气阀 关"
                         onCheckedChanged: {
                             switch8.text = switch8.checked ? "进气阀 开":"进气阀 关"
-
-                        }
-
-                        onClicked: {
                             if(switch8.checked){
                                 testService.valve_open(TestService.Valve_ID_INTAKE)
                             }else{
                                 testService.valve_close(TestService.Valve_ID_INTAKE)
                             }
                         }
+
                     }
 
                     UserSwitch{
@@ -280,7 +260,7 @@ Item{
                             onClicked: {
                                 //var str_number = voltage.text
                                 var num = Number(voltage.text)
-                                if((num>0) && (num<1000)){
+                                if((num>=0) && (num<=1000)){
                                     testService.adjust_Pressure(voltage.text)
                                 }else{
                                     console.log("input voltage invalid")

+ 181 - 35
TestService.cpp

@@ -1052,12 +1052,17 @@ void TestService::OnTimer2()
 Ret_Value  TestService::Pressure_RoughAdjust(const TestExpect& expect)
 {
     Ret_Value ret_v = Ret_OK;
-    int count = 0;
+    int keep_count = 0;
 
     bool bOpen1 = false;
     bool bOpen2 = false;
     bool bOpen3 = false;
 
+    //bool inTake_Open = false;
+    int exceed_times = 0;
+    int exceed_count = 0;
+    int delay_count = 0;
+
    QElapsedTimer  timer;
    timer.start();
    float current_pressure;
@@ -1067,9 +1072,13 @@ Ret_Value  TestService::Pressure_RoughAdjust(const TestExpect& expect)
 
         current_pressure = calculate_averagepressure();
 
-        if(current_pressure >=  expect.target+0.1){
+        if(current_pressure >=  expect.target+0.02){
 
-            count++;
+            if(0 == exceed_count){
+                exceed_times++;
+            }
+
+            exceed_count++;
 
             if(bOpen1){
                 if(Valve_op(Valve_ID_ROUGH_0, Valve_OP_Close))
@@ -1086,32 +1095,74 @@ Ret_Value  TestService::Pressure_RoughAdjust(const TestExpect& expect)
                     bOpen3 = false;
             }
 
-            //break;
-        }else if(current_pressure < expect.target) {
+            if(exceed_count >= 30){
+                keep_count = 50;
+            }
 
-            count =0;
+            if(exceed_times == 1){
+                delay_count = 15;
+            }else if(exceed_times == 2){
+                delay_count = 10;
+            }else {
+                delay_count = 5;
+            }
 
-            if(!bOpen1){
-                bOpen1 = Valve_op(Valve_ID_ROUGH_0, Valve_OP_Open);
+            //break;
+        }else if(current_pressure >=  expect.target && current_pressure <  expect.target+0.02){
+            //从超出, 回落到该区间
+            if(exceed_count > 0){
+                keep_count++;
             }
 
-            if(!bOpen2){
-                bOpen2 = Valve_op(Valve_ID_ROUGH_1, Valve_OP_Open);
+            //exceed_count = 0;
+
+        }else if(current_pressure < expect.target) {
+
+            exceed_count =0;
+            if(delay_count > 0){
+                delay_count--;
             }
 
-            if(!bOpen3){
-                bOpen3 = Valve_op(Valve_ID_ROUGH_2, Valve_OP_Open);
+            if(0 == delay_count){
+
+                if(0 == exceed_times){
+                    if(!bOpen1){
+                        bOpen1 = Valve_op(Valve_ID_ROUGH_0, Valve_OP_Open);
+                    }
+
+                    if(!bOpen2){
+                        bOpen2 = Valve_op(Valve_ID_ROUGH_1, Valve_OP_Open);
+                    }
+
+                    if(!bOpen3){
+                        bOpen3 = Valve_op(Valve_ID_ROUGH_2, Valve_OP_Open);
+                    }
+
+                }else if(1 == exceed_times){
+                    if(!bOpen1){
+                        bOpen1 = Valve_op(Valve_ID_ROUGH_0, Valve_OP_Open);
+                    }
+
+                    if(!bOpen2){
+                        bOpen2 = Valve_op(Valve_ID_ROUGH_1, Valve_OP_Open);
+                    }
+
+
+                }else{
+                    if(!bOpen1){
+                        bOpen1 = Valve_op(Valve_ID_ROUGH_0, Valve_OP_Open);
+                    }
+                }
+
             }
 
-        }else{
-            count++;
         }
 
-        if(count >= 240){ //about 60s
+        if(keep_count >= 30){ //about 60s
             break;
         }
 
-        QThread::msleep(500);
+        QThread::msleep(1000);
 
         int remainingtime = expect.timeout*1000 - timer.elapsed();
         if(remainingtime <= 0){
@@ -1153,36 +1204,85 @@ Ret_Value  TestService::Pressure_Adjust(const TestExpect& expect)
 {
     PID pid = PID(1, 20, -10, 5.1, 28.0, 1.0);
 
-    float current_pressure;
+    double current_pressure;
+    //double last_pressure;
     Ret_Value ret_v = Ret_OK;
     int voltage_offset = 0;
     int keep_times = 0;
     QElapsedTimer  timer;
+    bool inTake_Open = false;
+    int exceed_times = 0;
+    int exceed_count = 0;
+    int delay_count = 0;
+
 
-    Valve_op(Valve_ID_INTAKE, Valve_OP_Open);
+    inTake_Open = Valve_op(Valve_ID_INTAKE, Valve_OP_Open);
     timer.start();
 
     while(m_bRunning){
 
         current_pressure = calculate_averagepressure();
 
-        double inc = pid.calculate(expect.target, current_pressure);
+        if(current_pressure > expect.target + 0.05){
+            if(exceed_count == 0){
+                exceed_times++;
+            }
 
-        voltage_offset = (inc);
+            exceed_count++;
+            if(inTake_Open == true){
+                if(Valve_op(Valve_ID_INTAKE, Valve_OP_Close)){
+                    inTake_Open = false;
+                }
+            }
 
-        if(!Adjust_pressure(expect.start_voltage+voltage_offset)){
-            QThread::msleep(200);
-            if(!Adjust_pressure(expect.start_voltage+voltage_offset)){
-                qDebug("communication error, ajust_pressure failed");
-                ret_v = Ret_Failed;
-                break;
+            if(exceed_count > 15){
+                keep_times = 20;
             }
-        }
 
-        if(abs(current_pressure - (expect.target+0.05)) < 0.05){
-            keep_times++;
+            if(exceed_times == 1){
+                delay_count = 15;
+            }else if(exceed_times == 2){
+                delay_count = 10;
+            }else{
+                delay_count = 5;
+            }
+
+
+
+        }else if(current_pressure >= expect.target && current_pressure <= expect.target+0.05){
+            if(exceed_count > 0){
+                keep_times = 20;
+            }
+            exceed_count= 0;
+
         }else{
-            keep_times=0;
+
+            exceed_count= 0;
+            if(delay_count > 0){
+                delay_count--;
+            }
+
+            if(0 == delay_count){
+
+                if(false ==  inTake_Open){
+                   inTake_Open = Valve_op(Valve_ID_INTAKE, Valve_OP_Open);
+                }
+
+                double inc = pid.calculate(expect.target, current_pressure);
+
+                voltage_offset = (inc);
+
+                if(!Adjust_pressure(expect.start_voltage+voltage_offset)){
+                    QThread::msleep(200);
+                    if(!Adjust_pressure(expect.start_voltage+voltage_offset)){
+                        qDebug("communication error, ajust_pressure failed");
+                        ret_v = Ret_Failed;
+                        break;
+                    }
+                }
+            }
+
+
         }
 
         if(keep_times >= 15){
@@ -1191,8 +1291,6 @@ Ret_Value  TestService::Pressure_Adjust(const TestExpect& expect)
 
         QThread::msleep(1000);
 
-
-
         int remainingtime = expect.timeout*1000 - timer.elapsed();
         if(remainingtime < 0){
             ret_v = Ret_Timeout;
@@ -1202,6 +1300,7 @@ Ret_Value  TestService::Pressure_Adjust(const TestExpect& expect)
     }
 
      Valve_op(Valve_ID_INTAKE, Valve_OP_Close);
+     Adjust_pressure(0);
 
     if(!m_bRunning){
         // be stoped
@@ -1400,6 +1499,51 @@ Ret_Value  TestService::Pressure_Relief(const TestExpect& expect)
     return ret_v;
 }
 
+Ret_Value  TestService::Pressure_Relief()
+{
+    Ret_Value ret_v = Ret_OK;
+    bool bVent_Open = false;
+
+    Valve_op(Valve_ID_PRESSURESENSOR, Valve_OP_Open);
+
+     //等待压力清零
+    float current_pressure;
+    int keep_count = 0;
+
+    while(m_bRunning){
+
+        //打开泄压阀
+        if(bVent_Open == false){
+            bVent_Open = Valve_op(Valve_ID_VENT, Valve_OP_Open);
+        }
+
+        QThread::msleep(1000);
+
+        current_pressure = calculate_averagepressure();
+        if(abs(current_pressure) < 0.5){
+            keep_count++;
+            if(keep_count > 10){
+                break;
+            }
+        }else{
+            keep_count = 0;
+        }
+    }
+
+    //关闭泄压阀
+    if(bVent_Open == true){
+        Valve_op(Valve_ID_VENT, Valve_OP_Close);
+    }
+
+    if(!m_bRunning){
+        ret_v = Ret_Exit;
+    }
+
+    return ret_v;
+}
+
+
+
 Ret_Value  TestService::Pressure_Keep(int keeptime, float threshold, float& delta)
 {
     int count = 0;
@@ -1537,7 +1681,7 @@ void TestService::run()
                              Valve_op(Valve_ID_PRESSURESENSOR, Valve_OP_Open);
 
                              // 如果容积大于 1000L , 才进入粗调步骤
-                             if(m_tank.get_compartment(m_compartmentid).m_volume >= 1000){
+                             if(m_tank.get_compartment(m_compartmentid).m_volume >= 500){
                                  m_step = Test_Step_AddPressure;
                              }else{
                                  m_step = Test_Step_AdjustPressure;
@@ -1988,7 +2132,7 @@ void TestService::run()
 
                              // 检测 5分钟都没超限,就是通过了
                              float delta = 0;
-                             float threshold = 0.2;
+                             float threshold = 0.6;
                              bool bPassed = true;
 
                              ret_v = Pressure_Keep(5*60, threshold, delta);
@@ -2050,7 +2194,8 @@ void TestService::run()
     case QMessageBox::Yes:
         qDebug()<<"Yes";
         // 打开泄压阀
-        Valve_op(Valve_ID_VENT, Valve_OP_Open);
+        //Valve_op(Valve_ID_VENT, Valve_OP_Open);
+        Pressure_Relief();
         break;
     default:
         break;
@@ -2069,6 +2214,7 @@ void TestService::run()
 
     // 复位
     Adjust_pressure(0);
+    Valve_op(Valve_ID_All, Valve_OP_Close);
 
     //m_pTimer_1->stop();
 

+ 2 - 0
TestService.h

@@ -163,6 +163,8 @@ private:
     // -2  error
     Ret_Value  Pressure_Relief(const TestExpect& expect);
 
+    Ret_Value  Pressure_Relief();
+
 
     //0 pass
     //-1 nopass

+ 28 - 0
UserTristate.qml

@@ -42,6 +42,8 @@ Item {
     ButtonGroup{
         id:group
         buttons: row.children
+
+        /*
         onClicked:{
             //console.log("tristate clicked:", button.text)
             var old_state = state
@@ -59,6 +61,8 @@ Item {
                 root.usateChanged()
             }
         }
+
+        */
     }
 
     Row{
@@ -68,6 +72,14 @@ Item {
             checked: true
             text: text_state1
             font.pixelSize: fontsize
+            onCheckedChanged: {
+
+                if("0" !== root.state){
+                    //console.log("rb1 onCheckedChanged, rootstate:" , root.state)
+                    root.state = "0"
+                    root.usateChanged()
+                }
+            }
 
         }
 
@@ -76,6 +88,14 @@ Item {
             checked: false
             text: text_state2
             font.pixelSize: fontsize
+            onCheckedChanged: {
+
+                if("1" !== root.state){
+                    //console.log("rb2 onCheckedChanged, rootstate:" , root.state)
+                    root.state = "1"
+                    root.usateChanged()
+                }
+            }
         }
 
         UserRadioButton{
@@ -83,6 +103,14 @@ Item {
             checked: false
             text: text_state3
             font.pixelSize: fontsize
+            onCheckedChanged: {
+
+                if("2" !== root.state){
+                    //console.log("rb2 onCheckedChanged, rootstate:" , root.state)
+                    root.state = "2"
+                    root.usateChanged()
+                }
+            }
         }
     }
 }

+ 5 - 3
ValveTest.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 8.0.0, 2023-07-26T10:27:44. -->
+<!-- Written by QtCreator 8.0.0, 2023-07-31T11:38:42. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>
@@ -238,13 +238,15 @@
     <valuelist type="QVariantList" key="CustomOutputParsers"/>
     <value type="int" key="PE.EnvironmentAspect.Base">2</value>
     <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
-    <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:D:/Code/QTapps/ValveTest/ValveTest.pro</value>
-    <value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">D:/Code/QTapps/ValveTest/ValveTest.pro</value>
+    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">ValveTest2</value>
+    <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:D:/Code/QTapps/VRS/ValveTest.pro</value>
+    <value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">D:/Code/QTapps/VRS/ValveTest.pro</value>
     <value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
     <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
     <value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
     <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
     <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
+    <value type="QString" key="RunConfiguration.WorkingDirectory.default">D:/Code/QTapps/build-ValveTest-Desktop_Qt_5_15_2_MinGW_32_bit-Release</value>
    </valuemap>
    <value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
   </valuemap>

+ 1 - 1
main.cpp

@@ -26,7 +26,7 @@ int main(int argc, char *argv[])
 #endif
     QApplication app(argc, argv);
 
-    //qInstallMessageHandler(myMsgOutput);
+    qInstallMessageHandler(myMsgOutput);
     DLog_Init();
 
     //QMessageBox::critical(NULL, "critical", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);

+ 31 - 1
pid.cpp

@@ -14,6 +14,7 @@ class PIDImpl
         PIDImpl( double dt, double max, double min, double Kp, double Kd, double Ki );
         ~PIDImpl();
         double calculate( double setpoint, double pv );
+        void clear();
 
     private:
         double _dt;
@@ -24,6 +25,7 @@ class PIDImpl
         double _Ki;
         double _pre_error;
         double _integral;
+        double _pre_out;
 };
 
 PID::PID( double dt, double max, double min, double Kp, double Kd, double Ki )
@@ -34,6 +36,12 @@ double PID::calculate( double setpoint, double pv )
 {
     return pimpl->calculate(setpoint,pv);
 }
+
+void PID::clear()
+{
+    pimpl->clear();
+}
+
 PID::~PID()
 {
     delete pimpl;
@@ -51,7 +59,8 @@ PIDImpl::PIDImpl( double dt, double max, double min, double Kp, double Kd, doubl
     _Kd(Kd),
     _Ki(Ki),
     _pre_error(0),
-    _integral(0)
+    _integral(0),
+    _pre_out(0)
 {
 }
 
@@ -99,12 +108,33 @@ double PIDImpl::calculate( double setpoint, double pv )
     else if( output < _min )
         output = _min;
 
+    if(output < _pre_out){
+        if((_pre_out - output) > 1.0){
+            output = _pre_out - 1.0;
+        }
+
+    }else if(output > _pre_out){
+        if((output - _pre_out) > 1.0){
+            output = _pre_out + 1.0;
+        }
+    }
+
+    _pre_out = output;
+
     // Save error to previous error
     _pre_error = error;
 
     return output;
 }
 
+void PIDImpl::clear()
+{
+    _pre_error = 0;
+    _integral = 0;
+    _pre_out = 0;
+
+}
+
 PIDImpl::~PIDImpl()
 {
 }

+ 1 - 0
pid.h

@@ -16,6 +16,7 @@ class PID
 
         // Returns the manipulated variable given a setpoint and current process value
         double calculate( double setpoint, double pv );
+        void   clear();
         ~PID();
 
     private: