PMGasVerificationRoutine.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. using System.Collections.Generic;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.SCCore;
  5. using Venus_RT.Devices;
  6. using Venus_RT.Devices.IODevices;
  7. using Aitex.Core.RT.Log;
  8. using Venus_Core;
  9. using Aitex.Core.Util;
  10. using System;
  11. using MECF.Framework.Common.DBCore;
  12. using MECF.Framework.Common.Routine;
  13. using System.Collections.ObjectModel;
  14. namespace Venus_RT.Modules.PMs
  15. {
  16. class PMGasVerificationRoutine : PMRoutineBase, IRoutine
  17. {
  18. private enum GasStep
  19. {
  20. kPrepareValves,
  21. kPumpDown_1,
  22. kGasFlow,
  23. kWaitPendulumFullClose,
  24. KDelay_2S,
  25. KGetBeginPressure,
  26. kDelay_1,
  27. kGasVerification,
  28. kStopGasFlow,
  29. kPumpDown_2,
  30. kEnd,
  31. }
  32. public enum VerifyMode
  33. {
  34. OnePoint,
  35. TenPoint,
  36. }
  37. private double _basePressure;
  38. private double _beginPressure;
  39. private double _endPressure;
  40. private double _elapsedTime;
  41. private DeviceTimer _verificationDeviceTimer = new DeviceTimer();
  42. private int _mfcIndex;
  43. private float _mfcFlow;
  44. private int _flowTime;
  45. private int _pumpingTime;
  46. private int _holdTime;
  47. private double _mfcActualFlow;
  48. private double _maxPressure;
  49. private MfcBase1 _mfcDevice;
  50. private VerifyMode _paramMode;
  51. private Dictionary<int, float> _paramFlowSet = new Dictionary<int, float>();
  52. private Dictionary<float, Tuple<float, float>> _calibrationResult = new Dictionary<float, Tuple<float, float>>();
  53. private float _pressureStableTolerance = 2;//2mTorr
  54. private float _flowStableTolerance = 0.02f;//2%
  55. private double _chamberVolume;
  56. private double _gasTemperature;
  57. private double _leakRate;
  58. private double _maxDeviation;
  59. private readonly PumpDownRoutine _pumpDownRoutine;
  60. public ObservableCollection<MFCCalibrationData> _MFCCalibrationDatas = new ObservableCollection<MFCCalibrationData>();
  61. //private bool _flag;//判断3分钟是否大于9torr
  62. private JetChamber jetChamber = JetChamber.None;
  63. public PMGasVerificationRoutine(JetPMBase chamber, PumpDownRoutine pdRoutine) : base(chamber)
  64. {
  65. Name = "Gas Verification";
  66. _pumpDownRoutine = pdRoutine;
  67. jetChamber = chamber.ChamberType;
  68. }
  69. internal void Init(string mfc, double flow, int flowCount)
  70. {
  71. int.TryParse(mfc.Replace("MFC", ""), out _mfcIndex);
  72. _mfcDevice = DEVICE.GetDevice<MfcBase1>($"{Module}.MfcGas{_mfcIndex}");
  73. _mfcIndex -= 1;//start from 0
  74. _mfcFlow = (float)flow;
  75. if (flowCount == 10)
  76. _paramMode = VerifyMode.TenPoint;
  77. else
  78. _paramMode = VerifyMode.OnePoint;
  79. }
  80. public RState Start(params object[] objs)
  81. {
  82. if (!CheckLid())
  83. {
  84. return RState.Failed;
  85. }
  86. if (!CheckSlitDoor())
  87. {
  88. return RState.Failed;
  89. }
  90. if (!CheckDryPump())
  91. {
  92. return RState.Failed;
  93. }
  94. if (!CheckTurboPump())
  95. {
  96. return RState.Failed;
  97. }
  98. _calibrationResult.Clear();
  99. _paramFlowSet.Clear();
  100. _MFCCalibrationDatas.Clear();
  101. _basePressure = SC.GetValue<double>($"{Module}.MFCVerification.BasePressure");
  102. _chamberVolume = SC.GetValue<double>($"{Module}.MFCVerification.ChamberVolume");
  103. _gasTemperature = SC.GetValue<double>($"{Module}.MFCVerification.GasTemperature");
  104. _pumpingTime = SC.GetValue<int>($"{Module}.MFCVerification.PumpingTime");
  105. _flowTime = SC.GetValue<int>($"{Module}.MFCVerification.GasFlowTime");
  106. _holdTime = SC.GetValue<int>($"{Module}.MFCVerification.HoldTime");
  107. _maxDeviation = SC.GetValue<double>($"{Module}.MFCVerification.MaxDeviation");
  108. _pressureStableTolerance = (float)SC.GetValue<double>($"{Module}.MFCVerification.PressureStableTolerance");
  109. _flowStableTolerance = (float)(SC.GetValue<double>($"{Module}.MFCVerification.FlowStableTolerance") / 100.0);
  110. _maxPressure = SC.GetValue<double>($"{Module}.MFCVerification.TargetPressure");
  111. if (_paramMode == VerifyMode.TenPoint)
  112. {
  113. for (int i = 0; i < 10; i++)
  114. {
  115. _paramFlowSet.Add(i, (float)_mfcDevice.Scale * (i + 1) / 10);
  116. }
  117. }
  118. else
  119. {
  120. if (_mfcFlow <= 0 || _mfcFlow > _mfcDevice.Scale)
  121. {
  122. LOG.Write(eEvent.ERR_ROUTINE_FAILED, Module, Name, $"MFC set value {_mfcFlow} not valid");
  123. return RState.Failed;
  124. }
  125. _paramFlowSet.Add(0, _mfcFlow);
  126. }
  127. _mfcDevice.ResetVerificationData();
  128. _leakRate = 0;
  129. var dbData = DataQuery.Query($"SELECT * FROM \"leak_check_data\" where \"module_name\" = '{Module}' order by \"operate_time\" DESC;");
  130. if (dbData != null && dbData.Rows.Count > 0 && !dbData.Rows[0]["leak_rate"].Equals(DBNull.Value))
  131. {
  132. _leakRate = Convert.ToDouble(dbData.Rows[0]["leak_rate"]);
  133. }
  134. Reset();
  135. return Runner.Start(Module, Name);
  136. }
  137. public RState Monitor()
  138. {
  139. Runner.Run(GasStep.kPrepareValves, PrepareValve, _delay_50ms)
  140. .LoopStart(GasStep.kPumpDown_1, $"{_mfcDevice.Name} Gas Verification", _paramFlowSet.Count, PumpingDown, WaitPumpDone)
  141. .LoopRun(GasStep.kGasFlow, FlowGas, CheckGasStable)
  142. .Wait(GasStep.kWaitPendulumFullClose, WaitPendulumFullClose)
  143. .LoopDelay(GasStep.KDelay_2S, 2 * 1000)
  144. .LoopRun(GasStep.KGetBeginPressure, GetBeginPressure, JudgePressure, (_holdTime + 10) * 1000)
  145. //.LoopDelay(GasStep.kDelay_1, _holdTime * 1000)
  146. .LoopRun(GasStep.kGasVerification, CalcMfcCalibration, _delay_2s)
  147. .LoopEnd(GasStep.kStopGasFlow, StopGasFlow, IsPumpDownOK)
  148. .End(GasStep.kEnd, NullFun, _delay_2s);
  149. return Runner.Status;
  150. }
  151. private bool JudgePressure()
  152. {
  153. if (_verificationDeviceTimer.GetElapseTime() < 3 * 60 * 1000 && _chamber.ChamberPressure > 9000)
  154. {
  155. return true;
  156. }
  157. if (_verificationDeviceTimer.GetElapseTime() > _holdTime * 1000)
  158. {
  159. return true;
  160. }
  161. return false;
  162. }
  163. public void Abort()
  164. {
  165. _verificationDeviceTimer.Stop();
  166. _chamber.StopAllGases();
  167. _chamber.CloseValves();
  168. _mfcDevice.ResetVerificationData();
  169. }
  170. private bool PrepareValve()
  171. {
  172. _chamber.CloseValves();
  173. _chamber.OpenValve(ValveType.TurboPumpPumping, true);
  174. _chamber.OpenValve(ValveType.Guage, true);
  175. _chamber.OpenValve(ValveType.GasFinal, true);
  176. return true;
  177. }
  178. private bool PumpingDown()
  179. {
  180. _chamber.SetPVPostion(1000);
  181. return true;
  182. }
  183. private bool WaitPumpDone()
  184. {
  185. if (Runner.StepElapsedMS >= _pumpingTime * 1000)
  186. {
  187. if (_chamber.ProcessPressure <= _basePressure)
  188. {
  189. return true;
  190. }
  191. else
  192. {
  193. Runner.Stop($"MFC Gas Verification fail, Cannot pumping down to {_basePressure} mTorr in {_pumpingTime} seconds");
  194. return true;
  195. }
  196. }
  197. return false;
  198. }
  199. private void OpenPVNVlv(int mfcIndex, bool on)
  200. {
  201. ValveType[] vlvs = new ValveType[] { ValveType.PV11, ValveType.PV21, ValveType.PV31, ValveType.PV41 };
  202. if (_chamber.ChamberType == JetChamber.VenusSE || _chamber.ChamberType == JetChamber.VenusDE)
  203. {
  204. vlvs = new ValveType[] { ValveType.PV11, ValveType.PV21, ValveType.PV31, ValveType.PV41, ValveType.PV51, ValveType.PV61, ValveType.PV71, ValveType.PV81, ValveType.PV91, ValveType.PVA1, ValveType.PVB1, ValveType.PVC1, };
  205. }
  206. // if (mfcIndex < 4)
  207. //{
  208. _chamber.OpenValve(vlvs[mfcIndex], on);
  209. //}
  210. }
  211. private bool FlowGas()
  212. {
  213. Notify($"Start {_mfcDevice.Name} gas flow");
  214. _verificationDeviceTimer.Start(0);
  215. //if (jetChamber == JetChamber.Kepler2200A || jetChamber == JetChamber.Kepler2200B)
  216. //{
  217. // _beginPressure = ConvertPressureUnit.ConvertPaTomtorr(_chamber.ChamberPressure);
  218. //}
  219. //else
  220. //{
  221. // _beginPressure = _chamber.ChamberPressure;
  222. //}
  223. OpenPVNVlv(_mfcIndex, true);
  224. if (!_chamber.FlowGas(_mfcIndex, _paramMode == VerifyMode.TenPoint ? _paramFlowSet[Runner.LoopCounter] : _mfcFlow))
  225. {
  226. return false;
  227. }
  228. return true;
  229. }
  230. private bool WaitPendulumFullClose()
  231. {
  232. return _chamber.PendulumPosition <= 0;
  233. }
  234. private bool CheckGasStable()
  235. {
  236. if (_verificationDeviceTimer.GetElapseTime() > _flowTime * 1000)
  237. {
  238. if (!_chamber.TurnPendulumValve(false))
  239. {
  240. Runner.Stop("Stop Pendulum Valve failed.");
  241. }
  242. return true;
  243. }
  244. //if (Math.Abs(_chamber.ChamberPressure - _beginPressure) > _pressureStableTolerance)
  245. //{
  246. // Runner.Stop($"");
  247. // return true;
  248. //}
  249. if (_verificationDeviceTimer.GetElapseTime() > 3000)
  250. {
  251. if (Math.Abs(_mfcDevice.SetPoint - _mfcDevice.FeedBack) / _mfcDevice.SetPoint > _flowStableTolerance)
  252. {
  253. Runner.Stop($"Gas is not Stable");
  254. return true;
  255. }
  256. }
  257. return false;
  258. }
  259. private bool GetBeginPressure()
  260. {
  261. if (jetChamber == JetChamber.Kepler2200A || jetChamber == JetChamber.Kepler2200B)
  262. {
  263. _beginPressure = ConvertPressureUnit.ConvertPaTomtorr(_chamber.ChamberPressure);
  264. }
  265. else
  266. {
  267. _beginPressure = _chamber.ChamberPressure;
  268. }
  269. Notify($"Get begin pressure {_beginPressure.ToString("f1")}");
  270. _verificationDeviceTimer.Start(0);
  271. //Notify($"Check finished one point");
  272. return true;
  273. }
  274. private bool CalcMfcCalibration()
  275. {
  276. //_mfcIndex += 1;
  277. // full open Pendulum valve
  278. //.SetPVPostion(1000);
  279. if (jetChamber == JetChamber.Kepler2200A || jetChamber == JetChamber.Kepler2200B)
  280. {
  281. _endPressure = ConvertPressureUnit.ConvertPaTomtorr(_chamber.ChamberPressure);
  282. }
  283. else
  284. {
  285. _endPressure = _chamber.ChamberPressure;
  286. }
  287. _elapsedTime = _verificationDeviceTimer.GetElapseTime() / (1000 * 60); //unit minute
  288. float flow = _paramMode == VerifyMode.TenPoint ? _paramFlowSet[Runner.LoopCounter] : _mfcFlow;
  289. _mfcActualFlow = 273.15 * _chamberVolume / ((273.15 + _gasTemperature) * 760000) * ((_endPressure - _beginPressure) / _elapsedTime - _leakRate);
  290. Notify($"Calculate flow: calculate flow={_mfcActualFlow}, setpoint={flow}, begin pressure(mtorr)={_beginPressure:f3}, end pressure(mtorr)={_endPressure:f3}," +
  291. $"elapsed time(minute)={_elapsedTime:f3}");
  292. _MFCCalibrationDatas.Add(new MFCCalibrationData(flow, _mfcActualFlow));
  293. double deviation = (Math.Abs(_mfcActualFlow) - Math.Abs(flow)) / Math.Abs(flow) * 100;
  294. bool isOk = Math.Abs(deviation) <= Math.Abs(_maxDeviation);
  295. if (!isOk)
  296. {
  297. LOG.Write(eEvent.ERR_ROUTINE_FAILED, Module, Name, $"MFC{(_mfcIndex + 1).ToString()} verify failed, deviation{deviation} exceed max tolerance{_maxDeviation}");
  298. }
  299. if (_paramMode == VerifyMode.TenPoint)
  300. {
  301. _calibrationResult[flow] = Tuple.Create((float)_mfcActualFlow, (float)_elapsedTime);
  302. _mfcDevice.SetVerificationResult((float)flow, (float)_mfcActualFlow, _calibrationResult.Count == 10, _elapsedTime * 60, deviation, isOk, (int)VerifyMode.TenPoint);
  303. }
  304. else if (_paramMode == VerifyMode.OnePoint)
  305. {
  306. _mfcDevice.SetVerificationResult((float)flow, (float)_mfcActualFlow, true, _elapsedTime * 60, deviation, isOk, (int)VerifyMode.OnePoint);
  307. }
  308. return true;
  309. }
  310. private bool StopGasFlow()
  311. {
  312. Notify($"Stop gas {_mfcIndex} flow");
  313. if (!_chamber.FlowGas(_mfcIndex, 0))
  314. {
  315. return false;
  316. }
  317. OpenPVNVlv(_mfcIndex, false);
  318. _chamber.OpenValve(ValveType.TurboPumpPumping, false);
  319. _chamber.OpenValve(ValveType.FastPump, true);
  320. return _pumpDownRoutine.Start(_basePressure) == RState.Running;
  321. }
  322. private bool IsPumpDownOK()
  323. {
  324. var status = _pumpDownRoutine.Monitor();
  325. if (status == RState.End)
  326. {
  327. return true;
  328. }
  329. else if (status == RState.Failed || status == RState.Timeout)
  330. {
  331. Runner.Stop($"Pump down to {_basePressure} failed.");
  332. return true;
  333. }
  334. return false;
  335. }
  336. }
  337. }