MFSwapRoutine.cs 7.3 KB

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