Sic03/Modules/SicPM/Routines/PMLeakCheckRoutine.cs

569 lines
23 KiB
C#
Raw Normal View History

2022-07-26 09:41:07 +08:00
using Aitex.Core.RT.Device;
using Aitex.Core.RT.Device.Unit;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.Routine;
using Aitex.Core.RT.SCCore;
using MECF.Framework.Common.DBCore;
using MECF.Framework.Common.Equipment;
using SicPM.Devices;
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace SicPM.Routines
{
public class PMLeakCheckRoutine : PMBaseRoutine
{
private enum RoutineStep
{
RotationEnable,
HeatEnable,
VentPumpClose,
ArSupply,
SetGroupA,
SetGroupB,
SetGroupC,
SetGroupE,
SetGroupF,
SetGroupH,
SetGroupD,
SetGroupG,
SetGroupK,
SetMFCMode,
SetPCMode,
SetM1to16,
SetPC,
SetGroupJ,
SetM291519to38,
SetGasOut,
SetTv,
SetGasIn1, //V68
OpenFinal1, //V91-96
SetMfcFinal1, //M32-38
SetMfc19to26,
SetTVCloseMode,
SetTvPositionToZero,
SetGasIn2,
SetGroupJOpen,
SetM291519to26,
OpenFinal2,
SetMfcFinal2,
SetEPV1,
SetEPV2,
SetTvMode,
SetTvOpen,
SetTvModeToPress,
SetTVtoCurrent,
RoutinePre,
SetPressureUp,
SetPressureDown,
WaitPressureDown,
WaitPressureUp,
VentPumpOpen,
PressureToMax,
PressureToMin,
StartLoop,
EndLoop,
SetMfc28to31,
SetReactorPress,
CloseFinanl1,
CloseFinanl2,
CloseEPV2,
SetTVCloseMode2,
CLoseTvvvv,
SetEPVVV2,
CLoseEPV1,
CheckPM1000,
WaitPressUpTo1000,
WaitPressUpTo1020,
SetPressUpOrDown1,
SetPressUpOrDown2,
SetMfc28to40Special,
WaitPmPressureUp,
SetMfc28to40Default,
SetV75,
SetV76,
SetV751,
SetV761,
SetPC567Close,
SetPC567Mode,
SetPC567Default,
OpenEPV2,
WaitPressUpTo20,
SetMfc291519to38,
WaitPressUpTo0,
SetMfc291519to38ToDefault,
WaitPressDownTo20,
SetPmPressureTo20,
CloseMfcFinal1,
CloseMfcFinal2,
CloseMfc2915,
CheckFinal1Open,
DoLeakCheck,
CalcLeakCheck,
SetTVClose,
CloseTV,
CloseV27,
CloseV28,
CloseV69,
CloseV70,
SetGroupV25,
2022-07-30 08:50:44 +08:00
SetV92V93V95,
SetV94,
SetV96,
SetV68,
SetM32M35M37,
SetM36,
SetM38,
CloseM32M35M37,
CloseM36,
CloseM38,
CloseGasIn1,
2022-07-26 09:41:07 +08:00
TimeDelay1,
TimeDelay2,
TimeDelay3,
TimeDelay4,
TimeDelay5,
TimeDelay6,
TimeDelay7,
TimeDelay8,
TimeDelay9,
TimeDelay10,
TimeDelay11,
TimeDelay12,
TimeDelay13,
2022-07-30 08:50:44 +08:00
TimeDelay14,
TimeDelay20,
TimeDelay21,
TimeDelay22,
2022-07-26 09:41:07 +08:00
}
enum LeakCheckType
{
ChamberOnly,
ChamberAndGasline,
ChamberAndGaslineToFacility,
}
private ModuleName moduleName;
private IoThrottleValve2 _IoThrottle;
private IoInterLock _pmIoInterLock;
List<int> _lstPcList = new List<int> { 1, 2, 3, 4, 5, 6, 7 };
private int _rotationCheckSpeed = 0; //设置旋转速度为0后检查是否转速低于此数值
private int _rotationCloseTimeout; //旋转停止超时
private int _heatTimeOut = 5; //Heat关闭等待Di反馈超时时间
private double _pressureMax; //Loop压力上限可设置600-800
private double _pressureMin; //Loop压力下限可设置 0-400
private int _pressureLoopCount; //Loop次数
private int _pressureMinDelay;
private int _pressureMaxDelay;
private int _pressureMinTimeout;
private int _pressureMaxTimeout;
private int _IoValueOpenCloseTimeout = 10; //开关阀门超时时间
private double _pmPressureMaxDiff; //蝶阀与目标压力的差值范围(认为调整到位了)
private int _throttleTimeout; //蝶阀调整到指定压力的超时时间
private int _paramContinuePumpTime;
private int _paramLeakCheckTime ;
private double _beginPressure;
private double _beginTime;
private int _calTimes; //第几次计算LeakCheck的值每60秒计算一次
private double _leakSpec;
private int _routineTimeOut;
2022-07-30 08:50:44 +08:00
//private int _EPV2OpenDelayTime = 9;
2022-07-26 09:41:07 +08:00
private bool _useSettingValue = false;
private Stopwatch _swTimer = new Stopwatch();
public int ElapsedTime
{
get { return _swTimer.IsRunning ? (int)(_swTimer.ElapsedMilliseconds / 1000) : 0; }
}
public PMLeakCheckRoutine(ModuleName module, PMModule pm) : base(module, pm)
{
Module = module.ToString();
Name = "Leak Check";
_IoThrottle = DEVICE.GetDevice<IoThrottleValve2>($"{Module}.TV");
}
internal void Init(int pumpTime, int leakCheckTime)
{
_paramContinuePumpTime = pumpTime;
_paramLeakCheckTime = leakCheckTime;
_useSettingValue = true;
}
internal void Init()
{
_useSettingValue = false;
}
public override Result Start(params object[] objs)
{
//if (!PMDevice.CheckSlitValveClose())
//{
// EV.PostAlarmLog(Module, "PM SlitValve is not Closed!");
// return Result.FAIL;
//}
Reset();
_swTimer.Restart();
_rotationCloseTimeout = SC.GetValue<int>($"PM.{Module}.RotationCloseTimeout");
_pmPressureMaxDiff = SC.GetValue<double>($"PM.{Module}.ThrottlePressureMaxDiff");
_throttleTimeout = SC.GetValue<int>($"PM.{Module}.ThrottlePressureTimeout");
_pmIoInterLock = DEVICE.GetDevice<IoInterLock>($"{Module}.PMInterLock");
_rotationCloseTimeout = SC.GetValue<int>($"PM.{Module}.RotationCloseTimeout");
_pressureLoopCount = SC.GetValue<int>($"PM.{Module}.LeakCheck.CyclePurgeCount");
_pressureMin = SC.GetValue<double>($"PM.{Module}.LeakCheck.PumpBasePressure");
_pressureMinDelay = SC.GetValue<int>($"PM.{Module}.LeakCheck.PumpDelayTime");
_pressureMinTimeout = SC.GetValue<int>($"PM.{Module}.LeakCheck.PumpTimeout");
_pressureMax = SC.GetValue<double>($"PM.{Module}.LeakCheck.VentBasePressure");
_pressureMaxDelay = SC.GetValue<int>($"PM.{Module}.LeakCheck.VentDelayTime");
_pressureMaxTimeout = SC.GetValue<int>($"PM.{Module}.LeakCheck.VentTimeout");
_routineTimeOut = SC.GetValue<int>($"PM.{Module}.LeakCheck.RoutineTimeOut");
2022-07-30 08:50:44 +08:00
//_EPV2OpenDelayTime = SC.GetValue<int>($"PM.{Module}.TimeDelayAlterEPV2Open");
2022-07-26 09:41:07 +08:00
if (!_useSettingValue)
{
_paramContinuePumpTime = SC.GetValue<int>($"PM.{Module}.LeakCheck.ContinuePumpTime");
_paramLeakCheckTime = SC.GetValue<int>($"PM.{Module}.LeakCheck.LeakCheckDelayTime");
}
_leakSpec = SC.GetValue<double>($"PM.{Module}.LeakCheck.LeakSpec");
if (!PMDevice.SetIOValueByGroup(IoGroupName.V70, false))
{
EV.PostAlarmLog(Module,"Can not close V70-1");
return Result.FAIL;
}
Notify($"Start LoopCount:{_pressureLoopCount}");
return Result.RUN;
}
public override Result Monitor()
{
try
{
if (SC.GetValue<bool>("System.IsATMMode"))
{
return Result.DONE;
}
CheckRoutineTimeOut();
SetRotationValve((int)RoutineStep.RotationEnable, _rotationCheckSpeed, false, _rotationCloseTimeout);
SetHeatEnable((int)RoutineStep.HeatEnable, false, _heatTimeOut);
SetIoValueByGroup((int)RoutineStep.VentPumpClose, IoGroupName.VentPump, false, _IoValueOpenCloseTimeout);
SetIoValueByGroup((int)RoutineStep.ArSupply, IoGroupName.ArSupply, true, _IoValueOpenCloseTimeout);
SetIoValueByGroup((int)RoutineStep.SetGroupB, IoGroupName.B, false, _IoValueOpenCloseTimeout);
SetIoValueByGroup((int)RoutineStep.SetGroupC, IoGroupName.C, false, _IoValueOpenCloseTimeout);
SetIoValueByGroup((int)RoutineStep.SetGroupE, IoGroupName.E, false, _IoValueOpenCloseTimeout);
SetIoValueByGroup((int)RoutineStep.SetGroupF, IoGroupName.F, false, _IoValueOpenCloseTimeout);
SetIoValueByGroup((int)RoutineStep.SetGroupH, IoGroupName.H, false, _IoValueOpenCloseTimeout);
SetIoValueByGroup((int)RoutineStep.SetGroupK, IoGroupName.K, false, _IoValueOpenCloseTimeout);
SetIoValueByGroup((int)RoutineStep.SetGroupV25, IoGroupName.V25, true, _IoValueOpenCloseTimeout);
SetIoValueByGroup((int)RoutineStep.SetGroupD, IoGroupName.D, true, _IoValueOpenCloseTimeout);
SetIoValueByGroup((int)RoutineStep.SetGroupG, IoGroupName.G, true, _IoValueOpenCloseTimeout);
SetIoValueByGroup((int)RoutineStep.SetV76, IoGroupName.V76, false, _IoValueOpenCloseTimeout);
SetIoValueByGroup((int)RoutineStep.SetV75, IoGroupName.V75, true, _IoValueOpenCloseTimeout);
SetMfcModeToNormalByGroup((int)RoutineStep.SetMFCMode, MfcGroupName.All);
SetPcModeToNormal((int)RoutineStep.SetPCMode, _lstPcList);
SetMfcToDefaultByGroup((int)RoutineStep.SetM1to16, MfcGroupName.M1to16, 0);
SetPcToDefault((int)RoutineStep.SetPC, _lstPcList);
CheckFinalIoStatue((int)RoutineStep.CheckFinal1Open);
if (!_finalOpen)
{
SetMfcByGroup((int)RoutineStep.SetM291519to38, MfcGroupName.M2toM40, 0, 5);
TimeDelay((int)RoutineStep.TimeDelay1, 5);
}
2022-07-30 08:50:44 +08:00
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//打开Final valves 和对应的MFC值
2022-07-26 09:41:07 +08:00
SetIoValueByGroup((int)RoutineStep.OpenFinal2, IoGroupName.Final2, true, _IoValueOpenCloseTimeout);
SetMfcToDefaultByGroup((int)RoutineStep.SetMfcFinal2, MfcGroupName.Final2, 3);
TimeDelay((int)RoutineStep.TimeDelay3, 3);
2022-07-30 08:50:44 +08:00
//SetIoValueByGroup((int)RoutineStep.OpenFinal1, IoGroupName.Final1, true, _IoValueOpenCloseTimeout);
//SetMfcToDefaultByGroup((int)RoutineStep.SetMfcFinal1, MfcGroupName.Final1, 3);
//修改打开Final1的MFC和阀的开关流程
//1.打开V92,V93和V95,再打开V94,在打开V96,在打开V68
SetIoValueByGroup((int)RoutineStep.SetV92V93V95, IoGroupName.V92V93V95, true, _IoValueOpenCloseTimeout);
TimeDelay((int)RoutineStep.TimeDelay20, 3);
SetIoValueByGroup((int)RoutineStep.SetV94, IoGroupName.V94, true, _IoValueOpenCloseTimeout);
TimeDelay((int)RoutineStep.TimeDelay21, 3);
SetIoValueByGroup((int)RoutineStep.SetV96, IoGroupName.V96, true, _IoValueOpenCloseTimeout);
TimeDelay((int)RoutineStep.TimeDelay22, 3);
SetIoValueByGroup((int)RoutineStep.SetV68, IoGroupName.GasIn1, true, _IoValueOpenCloseTimeout);
//2.设置M32,M35,M37到默认值,再设置M36,延时2s,再设置M38,不用Ramp
SetMfcToDefaultByGroup((int)RoutineStep.SetM32M35M37, MfcGroupName.M32M35M37, 5);
SetMfcToDefaultByGroup((int)RoutineStep.SetM36, MfcGroupName.M36, 5);
TimeDelay((int)RoutineStep.TimeDelay10, 2);
SetMfcToDefaultByGroup((int)RoutineStep.SetM38, MfcGroupName.M38, 5);
2022-07-26 09:41:07 +08:00
TimeDelay((int)RoutineStep.TimeDelay4, 3);
2022-07-30 08:50:44 +08:00
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2022-07-26 09:41:07 +08:00
//4.打开J Valves
SetIoValueByGroup((int)RoutineStep.SetGroupJOpen, IoGroupName.J, true, _IoValueOpenCloseTimeout);
SetMfcToDefaultByGroup((int)RoutineStep.SetM291519to26, MfcGroupName.M2toM26, 3);
//打开EPV2,等待9秒,打开蝶阀
SetIoValueByGroup((int)RoutineStep.OpenEPV2, IoGroupName.EPV2, true, _IoValueOpenCloseTimeout);
2022-07-30 08:50:44 +08:00
TimeDelay((int)RoutineStep.TimeDelay5, 2);
2022-07-26 09:41:07 +08:00
SetThrottleEnableAndWait((int)RoutineStep.SetTvOpen, _IoThrottle, 10);
SetThrottleToPressModeAndWait((int)RoutineStep.SetTvModeToPress, _IoThrottle, 10);
//Loop
Loop((int)RoutineStep.StartLoop, _pressureLoopCount);
2022-08-02 08:34:41 +08:00
//SetPressureUpOrDown((int)RoutineStep.SetPressUpOrDown2, PressureUpOrDown.Uping);
//SetThrottleToTargetAndNoWait((int)RoutineStep.SetPressureUp, _IoThrottle, _pressureMax);
//WaitThrottleToPressureAndSetMfcSpecialForLidOpen((int)RoutineStep.WaitPressureUp, _IoThrottle, _pressureMax, _pmPressureMaxDiff, _pressureMaxTimeout);
//TimeDelay((int)RoutineStep.TimeDelay8, _pressureMaxDelay);
//SetPressureUpOrDown((int)RoutineStep.SetPressUpOrDown1, PressureUpOrDown.Dowing);
//SetThrottleToTargetAndNoWait((int)RoutineStep.SetPressureDown, _IoThrottle, _pressureMin);
//WaitThrottleToPressureAndSetMfcSpecialForLidOpen((int)RoutineStep.WaitPressureDown, _IoThrottle, _pressureMin, _pmPressureMaxDiff, _pressureMinTimeout);
//TimeDelay((int)RoutineStep.TimeDelay7, _pressureMinDelay);
SetThrottlePressureAndWait((int)RoutineStep.SetPressureUp, _IoThrottle, _pressureMax, _pmPressureMaxDiff, _throttleTimeout);
2022-07-26 09:41:07 +08:00
TimeDelay((int)RoutineStep.TimeDelay8, _pressureMaxDelay);
2022-08-02 08:34:41 +08:00
SetThrottlePressureAndWait((int)RoutineStep.SetPressureDown, _IoThrottle, _pressureMin, _pmPressureMaxDiff, _throttleTimeout);
2022-07-26 09:41:07 +08:00
TimeDelay((int)RoutineStep.TimeDelay7, _pressureMinDelay);
2022-08-02 08:34:41 +08:00
2022-07-26 09:41:07 +08:00
EndLoop((int)RoutineStep.EndLoop);
//2.依次关闭I Value
SetMfcByGroup((int)RoutineStep.CloseMfcFinal1, MfcGroupName.M32toM38, 0, 5);
TimeDelay((int)RoutineStep.TimeDelay10, 5);
2022-07-30 08:50:44 +08:00
//SetIoValueByGroup((int)RoutineStep.CloseFinanl1, IoGroupName.Final1, false, _IoValueOpenCloseTimeout);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//修改关闭Finanl1的流程
//1.关闭V68,延时5s
SetIoValueByGroup((int)RoutineStep.CloseGasIn1, IoGroupName.GasIn1, false, _IoValueOpenCloseTimeout);
Delay((int)RoutineStep.TimeDelay12, 5);
//2.关闭M32,M35,M36,M37,M38
SetMfcByGroup((int)RoutineStep.CloseM32M35M37, MfcGroupName.M32M35M37, 0, 5);
SetMfcByGroup((int)RoutineStep.CloseM36, MfcGroupName.M36, 0, 5);
SetMfcByGroup((int)RoutineStep.CloseM38, MfcGroupName.M38, 0, 5);
Delay((int)RoutineStep.TimeDelay14, 5);
//3.关闭Final1阀
2022-07-26 09:41:07 +08:00
SetIoValueByGroup((int)RoutineStep.CloseFinanl1, IoGroupName.Final1, false, _IoValueOpenCloseTimeout);
2022-07-30 08:50:44 +08:00
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2022-07-26 09:41:07 +08:00
SetMfcByGroup((int)RoutineStep.CloseMfcFinal2, MfcGroupName.M19toM33, 0, 5);
TimeDelay((int)RoutineStep.TimeDelay11, 5);
SetIoValueByGroup((int)RoutineStep.CloseFinanl2, IoGroupName.Final2, false, _IoValueOpenCloseTimeout);
SetIoValueByGroup((int)RoutineStep.CloseV27, IoGroupName.V27, false, _IoValueOpenCloseTimeout);
SetIoValueByGroup((int)RoutineStep.CloseV69, IoGroupName.V69, false, _IoValueOpenCloseTimeout);
TimeDelay((int)RoutineStep.TimeDelay9, _paramContinuePumpTime);
//关闭蝶阀,关闭EPV2
SetThrottleToCloseMode((int)RoutineStep.SetTVClose, _IoThrottle, 8);
TimeDelay((int)RoutineStep.TimeDelay12, 2);
SetThrottleDisable((int)RoutineStep.CloseTV, _IoThrottle, 8);
TimeDelay((int)RoutineStep.TimeDelay13, 2);
SetIoValueByGroup((int)RoutineStep.CloseEPV2, IoGroupName.EPV2, false, _IoValueOpenCloseTimeout);
DoLeakCheck((int)RoutineStep.DoLeakCheck, _paramLeakCheckTime);
CalcLeackCheckPerMinute(_paramLeakCheckTime);
}
catch (RoutineBreakException)
{
return Result.RUN;
}
catch (RoutineFaildException)
{
return Result.FAIL;
}
_swTimer.Stop();
return Result.DONE;
}
public override void Abort()
{
Stop($"{Module} leak check aborted");
_swTimer.Stop();
PMDevice._ioThrottleValve.StopRamp();
PMDevice.SetMfcStopRamp(PMDevice.GetMfcListByGroupName(MfcGroupName.All));
PMDevice.SetRotationServo(0, 0);
base.Abort();
}
private void CheckRoutineTimeOut()
{
if (_routineTimeOut > 10)
{
if ((int)(_swTimer.ElapsedMilliseconds / 1000) > _routineTimeOut)
{
EV.PostAlarmLog(Module, $"Routine TimeOut! over {_routineTimeOut} s");
throw (new RoutineFaildException());
}
}
}
public void DoLeakCheck(int id, double time)
{
Tuple<bool, Result> ret = Execute(id, () =>
{
Notify($"Keep pressure for {time} seconds");
_beginTime = _swTimer.ElapsedMilliseconds;
_beginPressure = PMDevice.ChamberPressure;
_calTimes = 1;
return true;
});
if (ret.Item1)
{
if (ret.Item2 == Result.FAIL)
{
throw (new RoutineFaildException());
}
else
throw (new RoutineBreakException());
}
//Tuple<bool, Result> ret = Delay(id, () =>
//{
// Notify($"Keep pressure for {time} seconds");
// _beginPressure = PMDevice.ChamberPressure; // mbar
// return true;
//}, time * 1000);
//if (ret.Item1)
//{
// if (ret.Item2 == Result.RUN)
// {
// throw (new RoutineBreakException());
// }
//}
}
public void CalcLeackCheckPerMinute(int time)
{
//大于LeakCheck时间,
if ((int)((_swTimer.ElapsedMilliseconds - _beginTime) / 1000) >= time)
{
int leakSecond = (int)((_swTimer.ElapsedMilliseconds - _beginTime) / 1000);
double endPressure = PMDevice.ChamberPressure;
double leakSpan = endPressure - _beginPressure;
double leakRate = (endPressure - _beginPressure) / (leakSecond / 60.0);
if (leakRate > _leakSpec)
{
LeakCheckDataRecorder.Add(time, (int)_beginPressure, (int)endPressure, leakRate, Result.FAIL.ToString(), "", Module);
EV.PostInfoLog(Module, $"Leak check result: end at {DateTime.Now.ToString("HH:mm:ss")}, start: {_beginPressure:F2}mbar, end: {endPressure:F2}mbar, using {time} seconds, leak rate: {leakRate:F2}");
}
else
{
LeakCheckDataRecorder.Add(time, (int)_beginPressure, (int)endPressure, leakRate, Result.Succeed.ToString(), "", Module);
EV.PostInfoLog(Module, $"Leak check result: end at {DateTime.Now.ToString("HH:mm:ss")}, start: {_beginPressure:F2}mbar, end: {endPressure:F2}mbar, using {time} seconds, leak rate: {leakRate:F2}");
}
}
else
{
if ((int)((_swTimer.ElapsedMilliseconds - _beginTime) / 1000) >= 60 * _calTimes)
{
_calTimes++;
int leakSecond = (int)((_swTimer.ElapsedMilliseconds - _beginTime) / 1000);
double endPressure = PMDevice.ChamberPressure;
double leakSpan = endPressure - _beginPressure;
double leakRate = (endPressure - _beginPressure) / (leakSecond / 60.0);
if (leakRate > _leakSpec)
{
EV.PostInfoLog(Module, $"Leak check Failed Count {_calTimes - 1}: using {leakSecond} seconds, leak rate: {leakRate:F2} ,Rate over {_leakSpec}");
throw (new RoutineFaildException());
}
EV.PostInfoLog(Module, $"Leak check Count {_calTimes - 1}: using {leakSecond} seconds, leak rate: {leakRate:F2}");
}
throw (new RoutineBreakException());
}
}
public void CalcLeakCheck(int id, int time)
{
Tuple<bool, Result> ret = Execute(id, () =>
{
double endPressure = PMDevice.ChamberPressure;
double leakSpan = endPressure - _beginPressure;
double leakRate = (endPressure - _beginPressure) / (time / 60.0);
if (leakRate > _leakSpec)
{
LeakCheckDataRecorder.Add(time, (int)_beginPressure, (int)endPressure, leakRate, Result.FAIL.ToString(), "", Module);
EV.PostInfoLog(Module,$"Leak check result: end at {DateTime.Now.ToString("HH:mm:ss")}, start: {_beginPressure:F2}mbar, end: {endPressure:F2}mbar, using {time} seconds, leak rate: {leakRate:F2}");
return false;
}
else
{
LeakCheckDataRecorder.Add(time, (int)_beginPressure, (int)endPressure, leakRate, Result.Succeed.ToString(), "", Module);
EV.PostInfoLog(Module,$"Leak check result: end at {DateTime.Now.ToString("HH:mm:ss")}, start: {_beginPressure:F2}mbar, end: {endPressure:F2}mbar, using {time} seconds, leak rate: {leakRate:F2}");
return true;
}
});
}
}
}