EfemSwapRoutine.cs 9.8 KB

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