MFSwapRoutine.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. ModulePrepare,
  23. OpenSlitDoor,
  24. MoveWafer,
  25. WaitMaferMoved,
  26. CloseSlitDoor,
  27. NotifyDone,
  28. }
  29. private readonly JetTM _JetTM;
  30. private readonly ITransferRobot _robot;
  31. private int _swapTimeout = 120 * 1000;
  32. private ModuleName _targetModule;
  33. private LLEntity _llModule;
  34. Queue<MoveItem> _actionList = new Queue<MoveItem>();
  35. MoveItem _currentAction;
  36. public MFSwapRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  37. {
  38. _JetTM = tm;
  39. _robot = robot;
  40. Name = "Swap";
  41. }
  42. public RState Start(params object[] objs)
  43. {
  44. if (!_robot.IsHomed)
  45. {
  46. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  47. return RState.Failed;
  48. }
  49. _actionList.Clear();
  50. foreach(var item in (Queue<MoveItem>)objs[0])
  51. {
  52. _actionList.Enqueue(new MoveItem(item.SourceModule, item.SourceSlot, item.DestinationModule, item.DestinationSlot, item.RobotHand));
  53. }
  54. var firtItem = _actionList.Peek();
  55. if (ModuleHelper.IsLoadLock(firtItem.SourceModule))
  56. _targetModule = firtItem.SourceModule;
  57. else if (ModuleHelper.IsLoadLock(firtItem.DestinationModule))
  58. _targetModule = firtItem.DestinationModule;
  59. else
  60. {
  61. LOG.Write(eEvent.ERR_TM, Module, $"Invalid move parameter: {firtItem.SourceModule},{firtItem.SourceSlot + 1} => {firtItem.DestinationModule},{firtItem.DestinationSlot + 1} ");
  62. return RState.Failed;
  63. }
  64. _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);
  65. if(_llModule == null)
  66. {
  67. LOG.Write(eEvent.ERR_TM, Module, $"Invalid Loadlock: {_targetModule}, maybe not installed");
  68. return RState.Failed;
  69. }
  70. Reset();
  71. _swapTimeout = SC.GetValue<int>($"TM.SwapTimeout") * 1000;
  72. return Runner.Start(Module, $"Swap with {_targetModule}");
  73. }
  74. public RState Monitor()
  75. {
  76. Runner.Wait((int)SwapStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  77. .Run((int)SwapStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  78. .Run((int)SwapStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen)
  79. .LoopStart((int)SwapStep.MoveWafer, loopName(), _actionList.Count, MoveWafer)
  80. .LoopEnd((int)SwapStep.WaitMaferMoved, NullFun, WaitWaferMoved)
  81. .Run((int)SwapStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed)
  82. .End((int)SwapStep.NotifyDone, NotifyLLDone, _delay_50ms);
  83. return Runner.Status;
  84. }
  85. private bool ModulePrepare()
  86. {
  87. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  88. return true;
  89. }
  90. private string loopName()
  91. {
  92. return "LoadLock Swap" ;
  93. }
  94. private bool IsModulePrepareReady()
  95. {
  96. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  97. }
  98. private bool OpenSlitDoor()
  99. {
  100. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  101. }
  102. private bool CloseSlitDoor()
  103. {
  104. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  105. }
  106. private bool IsSlitDoorOpen()
  107. {
  108. if (_targetModule == ModuleName.LLA)
  109. return _JetTM.IsLLASlitDoorOpen;
  110. else
  111. return _JetTM.IsLLBSlitDoorOpen;
  112. }
  113. private bool IsSlitDoorClosed()
  114. {
  115. if (_targetModule == ModuleName.LLA)
  116. return _JetTM.IsLLASlitDoorClosed;
  117. else
  118. return _JetTM.IsLLBSlitDoorClosed;
  119. }
  120. private bool VerifyWaferExistence(MoveItem item)
  121. {
  122. if (WaferManager.Instance.CheckHasWafer(item.DestinationModule, item.DestinationSlot))
  123. {
  124. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as desitination {_currentAction.DestinationModule},{_currentAction.DestinationSlot + 1} already a wafer: ");
  125. return false;
  126. }
  127. if (WaferManager.Instance.CheckNoWafer(_currentAction.SourceModule, _currentAction.SourceSlot))
  128. {
  129. LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as source {_currentAction.SourceModule}, {_currentAction.SourceSlot + 1} has no wafer");
  130. return false;
  131. }
  132. return true;
  133. }
  134. private bool MoveWafer()
  135. {
  136. _currentAction = _actionList.Dequeue();
  137. if (!VerifyWaferExistence(_currentAction))
  138. return false;
  139. var wafer = WaferManager.Instance.GetWafer(_currentAction.SourceModule, _currentAction.SourceSlot);
  140. 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}");
  141. if (ModuleHelper.IsLoadLock(_currentAction.SourceModule) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
  142. {
  143. return _robot.Pick(_currentAction.SourceModule, _currentAction.SourceSlot, (Hand)_currentAction.DestinationSlot);
  144. }
  145. else if(ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsLoadLock(_currentAction.DestinationModule))
  146. {
  147. return _robot.Place(_currentAction.DestinationModule, _currentAction.DestinationSlot, (Hand)_currentAction.SourceSlot);
  148. }
  149. else
  150. {
  151. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TMRobot, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");
  152. return false;
  153. }
  154. }
  155. private bool WaitWaferMoved()
  156. {
  157. if (_robot.Status == RState.Running)
  158. {
  159. return false;
  160. }
  161. else if (_robot.Status == RState.End)
  162. {
  163. WaferManager.Instance.WaferMoved(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  164. return true;
  165. }
  166. else
  167. {
  168. Runner.Stop($"TM Robot moving wafer failed, {_robot.Status}");
  169. return true;
  170. }
  171. }
  172. private bool NotifyLLDone()
  173. {
  174. _llModule.PostMsg(LLEntity.MSG.TM_Exchange_Ready);
  175. return true;
  176. }
  177. public void Abort()
  178. {
  179. _robot.Halt();
  180. }
  181. }
  182. }