MFSwapRoutine.cs 7.5 KB

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