EfemSwapRoutine.cs 9.4 KB

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