MFSwapRoutine.cs 9.5 KB

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