EfemSwapRoutine.cs 8.3 KB

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