EfemSwapRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. using Aitex.Core.RT.Routine;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Sorter.Common;
  4. using Venus_RT.Devices;
  5. using MECF.Framework.Common.Jobs;
  6. using MECF.Framework.Common.Routine;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.SubstrateTrackings;
  9. using Venus_Core;
  10. using Aitex.Core.RT.Log;
  11. using Aitex.Core.Util;
  12. using MECF.Framework.Common.Schedulers;
  13. using System.Collections.Generic;
  14. using Venus_RT.Devices.EFEM;
  15. namespace Venus_RT.Modules.EFEM
  16. {
  17. class EfemSwapRoutine : ModuleRoutineBase, IRoutine
  18. {
  19. private enum SwapStep
  20. {
  21. WaitModuleReady,
  22. ModulePrepare,
  23. OpenSlitDoor,
  24. WaitEFEMIdle,
  25. MoveWafer,
  26. WaferMoved,
  27. CloseSlitDoor,
  28. NotifyDone,
  29. }
  30. private readonly EfemBase _efem;
  31. private int _moveTimeout = 20 * 1000;
  32. private ModuleName _targetModule;
  33. private LLEntity _llModule;
  34. private TMEntity _tmModule;
  35. Queue<MoveItem> _actionList = new Queue<MoveItem>();
  36. MoveItem _currentAction;
  37. private int _actionCount = 0;
  38. private int _autoPumpOptInWafer = 4;
  39. private int _autoPumpOptOutWafer = 0;
  40. private SequenceLLInOutPath _sequencePattern = SequenceLLInOutPath.DInDOut;
  41. private bool _bAutoMode = true;
  42. public EfemSwapRoutine(EfemBase efem) : base(ModuleName.EfemRobot)
  43. {
  44. _efem = efem;
  45. Name = "Swap";
  46. }
  47. public RState Start(params object[] objs)
  48. {
  49. if (!_efem.IsHomed)
  50. {
  51. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, Module, $"EFEM is not homed, please home it first");
  52. return RState.Failed;
  53. }
  54. _actionList.Clear();
  55. foreach (var item in (Queue<MoveItem>)objs[0])
  56. {
  57. _actionList.Enqueue(new MoveItem(item.SourceModule, item.SourceSlot, item.DestinationModule, item.DestinationSlot, item.RobotHand));
  58. }
  59. if (!WaferManager.Instance.CheckDuplicatedWafersBeforeMove(_actionList))
  60. return RState.Failed;
  61. var firtItem = _actionList.Peek();
  62. if (ModuleHelper.IsLoadLock(firtItem.SourceModule))
  63. _targetModule = firtItem.SourceModule;
  64. else if (ModuleHelper.IsLoadLock(firtItem.DestinationModule))
  65. _targetModule = firtItem.DestinationModule;
  66. else
  67. {
  68. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Invalid move parameter: {firtItem.SourceModule},{firtItem.SourceSlot + 1} => {firtItem.DestinationModule},{firtItem.DestinationSlot + 1} ");
  69. return RState.Failed;
  70. }
  71. _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);
  72. if (_llModule == null)
  73. {
  74. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Invalid Loadlock: {_targetModule}, maybe not installed");
  75. return RState.Failed;
  76. }
  77. _tmModule = Singleton<RouteManager>.Instance.GetTM();
  78. if(_tmModule == null)
  79. {
  80. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Get TM Entity failed.");
  81. return RState.Failed;
  82. }
  83. _moveTimeout = SC.GetValue<int>("EFEM.MotionTimeout") * 1000;
  84. _autoPumpOptInWafer = SC.GetValue<int>("EFEM.LLAutoPumpInWaferOpt");
  85. _autoPumpOptOutWafer = SC.GetValue<int>("EFEM.LLAutoPumpOutWaferOpt");
  86. _sequencePattern = Singleton<RouteManager>.Instance.LLInOutPath;
  87. _bAutoMode = Singleton<RouteManager>.Instance.IsAutoMode;
  88. _actionCount = _actionList.Count;
  89. return Runner.Start(Module, $"EFEM Swap with {_targetModule}");
  90. }
  91. public RState Monitor()
  92. {
  93. Runner.Wait(SwapStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  94. .Run(SwapStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  95. .Run(SwapStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen, _delay_30s)
  96. .LoopStart(SwapStep.WaitEFEMIdle, loopName(), _actionCount, NullFun, WaitRobotReady, _delay_60s)
  97. .LoopRun(SwapStep.MoveWafer, MoveWafer, WaitWaferMoved, _moveTimeout + _delay_1s)
  98. .LoopEnd(SwapStep.WaferMoved, NullFun, _delay_5ms)
  99. .Run(SwapStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed, _delay_30s)
  100. .End(SwapStep.NotifyDone, NotifyLLDone, _delay_50ms);
  101. return Runner.Status;
  102. }
  103. private bool ModulePrepare()
  104. {
  105. _llModule.PostMsg(LLEntity.MSG.Prepare_EFEM);
  106. return true;
  107. }
  108. private string loopName()
  109. {
  110. return "EFEM Swap";
  111. }
  112. private bool IsModulePrepareReady()
  113. {
  114. return _llModule.Status == LLEntity.LLStatus.Ready_For_EFEM;
  115. }
  116. private bool OpenSlitDoor()
  117. {
  118. return _tmModule.TurnEFEMSlitDoor(_targetModule, true, out _);
  119. }
  120. private bool CloseSlitDoor()
  121. {
  122. return _tmModule.TurnEFEMSlitDoor(_targetModule, false, out _);
  123. }
  124. private bool IsSlitDoorOpen()
  125. {
  126. return _tmModule.IsLLSlitDoorOpen(_targetModule);
  127. }
  128. private bool IsSlitDoorClosed()
  129. {
  130. return _tmModule.IsLLSlitDoorClosed(_targetModule);
  131. }
  132. private bool WaitRobotReady()
  133. {
  134. return _efem.Status == RState.End;
  135. }
  136. private bool VerifyWaferExistence(MoveItem item)
  137. {
  138. if (WaferManager.Instance.CheckHasWafer(item.DestinationModule, item.DestinationSlot))
  139. {
  140. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Cannot move wafer as desitination {item.DestinationModule},{item.DestinationSlot} already a wafer: ");
  141. return false;
  142. }
  143. if (WaferManager.Instance.CheckNoWafer(item.SourceModule, item.SourceSlot))
  144. {
  145. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Cannot move wafer as source {item.SourceModule}, {item.SourceSlot} has no wafer");
  146. return false;
  147. }
  148. return true;
  149. }
  150. private bool MoveWafer()
  151. {
  152. if(_actionList.Count <= 0)
  153. {
  154. Runner.Stop("no action");
  155. return true;
  156. }
  157. _currentAction = _actionList.Dequeue();
  158. if (!VerifyWaferExistence(_currentAction))
  159. return false;
  160. var wafer = WaferManager.Instance.GetWafer(_currentAction.SourceModule, _currentAction.SourceSlot);
  161. LOG.Write(eEvent.EV_EFEM_ROBOT, ModuleName.EfemRobot, $"{wafer.WaferOrigin} will be move from {_currentAction.SourceModule} {_currentAction.SourceSlot + 1} to {_currentAction.DestinationModule} {_currentAction.DestinationSlot + 1}");
  162. if (ModuleHelper.IsLoadLock(_currentAction.SourceModule) && ModuleHelper.IsEFEMRobot(_currentAction.DestinationModule))
  163. {
  164. return _efem.Pick(_currentAction.SourceModule, _currentAction.SourceSlot, (Hand)_currentAction.DestinationSlot);
  165. }
  166. else if (ModuleHelper.IsEFEMRobot(_currentAction.SourceModule) && ModuleHelper.IsLoadLock(_currentAction.DestinationModule))
  167. {
  168. return _efem.Place(_currentAction.DestinationModule, _currentAction.DestinationSlot, (Hand)_currentAction.SourceSlot);
  169. }
  170. else
  171. {
  172. LOG.Write(eEvent.ERR_EFEM_ROBOT, ModuleName.EfemRobot, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");
  173. return false;
  174. }
  175. }
  176. private bool WaitWaferMoved()
  177. {
  178. if (_efem.Status == RState.Running)
  179. {
  180. if(Runner.StepElapsedMS > _moveTimeout)
  181. {
  182. WaferManager.Instance.CreateDuplicatedWafer(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  183. Runner.Stop($"EFEM Robot moving wafer from {_currentAction.SourceModule}.{_currentAction.SourceSlot + 1} to {_currentAction.DestinationModule}.{_currentAction.DestinationSlot + 1}, {_moveTimeout}ms");
  184. return true;
  185. }
  186. return false;
  187. }
  188. else if (_efem.Status == RState.End)
  189. {
  190. WaferManager.Instance.WaferMoved(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  191. return true;
  192. }
  193. else
  194. {
  195. WaferManager.Instance.CreateDuplicatedWafer(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  196. Runner.Stop($"EFEM Robot moving wafer failed, {_efem.Status}");
  197. return true;
  198. }
  199. }
  200. private bool NotifyLLDone()
  201. {
  202. var waferStatus = _llModule.GetWaferProcessStatus();
  203. bool bAutoPump = false;
  204. if (_bAutoMode)
  205. {
  206. if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLA) ||
  207. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLB)) &&
  208. waferStatus.unprocessed >= _autoPumpOptInWafer)
  209. {
  210. bAutoPump = true;
  211. }
  212. else if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLB) ||
  213. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLA)) &&
  214. waferStatus.processed <= _autoPumpOptOutWafer)
  215. {
  216. bAutoPump = true;
  217. }
  218. else if (_sequencePattern == SequenceLLInOutPath.DInDOut &&
  219. waferStatus.processed <= _autoPumpOptOutWafer &&
  220. waferStatus.unprocessed >= _autoPumpOptInWafer)
  221. {
  222. bAutoPump = true;
  223. }
  224. }
  225. LOG.Write(eEvent.EV_EFEM_ROBOT, Module, $"NotifyLLDone() => {_targetModule}, Sequence Pattern{_sequencePattern}, unprocessed wafer:{waferStatus.unprocessed}, processed wafer: {waferStatus.processed},bAutoPump = {bAutoPump}, Config Option:{_autoPumpOptInWafer},{_autoPumpOptOutWafer}");
  226. _llModule.PostMsg(bAutoPump ? LLEntity.MSG.AutoPump : LLEntity.MSG.EFEM_Exchange_Ready);
  227. return true;
  228. }
  229. public void Abort()
  230. {
  231. //_efem.Halt();
  232. }
  233. }
  234. }