MFSwapRoutine.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. namespace Venus_RT.Modules.TM
  12. {
  13. class MFSwapRoutine : ModuleRoutineBase, IRoutine
  14. {
  15. private enum SwapStep
  16. {
  17. WaitModuleReady,
  18. ModulePrepare,
  19. OpenSlitDoor,
  20. Picking,
  21. Placing,
  22. CloseSlitDoor,
  23. NotifyDone,
  24. }
  25. private readonly JetTM _JetTM;
  26. private readonly ITransferRobot _robot;
  27. private int _swapTimeout = 120 * 1000;
  28. private ModuleName _targetModule;
  29. private LLEntity _llModule;
  30. int _pickSlot, _placeSlot;
  31. Hand _pickHand, _placeHand;
  32. public MFSwapRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TM)
  33. {
  34. _JetTM = tm;
  35. _robot = robot;
  36. Name = "Swap";
  37. }
  38. public RState Start(params object[] objs)
  39. {
  40. if (!_robot.IsHomed)
  41. {
  42. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  43. return RState.Failed;
  44. }
  45. _targetModule = (ModuleName)objs[0];
  46. _pickSlot = (int)objs[1];
  47. _placeSlot = (int)objs[2];
  48. _pickHand = (Hand)objs[3];
  49. _placeHand = _pickHand == Hand.Blade1 ? Hand.Blade2 : Hand.Blade1;
  50. if (ModuleHelper.IsLoadLock(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  51. {
  52. _llModule = _targetModule == ModuleName.LLA ? Singleton<RouteManager>.Instance.LLA : Singleton<RouteManager>.Instance.LLB;
  53. }
  54. else
  55. {
  56. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for picking action");
  57. return RState.Failed;
  58. }
  59. if (WaferManager.Instance.CheckHasWafer(ModuleName.TM, (int)_pickHand))
  60. {
  61. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as TM Robot Arm: {_pickHand} already has a wafer");
  62. return RState.Failed;
  63. }
  64. if (WaferManager.Instance.CheckNoWafer(_targetModule, _pickSlot))
  65. {
  66. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as {_targetModule} Slot {_pickSlot} has no wafer");
  67. return RState.Failed;
  68. }
  69. if (WaferManager.Instance.CheckNoWafer(ModuleName.TM, (int)_placeHand))
  70. {
  71. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as TM Robot Arm: {_placeHand} has no wafer");
  72. return RState.Failed;
  73. }
  74. if (WaferManager.Instance.CheckHasWafer(_targetModule, _placeSlot))
  75. {
  76. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as {_targetModule} Slot {_placeSlot} already has a wafer");
  77. return RState.Failed;
  78. }
  79. Reset();
  80. _swapTimeout = SC.GetValue<int>($"{Module}.SwapTimeout") * 1000;
  81. return Runner.Start(Module, Name);
  82. }
  83. public RState Monitor()
  84. {
  85. Runner.Wait((int)SwapStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  86. .Run((int)SwapStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  87. .Run((int)SwapStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen)
  88. .Run((int)SwapStep.Picking, Picking, WaitPickDone)
  89. .Run((int)SwapStep.Placing, Placing, WaitPlaceDone)
  90. .Run((int)SwapStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed)
  91. .End((int)SwapStep.NotifyDone, NotifyLLDone, _delay_50ms);
  92. return Runner.Status;
  93. }
  94. private bool ModulePrepare()
  95. {
  96. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  97. return true;
  98. }
  99. private bool IsModulePrepareReady()
  100. {
  101. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  102. }
  103. private bool OpenSlitDoor()
  104. {
  105. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  106. }
  107. private bool CloseSlitDoor()
  108. {
  109. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  110. }
  111. private bool IsSlitDoorOpen()
  112. {
  113. if (_targetModule == ModuleName.LLA)
  114. return _JetTM.IsLLASlitDoorOpen;
  115. else
  116. return _JetTM.IsLLBSlitDoorOpen;
  117. }
  118. private bool IsSlitDoorClosed()
  119. {
  120. if (_targetModule == ModuleName.LLA)
  121. return _JetTM.IsLLASlitDoorClosed;
  122. else
  123. return _JetTM.IsLLBSlitDoorClosed;
  124. }
  125. private bool Picking()
  126. {
  127. return _robot.Pick(_targetModule, _pickSlot, _pickHand);
  128. }
  129. private bool WaitPickDone()
  130. {
  131. if (_robot.Status == RState.Running)
  132. {
  133. return false;
  134. }
  135. else if (_robot.Status == RState.End)
  136. {
  137. return true;
  138. }
  139. else
  140. {
  141. Runner.Stop($"TM Robot Picking failed, {_robot.Status}");
  142. return true;
  143. }
  144. }
  145. private bool Placing()
  146. {
  147. return _robot.Place(_targetModule, _placeSlot, _placeHand);
  148. }
  149. private bool WaitPlaceDone()
  150. {
  151. if (_robot.Status == RState.Running)
  152. {
  153. return false;
  154. }
  155. else if (_robot.Status == RState.End)
  156. {
  157. return true;
  158. }
  159. else
  160. {
  161. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  162. return true;
  163. }
  164. }
  165. private bool NotifyLLDone()
  166. {
  167. _llModule.PostMsg(LLEntity.MSG.TM_Exchange_Ready);
  168. return true;
  169. }
  170. public void Abort()
  171. {
  172. _robot.Halt();
  173. }
  174. }
  175. }