MFSwapRoutine.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. Queue<MoveItem> _actionList = new Queue<MoveItem>();
  36. MoveItem _currentAction;
  37. public MFSwapRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  38. {
  39. _JetTM = tm;
  40. _robot = robot;
  41. Name = "Swap";
  42. }
  43. public RState Start(params object[] objs)
  44. {
  45. if (!_robot.IsHomed)
  46. {
  47. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot 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_TM, 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_TM, Module, $"Invalid Loadlock: {_targetModule}, maybe not installed");
  69. return RState.Failed;
  70. }
  71. Reset();
  72. _swapTimeout = SC.GetValue<int>($"TM.SwapTimeout") * 1000;
  73. return Runner.Start(Module, $"Swap with {_targetModule}");
  74. }
  75. public RState Monitor()
  76. {
  77. Runner.Wait(SwapStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  78. .RunIf(SwapStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  79. .Run(SwapStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  80. .Run(SwapStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen)
  81. .LoopStart(SwapStep.MoveWafer, loopName(), _actionList.Count, MoveWafer)
  82. .LoopEnd(SwapStep.WaitMaferMoved, NullFun, WaitWaferMoved)
  83. .Run(SwapStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed)
  84. .End(SwapStep.NotifyDone, NotifyLLDone, _delay_50ms);
  85. return Runner.Status;
  86. }
  87. private bool ModulePrepare()
  88. {
  89. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  90. return true;
  91. }
  92. private string loopName()
  93. {
  94. return "LoadLock Swap" ;
  95. }
  96. private bool IsModulePrepareReady()
  97. {
  98. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  99. }
  100. private bool OpenSlitDoor()
  101. {
  102. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  103. }
  104. private bool CloseSlitDoor()
  105. {
  106. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  107. }
  108. private bool IsSlitDoorOpen()
  109. {
  110. if (_targetModule == ModuleName.LLA)
  111. return _JetTM.IsLLASlitDoorOpen;
  112. else
  113. return _JetTM.IsLLBSlitDoorOpen;
  114. }
  115. private bool IsSlitDoorClosed()
  116. {
  117. if (_targetModule == ModuleName.LLA)
  118. return _JetTM.IsLLASlitDoorClosed;
  119. else
  120. return _JetTM.IsLLBSlitDoorClosed;
  121. }
  122. private bool VerifyWaferExistence(MoveItem item)
  123. {
  124. if (WaferManager.Instance.CheckHasWafer(item.DestinationModule, item.DestinationSlot))
  125. {
  126. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as desitination {_currentAction.DestinationModule},{_currentAction.DestinationSlot + 1} already a wafer: ");
  127. return false;
  128. }
  129. if (WaferManager.Instance.CheckNoWafer(_currentAction.SourceModule, _currentAction.SourceSlot))
  130. {
  131. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as source {_currentAction.SourceModule}, {_currentAction.SourceSlot + 1} has no wafer");
  132. return false;
  133. }
  134. return true;
  135. }
  136. private bool MoveWafer()
  137. {
  138. _currentAction = _actionList.Dequeue();
  139. if (!VerifyWaferExistence(_currentAction))
  140. return false;
  141. var wafer = WaferManager.Instance.GetWafer(_currentAction.SourceModule, _currentAction.SourceSlot);
  142. 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}");
  143. if (ModuleHelper.IsLoadLock(_currentAction.SourceModule) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
  144. {
  145. return _robot.Pick(_currentAction.SourceModule, _currentAction.SourceSlot, (Hand)_currentAction.DestinationSlot);
  146. }
  147. else if(ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsLoadLock(_currentAction.DestinationModule))
  148. {
  149. return _robot.Place(_currentAction.DestinationModule, _currentAction.DestinationSlot, (Hand)_currentAction.SourceSlot);
  150. }
  151. else
  152. {
  153. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TMRobot, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");
  154. return false;
  155. }
  156. }
  157. private bool WaitWaferMoved()
  158. {
  159. if (_robot.Status == RState.Running)
  160. {
  161. return false;
  162. }
  163. else if (_robot.Status == RState.End)
  164. {
  165. WaferManager.Instance.WaferMoved(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  166. return true;
  167. }
  168. else
  169. {
  170. Runner.Stop($"TM Robot moving wafer failed, {_robot.Status}");
  171. return true;
  172. }
  173. }
  174. private bool RotateArm()
  175. {
  176. ModuleName preModule = _targetModule;
  177. Hand rotateHand = Hand.Blade1;
  178. if (ModuleHelper.IsLoadLock(_actionList.Peek().DestinationModule) && ModuleHelper.IsTMRobot(_actionList.Peek().SourceModule))
  179. {
  180. rotateHand = (Hand)_actionList.Peek().SourceSlot;
  181. preModule = _JetTM.PreRotateModules[_targetModule];
  182. }
  183. else
  184. {
  185. rotateHand = (Hand)_actionList.Peek().DestinationSlot;
  186. }
  187. _llModule.PostMsg(LLEntity.MSG.Prepare_TM); // Notify Loadlock to Serv pressure in advance for throughput enhancement
  188. return _robot.Goto(preModule, 0, rotateHand);
  189. }
  190. private bool WaitRotateDone()
  191. {
  192. if (_robot.Status == RState.Running)
  193. {
  194. return false;
  195. }
  196. else if (_robot.Status == RState.End)
  197. {
  198. return true;
  199. }
  200. else
  201. {
  202. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  203. return true;
  204. }
  205. }
  206. private bool NotifyLLDone()
  207. {
  208. _llModule.PostMsg(LLEntity.MSG.TM_Exchange_Ready);
  209. return true;
  210. }
  211. public void Abort()
  212. {
  213. _robot.Halt();
  214. }
  215. }
  216. }