VpwSpinOffRoutine.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 VpwSpinOffRoutine : RoutineBase, IRoutine
  25. {
  26. private enum PrepareStep
  27. {
  28. CloseCellValve,
  29. LoopStart,
  30. LoopRun,
  31. LoopEnd,
  32. End
  33. }
  34. #region 内部变量
  35. /// <summary>
  36. /// recipe
  37. /// </summary>
  38. private VpwRecipe _recipe;
  39. /// <summary>
  40. /// 设备
  41. /// </summary>
  42. private VpwCellDevice _vpwCellDevice;
  43. /// <summary>
  44. /// Main设备
  45. /// </summary>
  46. private VpwMainDevice _mainDevice;
  47. /// <summary>
  48. /// Lid Release Pressure
  49. /// </summary>
  50. private int _lidReleasePressure = 730;
  51. /// <summary>
  52. /// Lid Release Pressure
  53. /// </summary>
  54. private int _lidReleasePressureTimeout = 10000;
  55. /// <summary>
  56. /// 总时长
  57. /// </summary>
  58. private int _totalMicrosecond = 0;
  59. /// <summary>
  60. /// 步骤
  61. /// </summary>
  62. private int _stepIndex = 0;
  63. /// <summary>
  64. /// 启动步骤时间
  65. /// </summary>
  66. private DateTime _startStepTime = DateTime.Now;
  67. #endregion
  68. /// <summary>
  69. /// 构造函数
  70. /// </summary>
  71. /// <param name="module"></param>
  72. public VpwSpinOffRoutine(string module) : base(module)
  73. {
  74. }
  75. /// <summary>
  76. /// 中止
  77. /// </summary>
  78. public void Abort()
  79. {
  80. Runner.Stop("Manual abort");
  81. }
  82. /// <summary>
  83. /// 监控
  84. /// </summary>
  85. /// <returns></returns>
  86. public RState Monitor()
  87. {
  88. Runner.Run(PrepareStep.CloseCellValve,CloseCellValve,_delay_1ms)
  89. .LoopStart(PrepareStep.LoopStart,"Loop Step",1,NullFun,_delay_1ms)
  90. .LoopRunWithStopStatus(PrepareStep.LoopRun, CheckStepComplete, () => { return false; }, _totalMicrosecond + 60 * 1000)//总时长再延迟1分种
  91. .LoopEnd(PrepareStep.LoopEnd,NullFun,_delay_1ms)
  92. .End(PrepareStep.End,NullFun,_delay_1ms);
  93. return Runner.Status;
  94. }
  95. /// <summary>
  96. /// 打开相应的cell valve
  97. /// </summary>
  98. /// <returns></returns>
  99. private bool CloseCellValve()
  100. {
  101. int count = 0;
  102. count += _vpwCellDevice.FlowDripOff()?1:0;
  103. count += _vpwCellDevice.FlowLargeOff() ? 1 : 0;
  104. count += _vpwCellDevice.FlowSmallOff() ? 1 : 0;
  105. bool result= count == 3;
  106. if (!result)
  107. {
  108. NotifyError(eEvent.ERR_VPW, "close cell valve failed", 0);
  109. }
  110. _totalMicrosecond += _recipe.SpinTime * 1000;
  111. _startStepTime = DateTime.Now;
  112. _stepIndex = 0;
  113. return result;
  114. }
  115. /// <summary>
  116. /// 检验步骤是否完成
  117. /// </summary>
  118. /// <returns></returns>
  119. private bool CheckStepComplete()
  120. {
  121. _mainDevice.CellFlow = _vpwCellDevice.CommonData.DiwFlow;
  122. if (_stepIndex >= 1)
  123. {
  124. LOG.WriteLog(eEvent.INFO_VPW, Module, $"step {_stepIndex} is over step count 1");
  125. return true;
  126. }
  127. int length = _recipe.SpinTime;
  128. if (DateTime.Now.Subtract(_startStepTime).TotalSeconds >= length)
  129. {
  130. _stepIndex++;
  131. _startStepTime = DateTime.Now;
  132. if (_stepIndex >= 1)
  133. {
  134. LOG.WriteLog(eEvent.INFO_VPW, Module, $"step {_stepIndex} is over step count 1");
  135. return true;
  136. }
  137. bool result = _vpwCellDevice.ChangeRotationSpeed(_recipe.SpinSpeed*6);
  138. if (result)
  139. {
  140. LOG.WriteLog(eEvent.INFO_VPW, Module, $"step {_stepIndex} complete");
  141. }
  142. return result;
  143. }
  144. int firstDelay = SC.GetValue<int>($"{Module}.FlowCheckDelay") * 1000;
  145. if (DateTime.Now.Subtract(_startStepTime).TotalMilliseconds >= firstDelay)
  146. {
  147. bool abnormal = CheckDisable();
  148. if (abnormal)
  149. {
  150. return false;
  151. }
  152. }
  153. return false;
  154. }
  155. /// <summary>
  156. /// 检验数据
  157. /// </summary>
  158. /// <returns></returns>
  159. private bool CheckDisable()
  160. {
  161. double flow = _vpwCellDevice.CommonData.DiwFlow;
  162. double lowError = _recipe.VentPrewetFlowSetPoint * (1 - (double)_recipe.VentPrewetFlowErrorPercent / 100);
  163. double upError = _recipe.VentPrewetFlowSetPoint * (1 + (double)_recipe.VentPrewetFlowErrorPercent / 100);
  164. double lowWarn = _recipe.VentPrewetFlowSetPoint * (1 - (double)_recipe.VentPrewetFlowWarningPercent / 100);
  165. double upWarn = _recipe.VentPrewetFlowSetPoint * (1 + (double)_recipe.VentPrewetFlowWarningPercent / 100);
  166. if (flow<lowError)
  167. {
  168. NotifyError(eEvent.ERR_VPW, $"{Module} cell flow {flow} is less than {lowError} ", 0);
  169. Abort();
  170. return true;
  171. }
  172. if (flow > upError)
  173. {
  174. NotifyError(eEvent.ERR_VPW, $"{Module} cell flow {flow} is up than {upError} ", 0);
  175. Abort();
  176. return true;
  177. }
  178. if ((flow <= upError && flow >= upWarn) || (flow >= lowError && flow <= lowWarn))
  179. {
  180. string str = $"{Module} cell flow {flow} is in warning";
  181. if (AlarmListManager.Instance.AddWarn(Module, $"{Module} cell flow", str))
  182. {
  183. LOG.WriteLog(eEvent.WARN_VPW, Module, str);
  184. }
  185. }
  186. bool isSimulatorMode = SC.GetValue<bool>("System.IsSimulatorMode");
  187. if (!isSimulatorMode)
  188. {
  189. if (!_vpwCellDevice.CheckRotationRunning())
  190. {
  191. NotifyError(eEvent.ERR_VPW, $"{Module} rotation is stopped", 0);
  192. Abort();
  193. return true;
  194. }
  195. }
  196. return false;
  197. }
  198. /// <summary>
  199. /// 启动
  200. /// </summary>
  201. /// <param name="objs"></param>
  202. /// <returns></returns>
  203. public RState Start(params object[] objs)
  204. {
  205. _recipe=(VpwRecipe)objs[0];
  206. _vpwCellDevice = DEVICE.GetDevice<VpwCellDevice>(Module);
  207. _mainDevice = DEVICE.GetDevice<VpwMainDevice>(ModuleName.VPWMain1.ToString());
  208. _lidReleasePressure = SC.GetValue<int>($"{Module}.LidReleasePressure");
  209. _lidReleasePressureTimeout = SC.GetValue<int>($"{Module}.LidReleasePressureTimeout");
  210. _totalMicrosecond = 0;
  211. _stepIndex = 0;
  212. return Runner.Start(Module, $"{Module} spin off");
  213. }
  214. /// <summary>
  215. /// 重试
  216. /// </summary>
  217. /// <param name="step"></param>
  218. public RState Retry(int step)
  219. {
  220. if (_recipe == null)
  221. {
  222. NotifyError(eEvent.ERR_VPW, "recipe is null", -1);
  223. return RState.Failed;
  224. }
  225. List<Enum> preStepIds = new List<Enum>();
  226. return Runner.Retry(PrepareStep.CloseCellValve, preStepIds, Module, "Spin off Retry");
  227. }
  228. }
  229. }