VpwVentPrewetRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using MECF.Framework.Common.Alarm;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.RecipeCenter;
  9. using MECF.Framework.Common.Routine;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using PunkHPX8_Core;
  12. using PunkHPX8_RT.Devices.AXIS;
  13. using PunkHPX8_RT.Devices.VpwCell;
  14. using PunkHPX8_RT.Devices.VpwMain;
  15. using PunkHPX8_RT.Modules.VpwMain;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Diagnostics;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. namespace PunkHPX8_RT.Modules.VpwCell
  23. {
  24. public class VpwVentPrewetRoutine : RoutineBase, IRoutine
  25. {
  26. private enum PrepareStep
  27. {
  28. CloseVacuumpumpAndValve,
  29. OpenVentValve,
  30. CheckLidReleaseVacuum,
  31. CloseVentValve,
  32. OpenCellValve,
  33. LoopStart,
  34. LoopRun,
  35. LoopEnd,
  36. End
  37. }
  38. #region 内部变量
  39. /// <summary>
  40. /// recipe
  41. /// </summary>
  42. private VpwRecipe _recipe;
  43. /// <summary>
  44. /// 设备
  45. /// </summary>
  46. private VpwCellDevice _vpwCellDevice;
  47. /// <summary>
  48. /// Main设备
  49. /// </summary>
  50. private VpwMainDevice _mainDevice;
  51. /// <summary>
  52. /// Lid Release Pressure
  53. /// </summary>
  54. private int _lidReleasePressure = 730;
  55. /// <summary>
  56. /// Lid Release Pressure
  57. /// </summary>
  58. private int _lidReleasePressureTimeout = 10000;
  59. /// <summary>
  60. /// 总时长
  61. /// </summary>
  62. private int _totalMicrosecond = 0;
  63. /// <summary>
  64. /// 步骤
  65. /// </summary>
  66. private int _stepIndex = 0;
  67. /// <summary>
  68. /// 启动步骤时间
  69. /// </summary>
  70. private DateTime _startStepTime = DateTime.Now;
  71. #endregion
  72. /// <summary>
  73. /// 构造函数
  74. /// </summary>
  75. /// <param name="module"></param>
  76. public VpwVentPrewetRoutine(string module) : base(module)
  77. {
  78. }
  79. /// <summary>
  80. /// 中止
  81. /// </summary>
  82. public void Abort()
  83. {
  84. Runner.Stop("Manual abort");
  85. }
  86. /// <summary>
  87. /// 监控
  88. /// </summary>
  89. /// <returns></returns>
  90. public RState Monitor()
  91. {
  92. Runner.Run(PrepareStep.CloseVacuumpumpAndValve, CloseVacuumpumpAndValve, _delay_1ms)
  93. .Run(PrepareStep.OpenVentValve, OpenVentValve, _delay_1ms)
  94. .Wait(PrepareStep.CheckLidReleaseVacuum, CheckLidReleaseVacuum, _lidReleasePressureTimeout)
  95. .Run(PrepareStep.CloseVentValve, CloseVentValve, _delay_1ms)
  96. .Run(PrepareStep.OpenCellValve,OpenCellValve,_delay_1ms)
  97. .LoopStart(PrepareStep.LoopStart,"Loop Step",_recipe.VentRinseStep.Count,NullFun,_delay_1ms)
  98. .LoopRunWithStopStatus(PrepareStep.LoopRun, CheckStepComplete, () => { return false; }, _totalMicrosecond + 60 * 1000)//总时长再延迟1分种
  99. .LoopEnd(PrepareStep.LoopEnd,NullFun,_delay_1ms)
  100. .End(PrepareStep.End,NullFun,_delay_1ms);
  101. return Runner.Status;
  102. }
  103. /// <summary>
  104. /// 关闭真空泵和阀
  105. /// </summary>
  106. /// <returns></returns>
  107. private bool CloseVacuumpumpAndValve()
  108. {
  109. bool result = _mainDevice.VacuumPumpDisable();
  110. result &= _vpwCellDevice.VacuumValveOff();
  111. if (!result)
  112. {
  113. NotifyError(eEvent.ERR_VPW, "close vacuum pump and vavuum valve failed", 0);
  114. }
  115. return result;
  116. }
  117. /// <summary>
  118. /// 检验Lid Release真空数值
  119. /// </summary>
  120. /// <returns></returns>
  121. private bool CheckLidReleaseVacuum()
  122. {
  123. double vacuumValue = _vpwCellDevice.CommonData.VacuumPressure;
  124. return vacuumValue >= _lidReleasePressure;
  125. }
  126. /// <summary>
  127. /// open vent valve
  128. /// </summary>
  129. /// <returns></returns>
  130. private bool OpenVentValve()
  131. {
  132. bool result = _vpwCellDevice.VentValveOn();
  133. if (!result)
  134. {
  135. NotifyError(eEvent.ERR_VPW, "open vent valve failed", 0);
  136. }
  137. return result;
  138. }
  139. /// <summary>
  140. /// close vent valve
  141. /// </summary>
  142. /// <returns></returns>
  143. private bool CloseVentValve()
  144. {
  145. bool result = _vpwCellDevice.VentValveOff();
  146. if (!result)
  147. {
  148. NotifyError(eEvent.ERR_VPW, "close vent valve failed", 0);
  149. }
  150. return result;
  151. }
  152. /// <summary>
  153. /// 打开相应的cell valve
  154. /// </summary>
  155. /// <returns></returns>
  156. private bool OpenCellValve()
  157. {
  158. int count = 0;
  159. int enableCount = 0;
  160. if (_recipe.VentPrewetDripEnable)
  161. {
  162. count += _vpwCellDevice.FlowDripOn()?1:0;
  163. enableCount++;
  164. }
  165. else
  166. {
  167. _vpwCellDevice.FlowDripOff();
  168. }
  169. if (_recipe.VentPrewetLargeEnable)
  170. {
  171. count += _vpwCellDevice.FlowLargeOn() ? 1 : 0;
  172. enableCount++;
  173. }
  174. else
  175. {
  176. _vpwCellDevice.FlowLargeOff();
  177. }
  178. if (_recipe.VentPrewetSmallEnable)
  179. {
  180. count += _vpwCellDevice.FlowSmallOn() ? 1 : 0;
  181. enableCount++;
  182. }
  183. else
  184. {
  185. _vpwCellDevice.FlowSmallOff();
  186. }
  187. bool result = count == enableCount;
  188. if (!result)
  189. {
  190. NotifyError(eEvent.ERR_VPW, "open cell valve failed", 0);
  191. }
  192. foreach (var item in _recipe.VentRinseStep)
  193. {
  194. _totalMicrosecond += item.DurationSeconds * 1000;
  195. }
  196. _startStepTime = DateTime.Now;
  197. _stepIndex = 0;
  198. return result;
  199. }
  200. /// <summary>
  201. /// 检验步骤是否完成
  202. /// </summary>
  203. /// <returns></returns>
  204. private bool CheckStepComplete()
  205. {
  206. _mainDevice.CellFlow = _vpwCellDevice.CommonData.DiwFlow;
  207. if (_stepIndex >= _recipe.VentRinseStep.Count)
  208. {
  209. LOG.WriteLog(eEvent.INFO_VPW, Module, $"vent step {_stepIndex} is over step count {_recipe.VentRinseStep.Count}");
  210. return true;
  211. }
  212. int length = _recipe.VentRinseStep[_stepIndex].DurationSeconds;
  213. if (DateTime.Now.Subtract(_startStepTime).TotalSeconds >= length)
  214. {
  215. _stepIndex++;
  216. _startStepTime = DateTime.Now;
  217. if (_stepIndex >= _recipe.VentRinseStep.Count)
  218. {
  219. LOG.WriteLog(eEvent.INFO_VPW, Module, $"vent step {_stepIndex} is over step count {_recipe.VentRinseStep.Count}");
  220. return true;
  221. }
  222. bool result = _vpwCellDevice.ChangeRotationSpeed(_recipe.VentRinseStep[_stepIndex].RotationSpeed*6);
  223. if (result)
  224. {
  225. LOG.WriteLog(eEvent.INFO_VPW, Module, $"vent step {_stepIndex} complete");
  226. }
  227. return result;
  228. }
  229. int firstDelay = SC.GetValue<int>($"{Module}.FlowCheckDelay") * 1000;
  230. if (DateTime.Now.Subtract(_startStepTime).TotalMilliseconds >= firstDelay)
  231. {
  232. bool abnormal = CheckDisable();
  233. if (abnormal)
  234. {
  235. return false;
  236. }
  237. }
  238. return false;
  239. }
  240. /// <summary>
  241. /// 检验数据
  242. /// </summary>
  243. /// <returns></returns>
  244. private bool CheckDisable()
  245. {
  246. double flow = _vpwCellDevice.CommonData.DiwFlow;
  247. double lowError = _recipe.VentPrewetFlowSetPoint * (1 - (double)_recipe.VentPrewetFlowErrorPercent / 100);
  248. double upError = _recipe.VentPrewetFlowSetPoint * (1 + (double)_recipe.VentPrewetFlowErrorPercent / 100);
  249. double lowWarn = _recipe.VentPrewetFlowSetPoint * (1 - (double)_recipe.VentPrewetFlowWarningPercent / 100);
  250. double upWarn = _recipe.VentPrewetFlowSetPoint * (1 + (double)_recipe.VentPrewetFlowWarningPercent / 100);
  251. if (flow<lowError)
  252. {
  253. NotifyError(eEvent.ERR_VPW, $"{Module} cell flow {flow} is less than {lowError} ", 0);
  254. Abort();
  255. return true;
  256. }
  257. if (flow > upError)
  258. {
  259. NotifyError(eEvent.ERR_VPW, $"{Module} cell flow {flow} is up than {upError} ", 0);
  260. Abort();
  261. return true;
  262. }
  263. if ((flow <= upError && flow >= upWarn) || (flow >= lowError && flow <= lowWarn))
  264. {
  265. string str = $"{Module} cell flow {flow} is in warning";
  266. if (AlarmListManager.Instance.AddWarn(Module, $"{Module} cell flow", str))
  267. {
  268. LOG.WriteLog(eEvent.WARN_VPW, Module, str);
  269. }
  270. }
  271. bool isSimulatorMode = SC.GetValue<bool>("System.IsSimulatorMode");
  272. if (!isSimulatorMode)
  273. {
  274. if (!_vpwCellDevice.CheckRotationRunning())
  275. {
  276. NotifyError(eEvent.ERR_VPW, $"{Module} rotation is stopped", 0);
  277. Abort();
  278. return true;
  279. }
  280. }
  281. return false;
  282. }
  283. /// <summary>
  284. /// 启动
  285. /// </summary>
  286. /// <param name="objs"></param>
  287. /// <returns></returns>
  288. public RState Start(params object[] objs)
  289. {
  290. _recipe=(VpwRecipe)objs[0];
  291. _vpwCellDevice = DEVICE.GetDevice<VpwCellDevice>(Module);
  292. _mainDevice = DEVICE.GetDevice<VpwMainDevice>(ModuleName.VPWMain1.ToString());
  293. _lidReleasePressure = SC.GetValue<int>($"{Module}.LidReleasePressure");
  294. _lidReleasePressureTimeout = SC.GetValue<int>($"{Module}.LidReleasePressureTimeout")*1000;
  295. _totalMicrosecond = 0;
  296. _stepIndex = 0;
  297. return Runner.Start(Module, $"{Module} vent prewet");
  298. }
  299. /// <summary>
  300. /// 重试
  301. /// </summary>
  302. /// <param name="step"></param>
  303. public RState Retry(int step)
  304. {
  305. if (_recipe == null)
  306. {
  307. NotifyError(eEvent.ERR_VPW, "recipe is null", -1);
  308. return RState.Failed;
  309. }
  310. List<Enum> preStepIds = new List<Enum>();
  311. return Runner.Retry(PrepareStep.OpenVentValve, preStepIds, Module, "Vent Prewet Retry");
  312. }
  313. }
  314. }