PMLeakCheckRoutine.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Device.Unit;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.Routine;
  6. using Aitex.Core.RT.SCCore;
  7. using MECF.Framework.Common.DBCore;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TMs;
  10. using FurnaceRT.Equipments.PMs;
  11. using FurnaceRT.Equipments.PMs.Routines;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Diagnostics;
  15. namespace FurnaceRT.Modules.PMs
  16. {
  17. public class PMLeakCheckRoutine : PMBaseRoutine
  18. {
  19. enum RoutineStep
  20. {
  21. CheckSlitValve,
  22. SetValve,
  23. SetTV,
  24. SetGasLine1,
  25. SetGasLine2,
  26. SetGasLine3,
  27. SetGasLine4,
  28. SetTuning,
  29. Pump,
  30. ContinuePump,
  31. ClosePumpValve,
  32. DoLeakCheck,
  33. CalcLeakCheck,
  34. Vent,
  35. UnsetTuning,
  36. StopVent,
  37. }
  38. enum LeakCheckType
  39. {
  40. ChamberOnly,
  41. ChamberAndGasline,
  42. ChamberAndGaslineToFacility,
  43. }
  44. private int _paramContinuePumpTime;
  45. private int _paramLeakCheckTime;
  46. private string _leakCheckType;
  47. private bool[] _isMfcChecked;
  48. private string _gaslineSelection;
  49. private double[] _mfcScale = new double[4];
  50. private double _beginPressure;
  51. private int _tvPostion;
  52. private double _basePressure;
  53. private int _timeoutPump;
  54. private bool _enableTuning;
  55. private float _tuningPercent;
  56. private float _ventAtmPressure;
  57. //private TM _tm;
  58. private Stopwatch _swTimer = new Stopwatch();
  59. private List<string> _mfc = new List<string>() { "Mfc1", "Mfc2", "Mfc3", "Mfc4" };
  60. public int ElapsedTime
  61. {
  62. get { return _swTimer.IsRunning ? (int)(_swTimer.ElapsedMilliseconds / 1000) : 0; }
  63. }
  64. public PMLeakCheckRoutine(ModuleName module, PMModule pm) : base(module, pm)
  65. {
  66. Module = module.ToString();
  67. Name = "Leak Check";
  68. }
  69. internal void Init(int pumpTime, int leakCheckTime, string leakCheckType, bool[] isMfcChecked)
  70. {
  71. _paramContinuePumpTime = pumpTime;
  72. _paramLeakCheckTime = leakCheckTime;
  73. _leakCheckType = leakCheckType;
  74. _isMfcChecked = isMfcChecked;
  75. if (_leakCheckType != LeakCheckType.ChamberOnly.ToString())
  76. {
  77. _gaslineSelection = string.Empty;
  78. for (int i = 0; i < _isMfcChecked.Length; i++)
  79. {
  80. if (_isMfcChecked[i])
  81. {
  82. _mfcScale[i] = DEVICE.GetDevice<IoMfc3>($"{Module}.{_mfc[i]}").Scale;
  83. _gaslineSelection += _mfc[i] + ",";
  84. }
  85. }
  86. _gaslineSelection = _gaslineSelection.Remove(_gaslineSelection.Length - 1);
  87. }
  88. }
  89. public override Result Start(params object[] objs)
  90. {
  91. Reset();
  92. _swTimer.Restart();
  93. _tvPostion = SC.GetValue<int>($"PM.{Module}.LeakCheck.TVPosition");
  94. _basePressure = SC.GetValue<double>($"PM.{Module}.LeakCheck.PumpBasePressure");
  95. _timeoutPump = SC.GetValue<int>($"PM.{Module}.LeakCheck.PumpTimeout");
  96. _enableTuning = SC.GetValue<bool>($"PM.{Module}.LeakCheck.EnableTuning");
  97. _tuningPercent = (float) SC.GetValue<double>($"PM.{Module}.LeakCheck.TuningPercent");
  98. _ventAtmPressure = (float)SC.GetValue<double>($"PM.{Module}.VentRoutine.VentBasePressure");
  99. return Result.RUN;
  100. }
  101. public override Result Monitor()
  102. {
  103. try
  104. {
  105. CheckSlitValve((int)RoutineStep.CheckSlitValve, PMModule);
  106. SetValve((int)RoutineStep.SetValve, PMModule);
  107. SetTV((int)RoutineStep.SetTV, PMModule, _tvPostion);
  108. if (_leakCheckType == LeakCheckType.ChamberAndGasline.ToString())
  109. {
  110. for (int i = 0; i < _isMfcChecked.Length; i++)
  111. {
  112. if (_isMfcChecked[i])
  113. {
  114. SetGasLine((int)Enum.Parse(typeof(RoutineStep), $"SetGasLine{i + 1}"), PMModule, _mfc[i], 0);
  115. }
  116. }
  117. }
  118. else if (_leakCheckType == LeakCheckType.ChamberAndGaslineToFacility.ToString())
  119. {
  120. for (int i = 0; i < _isMfcChecked.Length; i++)
  121. {
  122. if (_isMfcChecked[i])
  123. {
  124. SetGasLine((int)Enum.Parse(typeof(RoutineStep), $"SetGasLine{i + 1}"), PMModule, _mfc[i], _mfcScale[i]);
  125. }
  126. }
  127. }
  128. if (_enableTuning)
  129. {
  130. SetTuning((int)RoutineStep.SetTuning, PMModule, _tuningPercent);
  131. }
  132. Pump((int)RoutineStep.Pump, PMModule, _timeoutPump, _basePressure);
  133. ContinuePump((int)RoutineStep.ContinuePump, _paramContinuePumpTime);
  134. ClosePumpValve((int)RoutineStep.ClosePumpValve, PMModule);
  135. DoLeakCheck((int)RoutineStep.DoLeakCheck, _paramLeakCheckTime);
  136. CalcLeakCheck((int)RoutineStep.CalcLeakCheck, _paramLeakCheckTime);
  137. FastVent((int)RoutineStep.Vent, PMModule, _ventAtmPressure, _timeoutPump);
  138. if (_enableTuning)
  139. {
  140. UnsetTuning((int)RoutineStep.UnsetTuning, PMModule);
  141. }
  142. StopVent((int)RoutineStep.StopVent, PMModule, _timeoutPump);
  143. }
  144. catch (RoutineBreakException)
  145. {
  146. return Result.RUN;
  147. }
  148. catch (RoutineFaildException)
  149. {
  150. return Result.FAIL;
  151. }
  152. _swTimer.Stop();
  153. return Result.DONE;
  154. }
  155. public override void Abort()
  156. {
  157. Stop($"{Module} leak check aborted");
  158. _swTimer.Stop();
  159. //LeakCheckDataRecorder.Add((int)_swTimer.ElapsedMilliseconds / 1000, _beginPressure, _tm.ChamberPressure, 0, Result.FAIL.ToString(), _leakCheckType, Module, _gaslineSelection);
  160. }
  161. private void SetTuning(int id, PMModule pm, float percent)
  162. {
  163. Tuple<bool, Result> ret = Execute(id, () =>
  164. {
  165. Notify($"Start leak check pumping");
  166. //pm.ChamberProcessPressureGauge.SetTuning(_tuningPercent);
  167. return true;
  168. });
  169. if (ret.Item1)
  170. {
  171. if (ret.Item2 == Result.FAIL)
  172. {
  173. throw (new RoutineFaildException());
  174. }
  175. else
  176. throw (new RoutineBreakException());
  177. }
  178. }
  179. private void UnsetTuning(int id, PMModule pm )
  180. {
  181. Tuple<bool, Result> ret = Execute(id, () =>
  182. {
  183. Notify($"Stop leak check venting");
  184. //pm.ChamberProcessPressureGauge.UnsetTuning();
  185. return true;
  186. });
  187. if (ret.Item1)
  188. {
  189. if (ret.Item2 == Result.FAIL)
  190. {
  191. throw (new RoutineFaildException());
  192. }
  193. else
  194. throw (new RoutineBreakException());
  195. }
  196. }
  197. private void StopVent(int id, PMModule pm, int timeout)
  198. {
  199. Tuple<bool, Result> ret = Execute(id, () =>
  200. {
  201. Notify($"Turn off {pm.Name} vent valve");
  202. //if (!pm.Gas4Valve.TurnValve(false, out string reason))
  203. //{
  204. // Stop(reason);
  205. // return false;
  206. //}
  207. return true;
  208. });
  209. if (ret.Item1)
  210. {
  211. if (ret.Item2 == Result.FAIL)
  212. {
  213. throw (new RoutineFaildException());
  214. }
  215. else
  216. throw (new RoutineBreakException());
  217. }
  218. }
  219. private void FastVent(int id, PMModule pm, float ventPressure, int timeout)
  220. {
  221. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  222. {
  223. Notify($"Turn {pm.Name} vent valve on, vent to {ventPressure} Torr");
  224. //if (!pm.Gas4Valve.TurnValve(true, out string reason))
  225. //{
  226. // Stop(reason);
  227. // return false;
  228. //}
  229. return true;
  230. }, () =>
  231. {
  232. return pm.ChamberPressure >= ventPressure;
  233. }, timeout * 1000);
  234. if (ret.Item1)
  235. {
  236. if (ret.Item2 == Result.FAIL)
  237. {
  238. throw (new RoutineFaildException());
  239. }
  240. else if (ret.Item2 == Result.TIMEOUT) //timeout
  241. {
  242. Stop($"{pm.Name} vent timeout, over {timeout} seconds");
  243. throw (new RoutineFaildException());
  244. }
  245. else
  246. throw (new RoutineBreakException());
  247. }
  248. }
  249. public void CheckSlitValve(int id, PMModule pm)
  250. {
  251. Tuple<bool, Result> ret = Check(id, () =>
  252. {
  253. Notify($"Check {Module} slit valve is closed");
  254. if (!pm.CheckSlitValveClose())
  255. {
  256. Stop($"{Module} slit valve is not closed.");
  257. return false;
  258. }
  259. return true;
  260. });
  261. if (ret.Item1)
  262. {
  263. if (ret.Item2 == Result.FAIL)
  264. {
  265. throw (new RoutineFaildException());
  266. }
  267. }
  268. }
  269. public void SetValve(int id, PMModule pm)
  270. {
  271. Tuple<bool, Result> ret = Execute(id, () =>
  272. {
  273. Notify($"Run {pm.Name} close valve all");
  274. string reason = "";
  275. foreach (var stick in PMModule.GasSticks)
  276. {
  277. if (!stick.SetFlow(out reason, 0, 0))
  278. {
  279. Stop(reason);
  280. return false;
  281. }
  282. }
  283. return true;
  284. });
  285. if (ret.Item1)
  286. {
  287. if (ret.Item2 == Result.FAIL)
  288. {
  289. throw (new RoutineFaildException());
  290. }
  291. else
  292. throw (new RoutineBreakException());
  293. }
  294. }
  295. public void SetTV(int id, PMModule pm, float position)
  296. {
  297. Tuple<bool, Result> ret = Check(id, () =>
  298. {
  299. Notify($"Run {Module} set TV position");
  300. //if (!pm.ThrottleValve.SetMode(PressureCtrlMode.TVPositionCtrl, out string reason))
  301. //{
  302. // Stop(reason);
  303. // return false;
  304. //}
  305. //if (!pm.ThrottleValve.SetPosition(position, out reason))
  306. //{
  307. // Stop(reason);
  308. // return false;
  309. //}
  310. return true;
  311. });
  312. if (ret.Item1)
  313. {
  314. if (ret.Item2 == Result.FAIL)
  315. {
  316. throw (new RoutineFaildException());
  317. }
  318. }
  319. }
  320. private void SetGasLine(int id, PMModuleBase pm, string mfcId, double flow)
  321. {
  322. Tuple<bool, Result> ret = Execute(id, () =>
  323. {
  324. Notify($"Set gas {mfcId} flow to {flow} sccm");
  325. //if (!pm.SetGasLine(mfcId, (float)flow, out string reason))
  326. //{
  327. // Stop(reason);
  328. // return false;
  329. //}
  330. return true;
  331. });
  332. if (ret.Item1)
  333. {
  334. if (ret.Item2 == Result.FAIL)
  335. {
  336. Stop($"Set gas {mfcId} flow to {flow} sccm failed.");
  337. throw (new RoutineFaildException());
  338. }
  339. else
  340. throw (new RoutineBreakException());
  341. }
  342. }
  343. public void Pump(int id, PMModule pm, int timeout, double pressure)
  344. {
  345. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  346. {
  347. Notify($"{pm.Name} pump to {pressure} Torr");
  348. //if (!pm.PumpValve.TurnValve(true, out string reason))
  349. //{
  350. // Stop(reason);
  351. // return false;
  352. //}
  353. return true;
  354. }, () =>
  355. {
  356. return pm.ChamberPressure < pressure;
  357. }, timeout * 1000);
  358. if (ret.Item1)
  359. {
  360. if (ret.Item2 == Result.FAIL)
  361. {
  362. throw (new RoutineFaildException());
  363. }
  364. else if (ret.Item2 == Result.TIMEOUT) //timeout
  365. {
  366. Stop($"{pm.Name} pump timeout, over {timeout} seconds");
  367. throw (new RoutineFaildException());
  368. }
  369. else
  370. throw (new RoutineBreakException());
  371. }
  372. }
  373. public void ContinuePump(int id, int delayTime)
  374. {
  375. Tuple<bool, Result> ret = Delay(id, () =>
  376. {
  377. Notify($"continue pump {delayTime} seconds");
  378. return true;
  379. }, delayTime * 1000);
  380. if (ret.Item1)
  381. {
  382. if (ret.Item2 == Result.FAIL)
  383. {
  384. throw (new RoutineFaildException());
  385. }
  386. throw new RoutineBreakException();
  387. }
  388. }
  389. public void ClosePumpValve(int id, PMModule pm)
  390. {
  391. string timeoutReason = string.Empty;
  392. Tuple<bool, Result> ret = Execute(id, () =>
  393. {
  394. Notify($"Run {pm.Name} close valve all");
  395. //if (!pm.PumpValve.TurnValve(false, out string reason))
  396. //{
  397. // Stop(reason);
  398. // return false;
  399. //}
  400. return true;
  401. });
  402. if (ret.Item1)
  403. {
  404. if (ret.Item2 == Result.FAIL)
  405. {
  406. throw (new RoutineFaildException());
  407. }
  408. else
  409. throw (new RoutineBreakException());
  410. }
  411. }
  412. public void DoLeakCheck(int id, double time)
  413. {
  414. Tuple<bool, Result> ret = Delay(id, () =>
  415. {
  416. Notify($"Keep pressure for {time} seconds");
  417. _beginPressure = PMModule.ChamberPressure * 1000; // 单位使用mTorr
  418. return true;
  419. }, time * 1000);
  420. if (ret.Item1)
  421. {
  422. if (ret.Item2 == Result.RUN)
  423. {
  424. throw (new RoutineBreakException());
  425. }
  426. }
  427. }
  428. public void CalcLeakCheck(int id, int time)
  429. {
  430. Tuple<bool, Result> ret = Execute(id, () =>
  431. {
  432. double endPressure = PMModule.ChamberPressure * 1000; // 单位使用mTorr
  433. double leakRate = (endPressure - _beginPressure) / (time / 60.0);
  434. LeakCheckDataRecorder.Add(time, _beginPressure, endPressure, leakRate, Result.Succeed.ToString(), _leakCheckType, Module, _gaslineSelection);
  435. EV.PostInfoLog(Module,
  436. $"{Module} leak check result: end at {DateTime.Now.ToString("HH:mm:ss")}, start: {_beginPressure:F2} mTorr, end: {endPressure:F2} mTorr, using {time} seconds, leak rate: {leakRate:F2}");
  437. return true;
  438. });
  439. }
  440. }
  441. }