EfemSwapRoutine.cs 9.9 KB

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