EfemSwapRoutine.cs 9.9 KB

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