MFSwapRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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 System;
  13. using System.Text;
  14. using System.Collections.Generic;
  15. using MECF.Framework.Common.Schedulers;
  16. namespace Venus_RT.Modules.TM
  17. {
  18. class MFSwapRoutine : ModuleRoutineBase, IRoutine
  19. {
  20. private enum SwapStep
  21. {
  22. WaitModuleReady,
  23. PreRotation,
  24. ModulePrepare,
  25. OpenSlitDoor,
  26. MoveWafer,
  27. WaitMaferMoved,
  28. CloseSlitDoor,
  29. NotifyDone,
  30. }
  31. private readonly JetTM _JetTM;
  32. private readonly ITransferRobot _robot;
  33. private int _swapTimeout = 120 * 1000;
  34. private ModuleName _targetModule;
  35. private LLEntity _llModule;
  36. private int _autoVentOptInWafer = 0;
  37. private int _autoVentOptOutWafer = 4;
  38. private SequenceLLInOutPath _sequencePattern = SequenceLLInOutPath.DInDOut;
  39. private bool _bAutoMode = true;
  40. Queue<MoveItem> _actionList = new Queue<MoveItem>();
  41. MoveItem _currentAction;
  42. public MFSwapRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  43. {
  44. _JetTM = tm;
  45. _robot = robot;
  46. Name = "Swap";
  47. }
  48. public RState Start(params object[] objs)
  49. {
  50. if (!_robot.IsHomed)
  51. {
  52. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot 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. var firtItem = _actionList.Peek();
  61. if (ModuleHelper.IsLoadLock(firtItem.SourceModule))
  62. _targetModule = firtItem.SourceModule;
  63. else if (ModuleHelper.IsLoadLock(firtItem.DestinationModule))
  64. _targetModule = firtItem.DestinationModule;
  65. else
  66. {
  67. LOG.Write(eEvent.ERR_TM, Module, $"Invalid move parameter: {firtItem.SourceModule},{firtItem.SourceSlot + 1} => {firtItem.DestinationModule},{firtItem.DestinationSlot + 1} ");
  68. return RState.Failed;
  69. }
  70. _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);
  71. if(_llModule == null)
  72. {
  73. LOG.Write(eEvent.ERR_TM, Module, $"Invalid Loadlock: {_targetModule}, maybe not installed");
  74. return RState.Failed;
  75. }
  76. Reset();
  77. _swapTimeout = SC.GetValue<int>($"TM.SwapTimeout") * 1000;
  78. _autoVentOptInWafer = SC.GetValue<int>("TM.LLAutoVentInWaferOpt");
  79. _autoVentOptOutWafer = SC.GetValue<int>("TM.LLAutoVentOutWaferOpt");
  80. _sequencePattern = Singleton<RouteManager>.Instance.LLInOutPath;
  81. _bAutoMode = Singleton<RouteManager>.Instance.IsAutoMode;
  82. return Runner.Start(Module, $"Swap with {_targetModule}");
  83. }
  84. public RState Monitor()
  85. {
  86. Runner.Wait(SwapStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  87. .RunIf(SwapStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  88. .Run(SwapStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  89. .Run(SwapStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen)
  90. .LoopStart(SwapStep.MoveWafer, loopName(), _actionList.Count, MoveWafer)
  91. .LoopEnd(SwapStep.WaitMaferMoved, NullFun, WaitWaferMoved)
  92. .Run(SwapStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed)
  93. .End(SwapStep.NotifyDone, NotifyLLDone, _delay_50ms);
  94. return Runner.Status;
  95. }
  96. private bool ModulePrepare()
  97. {
  98. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  99. return true;
  100. }
  101. private string loopName()
  102. {
  103. return "LoadLock Swap" ;
  104. }
  105. private bool IsModulePrepareReady()
  106. {
  107. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  108. }
  109. private bool OpenSlitDoor()
  110. {
  111. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  112. }
  113. private bool CloseSlitDoor()
  114. {
  115. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  116. }
  117. private bool IsSlitDoorOpen()
  118. {
  119. if (_targetModule == ModuleName.LLA)
  120. return _JetTM.IsLLASlitDoorOpen;
  121. else
  122. return _JetTM.IsLLBSlitDoorOpen;
  123. }
  124. private bool IsSlitDoorClosed()
  125. {
  126. if (_targetModule == ModuleName.LLA)
  127. return _JetTM.IsLLASlitDoorClosed;
  128. else
  129. return _JetTM.IsLLBSlitDoorClosed;
  130. }
  131. private bool VerifyWaferExistence(MoveItem item)
  132. {
  133. if (WaferManager.Instance.CheckHasWafer(item.DestinationModule, item.DestinationSlot))
  134. {
  135. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as desitination {_currentAction.DestinationModule},{_currentAction.DestinationSlot + 1} already a wafer: ");
  136. return false;
  137. }
  138. if (WaferManager.Instance.CheckNoWafer(_currentAction.SourceModule, _currentAction.SourceSlot))
  139. {
  140. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as source {_currentAction.SourceModule}, {_currentAction.SourceSlot + 1} has no wafer");
  141. return false;
  142. }
  143. return true;
  144. }
  145. private bool MoveWafer()
  146. {
  147. _currentAction = _actionList.Dequeue();
  148. if (!VerifyWaferExistence(_currentAction))
  149. return false;
  150. var wafer = WaferManager.Instance.GetWafer(_currentAction.SourceModule, _currentAction.SourceSlot);
  151. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from {_currentAction.SourceModule} {_currentAction.SourceSlot + 1} to {_currentAction.DestinationModule} {_currentAction.DestinationSlot + 1}");
  152. if (ModuleHelper.IsLoadLock(_currentAction.SourceModule) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
  153. {
  154. return _robot.Pick(_currentAction.SourceModule, _currentAction.SourceSlot, (Hand)_currentAction.DestinationSlot);
  155. }
  156. else if(ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsLoadLock(_currentAction.DestinationModule))
  157. {
  158. return _robot.Place(_currentAction.DestinationModule, _currentAction.DestinationSlot, (Hand)_currentAction.SourceSlot);
  159. }
  160. else
  161. {
  162. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TMRobot, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");
  163. return false;
  164. }
  165. }
  166. private bool WaitWaferMoved()
  167. {
  168. if (_robot.Status == RState.Running)
  169. {
  170. return false;
  171. }
  172. else if (_robot.Status == RState.End)
  173. {
  174. WaferManager.Instance.WaferMoved(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  175. return true;
  176. }
  177. else
  178. {
  179. Runner.Stop($"TM Robot moving wafer failed, {_robot.Status}");
  180. return true;
  181. }
  182. }
  183. private bool RotateArm()
  184. {
  185. ModuleName preModule = _targetModule;
  186. Hand rotateHand = Hand.Blade1;
  187. if (ModuleHelper.IsLoadLock(_actionList.Peek().DestinationModule) && ModuleHelper.IsTMRobot(_actionList.Peek().SourceModule))
  188. {
  189. rotateHand = (Hand)_actionList.Peek().SourceSlot;
  190. preModule = _JetTM.PreRotateModules[_targetModule];
  191. }
  192. else
  193. {
  194. rotateHand = (Hand)_actionList.Peek().DestinationSlot;
  195. }
  196. _llModule.PostMsg(LLEntity.MSG.Prepare_TM); // Notify Loadlock to Serv pressure in advance for throughput enhancement
  197. return _robot.Goto(preModule, 0, rotateHand);
  198. }
  199. private bool WaitRotateDone()
  200. {
  201. if (_robot.Status == RState.Running)
  202. {
  203. return false;
  204. }
  205. else if (_robot.Status == RState.End)
  206. {
  207. return true;
  208. }
  209. else
  210. {
  211. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  212. return true;
  213. }
  214. }
  215. private bool NotifyLLDone()
  216. {
  217. bool bAutoVent = false;
  218. var waferStatus = _llModule.GetWaferProcessStatus();
  219. if(_bAutoMode)
  220. {
  221. if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLA) ||
  222. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLB)) &&
  223. waferStatus.unprocessed <= _autoVentOptInWafer)
  224. {
  225. bAutoVent = true;
  226. }
  227. else if (((_sequencePattern == SequenceLLInOutPath.AInBOut && _targetModule == ModuleName.LLB) ||
  228. (_sequencePattern == SequenceLLInOutPath.BInAOut && _targetModule == ModuleName.LLA)) &&
  229. waferStatus.processed >= _autoVentOptOutWafer)
  230. {
  231. bAutoVent = true;
  232. }
  233. else if(_sequencePattern == SequenceLLInOutPath.DInDOut &&
  234. waferStatus.processed >= _autoVentOptOutWafer &&
  235. waferStatus.unprocessed <= _autoVentOptInWafer)
  236. {
  237. bAutoVent = true;
  238. }
  239. }
  240. LOG.Write(eEvent.INFO_TM, Module, $"NotifyLLDone() => {_targetModule}, Sequence Pattern{_sequencePattern}, unprocessed wafer:{waferStatus.unprocessed}, processed wafer: {waferStatus.processed},bAutoVent = {bAutoVent}, Config Option:{_autoVentOptInWafer},{_autoVentOptOutWafer}");
  241. _llModule.PostMsg(bAutoVent ? LLEntity.MSG.AutoVent : LLEntity.MSG.TM_Exchange_Ready);
  242. return true;
  243. }
  244. public void Abort()
  245. {
  246. _robot.Halt();
  247. }
  248. }
  249. }