VpwVentPrewetRoutine.cs 11 KB

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