SRDPresenceTestRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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.RecipeCenter;
  7. using MECF.Framework.Common.Routine;
  8. using MECF.Framework.Common.Utilities;
  9. using CyberX8_Core;
  10. using CyberX8_RT.Devices.AXIS;
  11. using CyberX8_RT.Devices.Facilities;
  12. using CyberX8_RT.Devices.SRD;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Reflection;
  17. using System.Runtime.InteropServices;
  18. using System.Text;
  19. using System.Threading;
  20. using System.Threading.Tasks;
  21. namespace CyberX8_RT.Modules.SRD
  22. {
  23. internal class SRDPresenceTestRoutine : RoutineBase, IRoutine
  24. {
  25. private enum PresenceTestStep
  26. {
  27. Ready,
  28. CloseDoor,
  29. CheckCloseDoor,
  30. ChuckVacuumOn,
  31. RunWafer,
  32. RunWaferWait,
  33. InitialUnloadingStateMachine,
  34. Unloading,
  35. UnloadingWait,
  36. End
  37. }
  38. #region 内部变量
  39. /// <summary>
  40. /// Rotation Axis
  41. /// </summary>
  42. private JetAxisBase _rotationAxis;
  43. /// <summary>
  44. /// Arm Axis
  45. /// </summary>
  46. private JetAxisBase _armAxis;
  47. /// <summary>
  48. /// SRD Common
  49. /// </summary>
  50. private SrdCommonDevice _srdCommon;
  51. /// <summary>
  52. /// recipe名称
  53. /// </summary>
  54. private string _recipe;
  55. /// <summary>
  56. /// SRD Recipe
  57. /// </summary>
  58. private SrdRecipe _srdRecipe;
  59. /// <summary>
  60. /// Module
  61. /// </summary>
  62. private string _module;
  63. /// <summary>
  64. /// Wafer Presence Test功能是否启用
  65. /// </summary>
  66. private bool _presenceTestEnabled;
  67. /// <summary>
  68. /// Run wafer Recipe Routine
  69. /// </summary>
  70. private SRDRunWaferRecipeRoutine _runWaferRecipRoutine;
  71. /// <summary>
  72. /// Unload Routine
  73. /// </summary>
  74. private SRDUnloadRoutine _unloadRoutine;
  75. #endregion
  76. #region 属性
  77. /// <summary>
  78. /// 当前子状态机
  79. /// </summary>
  80. public string CurrentStateMachine
  81. {
  82. get { return GetCurrentStateMachine(); }
  83. }
  84. #endregion
  85. /// <summary>
  86. /// 构造函数
  87. /// </summary>
  88. /// <param name="module"></param>
  89. public SRDPresenceTestRoutine(string module) : base(module)
  90. {
  91. _module = module;
  92. _srdCommon = DEVICE.GetDevice<SrdCommonDevice>($"{module}.Common");
  93. _runWaferRecipRoutine = new SRDRunWaferRecipeRoutine(module);
  94. _unloadRoutine = new SRDUnloadRoutine(module);
  95. }
  96. /// <summary>
  97. /// Abort
  98. /// </summary>
  99. public void Abort()
  100. {
  101. if(_unloadRoutine.Monitor() == RState.Running)
  102. {
  103. _unloadRoutine.Abort();
  104. }
  105. if (_runWaferRecipRoutine.Monitor() == RState.Running)
  106. {
  107. _runWaferRecipRoutine.Abort();
  108. }
  109. Runner.Stop("Presence Test Abort");
  110. if (_srdCommon != null)
  111. {
  112. _srdCommon.EnterErrorOperation();
  113. }
  114. }
  115. public RState Monitor()
  116. {
  117. Runner.Wait(PresenceTestStep.Ready, CheckReadyStatus, _delay_1ms)
  118. .Run(PresenceTestStep.CloseDoor, CloseDoor, CheckDoorClosed, _delay_1s)
  119. .Run(PresenceTestStep.ChuckVacuumOn, EngageChuckVacuum, CheckVacuum, _delay_1s)
  120. .Run(PresenceTestStep.RunWafer, () => { return StartRunWaferRecipeRoutine(_recipe); }, _delay_1ms)
  121. .WaitWithStopCondition(PresenceTestStep.RunWaferWait, CheckRunWaferRoutineCompleteStatus, CheckRunWaferRoutineErrorStatus)
  122. .Run(PresenceTestStep.Unloading, () => { return StartUnloadingRoutine(); }, _delay_1ms)
  123. .WaitWithStopCondition(PresenceTestStep.UnloadingWait, CheckUnloadingRoutineCompleteStatus, CheckUnloadingRoutineErrorStatus)
  124. .End(PresenceTestStep.End, NullFun, _delay_1ms);
  125. return Runner.Status;
  126. }
  127. /// <summary>
  128. /// 启动
  129. /// </summary>
  130. /// <param name="objs"></param>
  131. /// <returns></returns>
  132. public RState Start(params object[] objs)
  133. {
  134. _recipe = objs[0].ToString();
  135. _srdRecipe = RecipeFileManager.Instance.LoadGenericityRecipe<SrdRecipe>(_recipe);
  136. if (_srdRecipe == null)
  137. {
  138. LOG.WriteLog(eEvent.INFO_SRD, Module.ToString(), $"Start Run Wafer State Machine, recipe[{_recipe}] is null");
  139. return RState.Failed;
  140. }
  141. Runner.Start(Module, "PresenceTest");
  142. return RState.Running;
  143. }
  144. private bool CheckReadyStatus()
  145. {
  146. //Arm是否开启,是否home
  147. _armAxis = DEVICE.GetDevice<JetAxisBase>($"{_module}.Arm");
  148. if (_armAxis.IsSwitchOn)
  149. {
  150. if (!_armAxis.IsHomed)
  151. {
  152. LOG.WriteLog(eEvent.ERR_SRD, _module, "Arm is not swicth on");
  153. return false;
  154. }
  155. }
  156. else
  157. {
  158. LOG.WriteLog(eEvent.ERR_SRD, _module, "Arm is not home");
  159. return false;
  160. }
  161. //Rotation是否开启,是否home
  162. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{_module}.Rotation");
  163. if (_rotationAxis.IsSwitchOn)
  164. {
  165. if (!_rotationAxis.IsHomed)
  166. {
  167. LOG.WriteLog(eEvent.ERR_SRD, _module, "Rotation is not homed");
  168. return false;
  169. }
  170. }
  171. else
  172. {
  173. LOG.WriteLog(eEvent.ERR_SRD, _module, "Rotation is not switched on ");
  174. return false;
  175. }
  176. //检查N2与CDA
  177. SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  178. var result = systemFacilities.CheckCDAN2();
  179. if (!result.result)
  180. {
  181. LOG.WriteLog(eEvent.ERR_SRD, _module, $"CheckCDAN2 is failed");
  182. return false;
  183. }
  184. //Wafer Presence Test功能是否开启
  185. if (SC.ContainsItem($"SRD.{_module}EnablePresenceCheckvalue"))
  186. {
  187. _presenceTestEnabled = SC.GetValue<bool>($"SRD.{_module}EnablePresenceCheckvalue");
  188. if (!_presenceTestEnabled)
  189. {
  190. LOG.WriteLog(eEvent.ERR_SRD, _module, $"{_module}EnablePresenceCheckvalue is unable");
  191. return false;
  192. }
  193. }
  194. else
  195. {
  196. LOG.WriteLog(eEvent.ERR_SRD, _module, $"Config dosen't have EnablePresenceCheckvalue");
  197. return false;
  198. }
  199. return true;
  200. }
  201. /// <summary>
  202. /// Close Door
  203. /// </summary>
  204. /// <param name="param"></param>
  205. /// <returns></returns>
  206. private bool CloseDoor()
  207. {
  208. bool result = _srdCommon.DoorCloseAction("", null);
  209. if (!result)
  210. {
  211. return false;
  212. }
  213. return result;
  214. }
  215. /// <summary>
  216. /// 检验DoorClosed
  217. /// </summary>
  218. /// <param name="param"></param>
  219. /// <returns></returns>
  220. private bool CheckDoorClosed()
  221. {
  222. if (_srdCommon.Status == RState.Failed || _srdCommon.Status == RState.Timeout)
  223. {
  224. return false;
  225. }
  226. return _srdCommon.Status == RState.End && _srdCommon.CommonData.DoorClosed;
  227. }
  228. /// <summary>
  229. /// Chuck Vacuum On
  230. /// </summary>
  231. /// <param name="param"></param>
  232. /// <returns></returns>
  233. private bool EngageChuckVacuum()
  234. {
  235. bool result = _srdCommon.ChuckVacuumOnAction("", null);
  236. if (!result)
  237. {
  238. return false;
  239. }
  240. return result;
  241. }
  242. /// <summary>
  243. /// 检查真空状态
  244. /// </summary>
  245. /// <param name="param"></param>
  246. /// <returns></returns>
  247. private bool CheckVacuum()
  248. {
  249. if (_srdCommon.Status == RState.Failed || _srdCommon.Status == RState.Timeout)
  250. {
  251. return false;
  252. }
  253. return _srdCommon.Status == RState.End && !_srdCommon.CommonData.ChuckVacuum;
  254. }
  255. #region SRD RunWaferRecipeRoutine
  256. /// <summary>
  257. /// 启动RunWaferRecipeRoutine
  258. /// </summary>
  259. /// <param name="recipe"></param>
  260. /// <returns></returns>
  261. private bool StartRunWaferRecipeRoutine(string recipe)
  262. {
  263. bool presenceTestFlag = true;
  264. return _runWaferRecipRoutine.Start(_srdRecipe, presenceTestFlag) == RState.Running;
  265. }
  266. /// <summary>
  267. /// 检验RunWaferRecipeRoutine是否完成
  268. /// </summary>
  269. /// <returns></returns>
  270. private bool CheckRunWaferRoutineCompleteStatus()
  271. {
  272. return CommonFunction.CheckRoutineEndState(_runWaferRecipRoutine);
  273. }
  274. /// <summary>
  275. /// 检验RunWaferRecipeRoutine是否出错
  276. /// </summary>
  277. /// <returns></returns>
  278. private bool CheckRunWaferRoutineErrorStatus()
  279. {
  280. bool result = CommonFunction.CheckRoutineStopState(_runWaferRecipRoutine);
  281. if (result && _srdCommon != null)
  282. {
  283. _srdCommon.EnterErrorOperation();
  284. }
  285. return result;
  286. }
  287. #endregion
  288. #region SRD UnloadingRoutine
  289. /// <summary>
  290. /// 启动UnloadingRoutine
  291. /// </summary>
  292. /// <param name="recipe"></param>
  293. /// <returns></returns>
  294. private bool StartUnloadingRoutine()
  295. {
  296. return _unloadRoutine.Start() == RState.Running;
  297. }
  298. /// <summary>
  299. /// 检验UnloadingRoutine是否完成
  300. /// </summary>
  301. /// <returns></returns>
  302. private bool CheckUnloadingRoutineCompleteStatus()
  303. {
  304. return CommonFunction.CheckRoutineEndState(_unloadRoutine);
  305. }
  306. /// <summary>
  307. /// 检验UnloadingRoutine是否出错
  308. /// </summary>
  309. /// <returns></returns>
  310. private bool CheckUnloadingRoutineErrorStatus()
  311. {
  312. return CommonFunction.CheckRoutineStopState(_unloadRoutine);
  313. }
  314. #endregion
  315. /// <summary>
  316. /// 获取当前子状态机
  317. /// </summary>
  318. private string GetCurrentStateMachine()
  319. {
  320. string result;
  321. if (Runner.CurrentStep.ToString() == "Ready")
  322. {
  323. result = "Ready";
  324. }
  325. else if (Runner.CurrentStep.ToString().Contains("RunWafer"))
  326. {
  327. result = _runWaferRecipRoutine.CurrentStep;
  328. }
  329. else if (Runner.CurrentStep.ToString().Contains("Unloading"))
  330. {
  331. result = _unloadRoutine.CurrentStep;
  332. }
  333. else
  334. {
  335. result = "End";
  336. }
  337. return result;
  338. }
  339. }
  340. }