EfemSwapRoutine.cs 7.7 KB

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