EfemSwapRoutine.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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.Routine;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.SubstrateTrackings;
  8. using Venus_Core;
  9. using Aitex.Core.RT.Log;
  10. using Aitex.Core.Util;
  11. using MECF.Framework.Common.Schedulers;
  12. using System.Collections.Generic;
  13. using Venus_RT.Devices.EFEM;
  14. namespace Venus_RT.Modules.EFEM
  15. {
  16. class EfemSwapRoutine : ModuleRoutineBase, IRoutine
  17. {
  18. private enum SwapStep
  19. {
  20. WaitModuleReady,
  21. ModulePrepare,
  22. OpenSlitDoor,
  23. MoveWafer,
  24. WaitMaferMoved,
  25. CloseSlitDoor,
  26. NotifyDone,
  27. }
  28. private readonly EfemBase _efem;
  29. private int _moveTimeout = 20 * 1000;
  30. private ModuleName _targetModule;
  31. private LLEntity _llModule;
  32. private TMEntity _tmModule;
  33. Queue<MoveItem> _actionList = new Queue<MoveItem>();
  34. MoveItem _currentAction;
  35. public EfemSwapRoutine(EfemBase efem) : base(ModuleName.EfemRobot)
  36. {
  37. _efem = efem;
  38. Name = "Swap";
  39. }
  40. public RState Start(params object[] objs)
  41. {
  42. if (!_efem.IsHomed)
  43. {
  44. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, Module, $"EFEM is not homed, please home it first");
  45. return RState.Failed;
  46. }
  47. _actionList = (Queue<MoveItem>)objs[0];
  48. var firtItem = _actionList.Peek();
  49. if (ModuleHelper.IsLoadLock(firtItem.SourceModule))
  50. _targetModule = firtItem.SourceModule;
  51. else if (ModuleHelper.IsLoadLock(firtItem.DestinationModule))
  52. _targetModule = firtItem.DestinationModule;
  53. else
  54. {
  55. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Invalid move parameter: {firtItem.SourceModule},{firtItem.SourceSlot + 1} => {firtItem.DestinationModule},{firtItem.DestinationSlot + 1} ");
  56. return RState.Failed;
  57. }
  58. _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);
  59. if (_llModule == null)
  60. {
  61. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Invalid Loadlock: {_targetModule}, maybe not installed");
  62. return RState.Failed;
  63. }
  64. _tmModule = Singleton<RouteManager>.Instance.GetTM();
  65. if(_tmModule == null)
  66. {
  67. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Get TM Entity failed.");
  68. return RState.Failed;
  69. }
  70. _moveTimeout = SC.GetValue<int>($"EFEM.MotionTimeout") * 1000;
  71. return Runner.Start(Module, $"EFEM Swap with {_targetModule}");
  72. }
  73. public RState Monitor()
  74. {
  75. Runner.Wait((int)SwapStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  76. .Run((int)SwapStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  77. .Run((int)SwapStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen)
  78. .LoopStart((int)SwapStep.MoveWafer, loopName(), _actionList.Count, MoveWafer)
  79. .LoopEnd((int)SwapStep.WaitMaferMoved, NullFun, WaitWaferMoved, _moveTimeout)
  80. .Run((int)SwapStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed)
  81. .End((int)SwapStep.NotifyDone, NotifyLLDone, _delay_50ms);
  82. return Runner.Status;
  83. }
  84. private bool ModulePrepare()
  85. {
  86. _llModule.PostMsg(LLEntity.MSG.Prepare_EFEM);
  87. return true;
  88. }
  89. private string loopName()
  90. {
  91. return "EFEM Swap";
  92. }
  93. private bool IsModulePrepareReady()
  94. {
  95. return _llModule.Status == LLEntity.LLStatus.Ready_For_EFEM;
  96. }
  97. private bool OpenSlitDoor()
  98. {
  99. return _tmModule.TurnEFEMSlitDoor(_targetModule, true, out _);
  100. }
  101. private bool CloseSlitDoor()
  102. {
  103. return _tmModule.TurnEFEMSlitDoor(_targetModule, false, out _);
  104. }
  105. private bool IsSlitDoorOpen()
  106. {
  107. return _tmModule.IsLLSlitDoorOpen(_targetModule);
  108. }
  109. private bool IsSlitDoorClosed()
  110. {
  111. return _tmModule.IsLLSlitDoorClosed(_targetModule);
  112. }
  113. private bool VerifyWaferExistence(MoveItem item)
  114. {
  115. if (WaferManager.Instance.CheckHasWafer(item.DestinationModule, item.DestinationSlot))
  116. {
  117. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Cannot move wafer as desitination {item.DestinationModule},{item.DestinationSlot} already a wafer: ");
  118. return false;
  119. }
  120. if (WaferManager.Instance.CheckNoWafer(item.SourceModule, item.SourceSlot))
  121. {
  122. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Cannot move wafer as source {item.SourceModule}, {item.SourceSlot} has no wafer");
  123. return false;
  124. }
  125. return true;
  126. }
  127. private bool MoveWafer()
  128. {
  129. _currentAction = _actionList.Dequeue();
  130. if (!VerifyWaferExistence(_currentAction))
  131. return false;
  132. var wafer = WaferManager.Instance.GetWafer(_currentAction.SourceModule, _currentAction.SourceSlot);
  133. 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}");
  134. if (ModuleHelper.IsLoadLock(_currentAction.SourceModule) && ModuleHelper.IsEFEMRobot(_currentAction.DestinationModule))
  135. {
  136. return _efem.Pick(_currentAction.SourceModule, _currentAction.SourceSlot, (Hand)_currentAction.DestinationSlot);
  137. }
  138. else if (ModuleHelper.IsEFEMRobot(_currentAction.SourceModule) && ModuleHelper.IsLoadLock(_currentAction.DestinationModule))
  139. {
  140. return _efem.Place(_currentAction.DestinationModule, _currentAction.DestinationSlot, (Hand)_currentAction.SourceSlot);
  141. }
  142. else
  143. {
  144. LOG.Write(eEvent.ERR_EFEM_ROBOT, ModuleName.TM, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");
  145. return false;
  146. }
  147. }
  148. private bool WaitWaferMoved()
  149. {
  150. if (_efem.Status == RState.Running)
  151. {
  152. return false;
  153. }
  154. else if (_efem.Status == RState.End)
  155. {
  156. WaferManager.Instance.WaferMoved(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  157. return true;
  158. }
  159. else
  160. {
  161. Runner.Stop($"EFEM Robot moving wafer failed, {_efem.Status}");
  162. return true;
  163. }
  164. }
  165. private bool NotifyLLDone()
  166. {
  167. _llModule.PostMsg(LLEntity.MSG.EFEM_Exchange_Ready);
  168. return true;
  169. }
  170. public void Abort()
  171. {
  172. _efem.Halt();
  173. }
  174. }
  175. }