EfemSwapRoutine.cs 7.7 KB

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