This repository has been archived on 2023-03-29. You can view files and clone it, but cannot push or open issues or pull requests.
Sic02/Modules/Mainframe/TMs/TMPressureBalanceRoutine.cs

504 lines
16 KiB
C#
Raw Normal View History

2022-08-05 14:47:02 +08:00
using System;
using Aitex.Core.RT.Device;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.Routine;
using Aitex.Core.RT.SCCore;
using MECF.Framework.Common.Equipment;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TMs;
namespace Mainframe.TMs
{
public class TMPressureBalanceRoutine : ModuleRoutine, IRoutine
{
enum RoutineStep
{
CheckPressureCondition,
PumpDownToBase,
CloseIsoValve,
OpenTmSlowVent,
VentToSetPoint,
StopVent,
WaitPressureToSetPoint,
SlowPump, FastPump, VaccumDelay, CloseValves, CLoseSlowValue,
CheckNeedVent
}
private TM _tm;
private TMPumpRoutine _pumpDownRoutine;
private ModuleName _paramTarget; //每个模块包含以下三个参数↓
private bool _needMfcVent; //是否需要Vent操作
private double _ventMfcFlow; //MFC在Vent时设置的值
private double _balancePressure; //目标压力值
double maxDifferent = 0;
private int _ventTimeout; //MFC 超时
private int _waitPressureTimeout; //不需要Vent操作时等待压力平衡时间
private bool _needPumpDown; //执行Routine之前已经是真空则不需要抽真空
private bool _needBalance; //执行Routine之前已经在设定压力值则不需要继续平衡
private double _slowFastPumpSwitchPressure; //慢快抽切换压力
private int _fastPumpTime;
private int _slowPumpTimeout;
private bool isAtmMode = false;
public TMPressureBalanceRoutine()
{
Module = ModuleName.TM.ToString();
Name = "Pressure Balance";
_tm = DEVICE.GetDevice<SicTM>($"{ ModuleName.System.ToString()}.{ ModuleName.TM.ToString()}");
_pumpDownRoutine = new TMPumpRoutine();
_paramTarget = ModuleName.System;
}
public void Init(ModuleName target)
{
Name = "Pressure Balance with " + target;
_paramTarget = target;
}
public Result Start(params object[] objs)
{
Reset();
if (ModuleHelper.IsLoadLock(_paramTarget))
{
_balancePressure = SC.GetValue<double>("TM.PressureBalance.BalancePressureForLL");
_needMfcVent = SC.GetValue<bool>("TM.PressureBalance.NeedMfcVentLL");
_ventMfcFlow = SC.GetValue<double>("TM.PressureBalance.MfcBalanceFlowLL");
}
else if (ModuleHelper.IsPm(_paramTarget))
{
if (!SC.ContainsItem($"TM.PressureBalance.BalancePressureFor{_paramTarget}"))
{
EV.PostAlarmLog(Module, $"did not define balance pressure for {_paramTarget}");
return Result.FAIL;
}
_balancePressure = SC.GetValue<double>($"TM.PressureBalance.BalancePressureFor{_paramTarget}") + +SC.GetValue<double>("TM.TMPressureBigThanPM");
_needMfcVent = SC.GetValue<bool>($"TM.PressureBalance.NeedMfcVent{_paramTarget}");
_ventMfcFlow = SC.GetValue<double>($"TM.PressureBalance.MfcBalanceFlow{_paramTarget}");
}
else
{
EV.PostAlarmLog(Module, $"did not define balance pressure for {_paramTarget}");
return Result.FAIL;
}
_ventTimeout = SC.GetValue<int>("TM.PressureBalance.VentTimeout");
_waitPressureTimeout = SC.GetValue<int>("TM.PressureBalance.WaitPressureAboveSetPointTimeout");
_slowFastPumpSwitchPressure = SC.GetValue<double>("TM.Pump.SlowFastPumpSwitchPressure");
_fastPumpTime = SC.GetValue<int>("TM.Pump.FastPumpTimeout");
_slowPumpTimeout = SC.GetValue<int>("TM.Pump.PumpSlowTimeout");
//_needPumpDown = !_tm.CheckVacuum();
maxDifferent = SC.GetValue<double>("TM.PressureBalance.BalanceMaxDiffPressure");
isAtmMode = SC.GetValue<bool>("System.IsATMMode");
if ((Math.Abs(_tm.ChamberPressure - _balancePressure) < maxDifferent) && _balancePressure != 0)
{
return Result.DONE;
}
_needPumpDown = (_tm.ChamberPressure > _balancePressure) || _balancePressure == 0;
_needMfcVent = _balancePressure > 10;
Notify("Start");
return Result.RUN;
}
public Result Monitor()
{
try
{
if (isAtmMode)
{
return Result.DONE;
}
if (_needPumpDown)
{
if (_balancePressure < _slowFastPumpSwitchPressure)
{
OpenSlowPump((int)RoutineStep.SlowPump, _tm, _slowFastPumpSwitchPressure, _slowPumpTimeout);
OpenFastPump((int)RoutineStep.FastPump, _tm, _balancePressure, _fastPumpTime);
CloseFastPump((int)RoutineStep.CloseValves, _tm);
CloseSlowPump((int)RoutineStep.CLoseSlowValue, _tm);
}
else
{
OpenSlowPump((int)RoutineStep.SlowPump, _tm, _balancePressure, _slowPumpTimeout);
CloseSlowPump((int)RoutineStep.CLoseSlowValue, _tm);
}
//ExecuteRoutine((int)RoutineStep.PumpDownToBase, _pumpDownRoutine);
}
CheckNeedVent((int)RoutineStep.CheckNeedVent);
if (_needMfcVent)
{
VentToSetPoint((int)RoutineStep.VentToSetPoint, _tm, _balancePressure, _ventMfcFlow, _ventTimeout);
StopVent((int)RoutineStep.StopVent, _tm, 2);
}
//else
//{
// WaitPressureToSetPoint((int)RoutineStep.WaitPressureToSetPoint, _tm, _balancePressure, _waitPressureTimeout);
//}
}
catch (RoutineBreakException)
{
return Result.RUN;
}
catch (RoutineFaildException)
{
return Result.FAIL;
}
Notify("Finished");
return Result.DONE;
}
public void Abort()
{
_tm.SetSlowVentValve(false, out string reason);
_tm.SetFastVentValve(false, out reason);
_tm.SetSlowPumpValve(false, out reason);
_tm.SetFastPumpValve(false, out reason);
Notify("Aborted");
}
private void CheckNeedVent(int id)
{
Tuple<bool, Result> ret = Execute(id, () =>
{
if ((Math.Abs(_tm.ChamberPressure - _balancePressure) < maxDifferent) && _balancePressure != 0)
{
_needMfcVent = false;
}
else if(_tm.ChamberPressure < _balancePressure)
{
_needMfcVent = true;
}
return true;
});
if (ret.Item1)
{
if (ret.Item2 == Result.FAIL)
{
throw (new RoutineFaildException());
}
else
throw (new RoutineBreakException());
}
}
public void OpenTMSlowVent(int id,int delayTime)
{
Tuple<bool, Result> ret = Wait(id, () =>
{
Notify($"Open tm slowVent");
if (!_tm.SetSlowVentValve(true, out string reason))
{
Stop(reason);
return false;
}
return true;
}, delayTime * 1000);
if (ret.Item1)
{
if (ret.Item2 == Result.FAIL)
{
throw (new RoutineFaildException());
}
else
throw (new RoutineBreakException());
}
}
public void VentToSetPoint(int id, TM tm, double balancePressure, double ventFlow, int timeout)
{
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
{
Notify($"vent to {balancePressure} mbar with {ventFlow} sccm");
if (!_tm.SetSlowVentValve(true, out string reason))
{
Stop(reason);
return false;
}
if (!_tm.SetVentMfc(ventFlow, out reason))
{
Stop(reason);
return false;
}
return true;
}, () =>
{
return _tm.ChamberPressure >= balancePressure;
}, timeout * 1000);
if (ret.Item1)
{
if (ret.Item2 == Result.FAIL)
{
throw (new RoutineFaildException());
}
else if (ret.Item2 == Result.TIMEOUT) //timeout
{
Stop($"can not vent to {balancePressure} in {timeout} seconds");
throw (new RoutineFaildException());
}
else
throw (new RoutineBreakException());
}
}
public void StopVent(int id, TM tm, int delayTime)
{
Tuple<bool, Result> ret = Wait(id, () =>
{
Notify($"stop vent");
if (!_tm.SetSlowVentValve(false, out string reason))
{
Stop(reason);
return false;
}
if (!_tm.SetVentMfc(0, out reason))
{
Stop(reason);
return false;
}
return true;
}, delayTime * 1000);
if (ret.Item1)
{
if (ret.Item2 == Result.FAIL)
{
throw (new RoutineFaildException());
}
else
throw (new RoutineBreakException());
}
}
public void WaitPressureToSetPoint(int id, TM tm, double pressure, int timeout)
{
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
{
Notify($"Wait pressure above {pressure} mbar");
return true;
}, () =>
{
return tm.ChamberPressure >= pressure;
}, timeout * 1000);
if (ret.Item1)
{
if (ret.Item2 == Result.TIMEOUT) //timeout
{
Stop($"{tm.Name} pressure can not above {pressure} in {timeout} seconds");
throw (new RoutineFaildException());
}
else
throw (new RoutineBreakException());
}
}
//public void CloseIsoValve(int id, TM tm, int timeout)
//{
// Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
// {
// Notify($"Close {tm.Name} isolate valves");
// if (!tm.SetTurboPumpIsoValve(false, out string reason))
// {
// Stop(reason);
// return false;
// }
// return true;
// }, () =>
// {
// return tm.CheckIsoValveClose();
// }, timeout*1000);
// if (ret.Item1)
// {
// if (ret.Item2 == Result.FAIL)
// {
// throw (new RoutineFaildException());
// }
// if (ret.Item2 == Result.TIMEOUT)
// {
// Notify($"can not close isolate valve in {timeout} seconds");
// throw (new RoutineFaildException());
// }
// else
// throw (new RoutineBreakException());
// }
//}
public void OpenSlowPump(int id, TM tm, double basePressure, int timeout)
{
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
{
Notify($"Open {tm.Name} slow pump valve");
if (!tm.SetSlowPumpValve(true, out string reason))
{
Stop(reason);
return false;
}
return true;
}, () =>
{
return tm.ChamberPressure <= basePressure;
}, timeout * 1000);
if (ret.Item1)
{
if (ret.Item2 == Result.FAIL)
{
throw (new RoutineFaildException());
}
else if (ret.Item2 == Result.TIMEOUT) //timeout
{
tm.SetFastPumpValve(false, out string _);
Stop($"{tm.Name} pressure can not pump to {basePressure} in {timeout} seconds");
throw (new RoutineFaildException());
}
else
throw (new RoutineBreakException());
}
}
public void CloseSlowPump(int id, TM tm)
{
Tuple<bool, Result> ret = Execute(id, () =>
{
Notify($"Close {tm.Name} pump valves");
if (!_tm.SetSlowPumpValve(false, out string reason))
{
Stop(reason);
return false;
}
return true;
});
if (ret.Item1)
{
if (ret.Item2 == Result.FAIL)
{
throw (new RoutineFaildException());
}
else
throw (new RoutineBreakException());
}
}
public void OpenFastPump(int id, TM tm, double basePressure, int timeout)
{
Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
{
Notify($"Open {tm.Name} pump valve");
if (!tm.SetFastPumpValve(true, out string reason))
{
Stop(reason);
return false;
}
return true;
}, () =>
{
return tm.ChamberPressure <= basePressure;
}, timeout * 1000);
if (ret.Item1)
{
if (ret.Item2 == Result.FAIL)
{
throw (new RoutineFaildException());
}
else if (ret.Item2 == Result.TIMEOUT) //timeout
{
tm.SetFastPumpValve(false, out string _);
Stop($"{tm.Name} pressure can not pump to {basePressure} in {timeout} seconds");
throw (new RoutineFaildException());
}
else
throw (new RoutineBreakException());
}
}
public void CloseFastPump(int id, TM tm)
{
Tuple<bool, Result> ret = Execute(id, () =>
{
Notify($"Close {tm.Name} pump valves");
if (!_tm.SetFastPumpValve(false, out string reason))
{
Stop(reason);
return false;
}
return true;
});
if (ret.Item1)
{
if (ret.Item2 == Result.FAIL)
{
throw (new RoutineFaildException());
}
else
throw (new RoutineBreakException());
}
}
}
}