RinseThirdStepRoutine.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.RecipeCenter;
  4. using Aitex.Core.RT.Routine;
  5. using Aitex.Core.RT.SCCore;
  6. using MECF.Framework.Common.DataCenter;
  7. using MECF.Framework.Common.RecipeCenter;
  8. using MECF.Framework.Common.Routine;
  9. using MECF.Framework.Common.Utilities;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using CyberX8_Core;
  16. using CyberX8_RT.Devices.Resistivity;
  17. using CyberX8_RT.Devices.Rinse;
  18. namespace CyberX8_RT.Modules.Rinse
  19. {
  20. public class RinseThirdStepRoutine : RoutineBase, IRoutine
  21. {
  22. private enum RinseThirdStep
  23. {
  24. Recipe_StartThirdRinseCycle,
  25. Recipe_ThirdRinseStartFilling,
  26. Recipe_ThirdRinseRecordStartWaterLevel,
  27. Recipe_ThirdRinseStartFillingWait,
  28. Recipe_ThirdRinseWaitFillingDetected,
  29. Recipe_ThirdRinseWaitFull,
  30. Recipe_ThirdRinseWaitEndFillTime,
  31. Recipe_ThirdRinseWaitResistivityStart,
  32. Recipe_ThirdRinseResistivityAveraging,
  33. Recipe_ThirdRinseCheckResistivity,
  34. Recipe_StartThirdRinseClampCycle,
  35. Recipe_ThirdRinseWaitClampTime,
  36. Recipe_ThirdRinseCycleClampOff,
  37. Recipe_ThirdRinseCycleClampOn,
  38. Recipe_ThirdRinseCycleWaitSlowDrainTime,
  39. Recipe_ThirdRinseCycleEnd,
  40. Recipe_ThirdRinseWaitDrain,
  41. Recipe_ThirdRinseCheckDrain,
  42. Recipe_ThirdRinseWaitDrainExtraTime,
  43. Recipe_ThirdRinseComplete,
  44. Recipe_Complete,
  45. }
  46. #region 内部变量
  47. /// <summary>
  48. /// 设备对象
  49. /// </summary>
  50. private RinseDevice _device;
  51. /// <summary>
  52. /// Recipe
  53. /// </summary>
  54. private QdrRecipe _recipe;
  55. /// <summary>
  56. /// Fill打开注水记录Water Level
  57. /// </summary>
  58. private double _fillingDetectStartWaterLevel;
  59. /// <summary>
  60. /// Concurrent Fill Time Seconds
  61. /// </summary>
  62. private int _concurrentFillTimeSeconds;
  63. /// <summary>
  64. /// 开始注水的偏差
  65. /// </summary>
  66. private double _fillingStartedDelta;
  67. /// <summary>
  68. /// 注满数值
  69. /// </summary>
  70. private int _sensorReadingFull;
  71. /// <summary>
  72. /// 液位为空数值
  73. /// </summary>
  74. private int _sensorReadingEmpty;
  75. /// <summary>
  76. /// 开始流水时间
  77. /// </summary>
  78. private DateTime _startFillTime;
  79. /// <summary>
  80. /// Clamp开关等待时间
  81. /// </summary>
  82. private double _clampCycleTimeSeconds;
  83. /// <summary>
  84. /// 从开始排水到检测是否排空的间隔时间
  85. /// </summary>
  86. private int _normalDrainTimeSeconds;
  87. /// <summary>
  88. /// Clamp Cycle开关次数
  89. /// </summary>
  90. private int _numberClampCyclesToComplete;
  91. /// <summary>
  92. /// Resistivity取值样本列表
  93. /// </summary>
  94. private List<double> _resistivitySample = new List<double>();
  95. /// <summary>
  96. /// 开始注水后检测是否正常注水间隔
  97. /// </summary>
  98. private int _checkIsFillingTimeSeconds;
  99. /// <summary>
  100. /// 开始注水后检测是否注满间隔
  101. /// </summary>
  102. private int _checkIsFullTimeSeconds;
  103. /// 采样水阻值次数
  104. /// </summary>
  105. private int _readResistivityCount = 0;
  106. /// <summary>
  107. /// 当前执行到哪一步的显示
  108. /// </summary>
  109. private string _currentStateMachine;
  110. /// <summary>
  111. /// 开始采样时间
  112. /// </summary>
  113. private DateTime _startSampleTime = DateTime.Now;
  114. /// <summary>
  115. /// 采样时间
  116. /// </summary>
  117. private DateTime _sampeIntervalTime = DateTime.Now;
  118. /// <summary>
  119. /// 启动采样
  120. /// </summary>
  121. private bool _startSample = false;
  122. #endregion
  123. /// <summary>
  124. /// 构造函数
  125. /// </summary>
  126. /// <param name="module"></param>
  127. public RinseThirdStepRoutine(string module) : base(module)
  128. {
  129. }
  130. /// <summary>
  131. /// 启动
  132. /// </summary>
  133. /// <param name="objects"></param>
  134. /// <returns></returns>
  135. public RState Start(params object[] objects)
  136. {
  137. _startSample = false;
  138. _resistivitySample.Clear();
  139. _device = DEVICE.GetDevice<RinseDevice>(Module);
  140. _recipe = objects[0] as QdrRecipe;
  141. _concurrentFillTimeSeconds = SC.GetValue<int>("QDR.ConcurrentFillTimeSeconds");
  142. _fillingDetectStartWaterLevel = 0;
  143. _fillingStartedDelta = SC.GetValue<double>("QDR.FillingStartedDelta");
  144. _sensorReadingFull = SC.GetValue<int>("QDR.SensorReadingFull");
  145. _sensorReadingEmpty = SC.GetValue<int>("QDR.SensorReadingEmpty");
  146. _clampCycleTimeSeconds = SC.GetValue<double>("QDR.ClampCycleTimeSeconds");
  147. _numberClampCyclesToComplete = SC.GetValue<int>("QDR.NumberClampCyclesToComplete");
  148. _normalDrainTimeSeconds = SC.GetValue<int>("QDR.NominalDrainTimeSeconds");
  149. _checkIsFillingTimeSeconds = SC.GetValue<int>("QDR.NominalCheckFillWaterTimeSeconds");
  150. _checkIsFullTimeSeconds = SC.GetValue<int>("QDR.NominalCheckFillFullTimeSeconds");
  151. //配置项规范性验证
  152. if (_checkIsFillingTimeSeconds + _checkIsFullTimeSeconds > _concurrentFillTimeSeconds)
  153. {
  154. NotifyError(eEvent.ERR_RINSE, $"configuration item 'QDR.NominalCheckFillWaterTimeSeconds' plus 'QDR.NominalCheckFillFullTimeSeconds' is large than QDR.ConcurrentFillTimeSeconds", 0);
  155. return RState.Failed;
  156. }
  157. if (_normalDrainTimeSeconds > _recipe.DumpTimeSeconds)
  158. {
  159. NotifyError(eEvent.ERR_RINSE, $"configuration item 'QDR.NominalDrainTimeSeconds' is large than 'recipe.DumpTimeSeconds", 0);
  160. return RState.Failed;
  161. }
  162. return Runner.Start(Module, "Start Rinse Third Step");
  163. }
  164. /// <summary>
  165. /// 监控
  166. /// </summary>
  167. /// <returns></returns>
  168. public RState Monitor()
  169. {
  170. _currentStateMachine = Runner.CurrentStep.ToString();
  171. _device.UpdateStateMachine(_currentStateMachine);
  172. //3.6-StartThirdRinseCycle
  173. Runner.Run(RinseThirdStep.Recipe_StartThirdRinseCycle, OpenN2ValveAndCloseDumpValve, _delay_1ms)
  174. //3.7-ThirdRinseStartFilling
  175. .Run(RinseThirdStep.Recipe_ThirdRinseStartFilling, () => _device.FillValveOn(), _delay_1ms)
  176. .Run(RinseThirdStep.Recipe_ThirdRinseRecordStartWaterLevel, CheckFillValveOn, _delay_1ms)
  177. .RunDelay(RinseThirdStep.Recipe_ThirdRinseStartFillingWait, CheckFillNormalStatus, _checkIsFillingTimeSeconds * 1000)
  178. //3.8-ThirdRinseWaitFillingDetected and 3.9-ThirdRinseWaitFull
  179. .RunDelay(RinseThirdStep.Recipe_ThirdRinseWaitFillingDetected, CheckFillFullStatus, _checkIsFullTimeSeconds * 1000)
  180. //.Run(RinseThirdStep.Recipe_ThirdRinseWaitFull, CheckFillFullStatus, _delay_1s)
  181. //4.0-ThirdRinseWaitEndFillTime
  182. .Delay(RinseThirdStep.Recipe_ThirdRinseWaitEndFillTime, (_concurrentFillTimeSeconds - _checkIsFillingTimeSeconds - _checkIsFullTimeSeconds) * 1000)
  183. //4.1-ThirdRinseWaitResistivityStart
  184. .Run(RinseThirdStep.Recipe_ThirdRinseWaitResistivityStart, ResistivityStart, _recipe.ResistivityStartTimeSeconds * 1000)
  185. //4.2-ThirdRinseResistivityAveraging
  186. .Run(RinseThirdStep.Recipe_ThirdRinseResistivityAveraging, ResistivityAveraging, _delay_1ms)
  187. //4.3-ThirdRinseCheckResistivity
  188. .Wait(RinseThirdStep.Recipe_ThirdRinseCheckResistivity, ResitivitySampleResitivity, _recipe.ResistivityDurationSeconds * 1000)
  189. //4.4-ThirdRinseWaitClampTime
  190. .Delay(RinseThirdStep.Recipe_ThirdRinseWaitClampTime, (_recipe.FinalRinsePulseClampTime - _recipe.ResistivityStartTimeSeconds - _recipe.ResistivityDurationSeconds) * 1000)
  191. .LoopStart(RinseThirdStep.Recipe_StartThirdRinseClampCycle, "Clamp On/Off Cycle", _numberClampCyclesToComplete, NullFun, _delay_1ms)
  192. //4.5-ThirdRinseCycleClampOff
  193. .LoopRun(RinseThirdStep.Recipe_ThirdRinseCycleClampOff, () => _device.WaferHolderClampValveOff(), (int)(_clampCycleTimeSeconds * 1000))
  194. //4.6-ThirdRinseCycleClampOn
  195. .LoopRun(RinseThirdStep.Recipe_ThirdRinseCycleClampOn, () => _device.WaferHolderClampValveOn(), (int)(_clampCycleTimeSeconds * 1000))
  196. .LoopEnd(RinseThirdStep.Recipe_ThirdRinseCycleEnd, NullFun, _delay_1ms)
  197. //4.8-ThirdRinseCycleWaitSlowDrainTime
  198. .Delay(RinseThirdStep.Recipe_ThirdRinseCycleWaitSlowDrainTime, (int)((_recipe.FinalRinseSlowDrainTime - _recipe.FinalRinsePulseClampTime - _clampCycleTimeSeconds * 2 * _numberClampCyclesToComplete) * 1000))
  199. //4.9-ThirdRinseWaitDrain
  200. .Run(RinseThirdStep.Recipe_ThirdRinseWaitDrain, StartOpenDumpValve, _delay_1ms)
  201. .RunDelay(RinseThirdStep.Recipe_ThirdRinseCheckDrain, CheckWaterLevelEmpty, _normalDrainTimeSeconds * 1000)
  202. //5.0-ThirdRinseWaitDrainExtraTime
  203. .RunIf(RinseThirdStep.Recipe_ThirdRinseWaitDrainExtraTime, _recipe.DumpTimeSeconds - _normalDrainTimeSeconds > 0, NullFun, (_recipe.DumpTimeSeconds - _normalDrainTimeSeconds) * 1000)
  204. //5.1-Recipe_Complete
  205. .Run(RinseThirdStep.Recipe_ThirdRinseComplete, () => _device.WasteValveOff(), _delay_1ms)
  206. .End(RinseThirdStep.Recipe_Complete, NullFun, _delay_1ms);
  207. return Runner.Status;
  208. }
  209. /// <summary>
  210. /// 启动N2和关闭Dump Valve
  211. /// </summary>
  212. /// <returns></returns>
  213. private bool OpenN2ValveAndCloseDumpValve()
  214. {
  215. bool result = true;
  216. if (_recipe.Step2N2BubbleOn)
  217. {
  218. result = _device.N2ValveOn();
  219. if (!result)
  220. {
  221. NotifyError(eEvent.ERR_RINSE, "Open N2 Valve error", 0);
  222. return false;
  223. }
  224. }
  225. result = _device.DrainValveOff();
  226. if (!result)
  227. {
  228. NotifyError(eEvent.ERR_RINSE, "Close Dump Valve error", 0);
  229. }
  230. return result;
  231. }
  232. /// <summary>
  233. /// 检验Fill Valve打开状态
  234. /// </summary>
  235. /// <returns></returns>
  236. private bool CheckFillValveOn()
  237. {
  238. _startFillTime = DateTime.Now;
  239. _fillingDetectStartWaterLevel = _device.RinseData.WaterLevel;
  240. LOG.WriteLog(eEvent.INFO_RINSE, Module, $"Start Fill Valve WaterLevel {_fillingDetectStartWaterLevel}");
  241. return true;
  242. }
  243. /// <summary>
  244. /// 检验是否正常注水
  245. /// </summary>
  246. /// <returns></returns>
  247. private bool CheckFillNormalStatus()
  248. {
  249. double currentWaterLevel = _device.RinseData.WaterLevel;
  250. return (currentWaterLevel - _fillingDetectStartWaterLevel) > _fillingStartedDelta;
  251. }
  252. /// <summary>
  253. /// 检验是否注满
  254. /// </summary>
  255. /// <returns></returns>
  256. private bool CheckFillFullStatus()
  257. {
  258. double currentWaterLevel = _device.RinseData.WaterLevel;
  259. bool result = currentWaterLevel > _sensorReadingFull;
  260. return result;
  261. }
  262. /// <summary>
  263. /// 打开Dump Valve
  264. /// </summary>
  265. /// <returns></returns>
  266. private bool StartOpenDumpValve()
  267. {
  268. CheckNeedCloseMetalDrain();
  269. bool result = _device.DrainValveOn();
  270. if (!result)
  271. {
  272. NotifyError(eEvent.ERR_RINSE, "Open Dump valve error", 0);
  273. return false;
  274. }
  275. return result;
  276. }
  277. /// <summary>
  278. /// 检验快排是否排空
  279. /// </summary>
  280. /// <returns></returns>
  281. private bool CheckWaterLevelEmpty()
  282. {
  283. double currentWaterLevel = _device.RinseData.WaterLevel;
  284. bool reseult = currentWaterLevel < _sensorReadingEmpty;
  285. if (!reseult)
  286. {
  287. NotifyError(eEvent.ERR_RINSE, $"current water level: {currentWaterLevel} is large than sensorReadingEmpty: {_sensorReadingEmpty}", 0);
  288. }
  289. return reseult;
  290. }
  291. /// <summary>
  292. /// 检验是否需要关闭Metal Valve
  293. /// </summary>
  294. /// <returns></returns>
  295. private void CheckNeedCloseMetalDrain()
  296. {
  297. //此时已经冲洗的次数包括第一步加第二步加第三步的一次
  298. if (_recipe.Step1NumberOfRinse + _recipe.Step2NumberOfRinse + 1 > _recipe.Step1NumberOfDumpToMetalDrain)
  299. {
  300. bool result = _device.WasteValveOn();
  301. if (!result)
  302. {
  303. NotifyError(eEvent.ERR_RINSE, "Close Metal Drain Valve error", 0);
  304. }
  305. }
  306. }
  307. /// <summary>
  308. /// ResistivityStart
  309. /// </summary>
  310. /// <returns></returns>
  311. private bool ResistivityStart()
  312. {
  313. bool result = true;
  314. result = _device.FillValveOff();
  315. if (!result)
  316. {
  317. NotifyError(eEvent.ERR_RINSE, "Fill Valve Off error", 0);
  318. return false;
  319. }
  320. if (_recipe.Step2N2BubbleOn)
  321. {
  322. result = _device.N2ValveOff();
  323. if (!result)
  324. {
  325. NotifyError(eEvent.ERR_RINSE, "N2 Valve Off error", 0);
  326. return false;
  327. }
  328. }
  329. return result;
  330. }
  331. /// <summary>
  332. /// ResistivityAveraging
  333. /// </summary>
  334. /// <returns></returns>
  335. private bool ResistivityAveraging()
  336. {
  337. if (_recipe.ResistivityDurationSeconds == 0)
  338. {
  339. _resistivitySample.Add(GetResitivity());
  340. }
  341. else
  342. {
  343. _startSampleTime = DateTime.Now;
  344. _sampeIntervalTime = DateTime.Now;
  345. _startSample = true;
  346. }
  347. return true;
  348. }
  349. /// <summary>
  350. /// 采样Resitivity
  351. /// </summary>
  352. /// <returns></returns>
  353. private bool ResitivitySampleResitivity()
  354. {
  355. if (!_startSample)
  356. {
  357. return true;
  358. }
  359. int sampleTotalCount = (int)Math.Ceiling(_recipe.ResistivityDurationSeconds / 0.1);
  360. //每隔100毫秒采样
  361. if (DateTime.Now.Subtract(_sampeIntervalTime).TotalMilliseconds >= 100)
  362. {
  363. _sampeIntervalTime = DateTime.Now;
  364. _readResistivityCount++;
  365. _resistivitySample.Add(GetResitivity());
  366. }
  367. //ResistivityDurationSeconds时长减去0.1s,避免超时
  368. if (DateTime.Now.Subtract(_startSampleTime).TotalMilliseconds >= _recipe.ResistivityDurationSeconds * 1000 - 100)
  369. {
  370. bool result = CheckResistivity();
  371. if (!result)
  372. {
  373. Runner.Stop("Sample Resitiviy abormal", true);
  374. }
  375. return result;
  376. }
  377. return false;
  378. }
  379. //读取Resitivity的值
  380. private double GetResitivity()
  381. {
  382. double resistivity = 0;
  383. ResistivityController resistivityController = DEVICE.GetDevice<ResistivityController>(_device.RinseItem.ResistivityID);
  384. if (resistivityController != null)
  385. {
  386. try
  387. {
  388. resistivity = double.Parse(resistivityController.ResisitivityValue.Trim());
  389. }
  390. catch
  391. {
  392. resistivity = 0;
  393. }
  394. }
  395. return resistivity;
  396. }
  397. /// <summary>
  398. /// CheckResistivity
  399. /// </summary>
  400. /// <returns></returns>
  401. private bool CheckResistivity()
  402. {
  403. if (_recipe.ResistivityMegaOhms == 0)
  404. {
  405. _resistivitySample.Clear();
  406. return true;
  407. }
  408. double resistivityAverageValue = _resistivitySample.Average();
  409. if ((_resistivitySample.Count == 1 && _resistivitySample[0] < _recipe.ResistivityMegaOhms) || resistivityAverageValue < _recipe.ResistivityMegaOhms)
  410. {
  411. NotifyError(eEvent.ERR_RINSE, $"The detected resistivity value is abnormal,: {resistivityAverageValue}", 0);
  412. }
  413. else
  414. {
  415. LOG.WriteLog(eEvent.INFO_RINSE, Module, $"The detected resistivity value is : {resistivityAverageValue}");
  416. }
  417. _resistivitySample.Clear();
  418. return true;
  419. }
  420. /// <summary>
  421. /// Abort
  422. /// </summary>
  423. public void Abort()
  424. {
  425. Runner.Stop("Manual abort");
  426. }
  427. }
  428. }