PMGasVerificationRoutine.cs 14 KB

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