MFPMSwapRoutine.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 Venus_RT.Modules.PMs;
  12. namespace Venus_RT.Modules.TM
  13. {
  14. class MFPMSwapRoutine : ModuleRoutineBase, IRoutine
  15. {
  16. private enum SwapStep
  17. {
  18. WaitPMReady,
  19. PickPrepare,
  20. PickExtend,
  21. DropDownWafer,
  22. PickRetract,
  23. PlacePrepare,
  24. PlaceExtend,
  25. LiftUpWafer,
  26. PlaceRetract,
  27. NotifyDone,
  28. }
  29. private readonly JetTM _JetTM;
  30. private readonly ITransferRobot _robot;
  31. private int _swapingTimeout = 120 * 1000;
  32. private ModuleName _targetModule;
  33. private PMEntity _pmModule;
  34. int _targetSlot;
  35. Hand _pickHand;
  36. Hand _placeHand;
  37. public MFPMSwapRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TM)
  38. {
  39. _JetTM = tm;
  40. _robot = robot;
  41. Name = "Swap with PM";
  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. _targetModule = (ModuleName)objs[0];
  51. _targetSlot = (int)objs[1];
  52. _pickHand = (Hand)objs[2];
  53. _placeHand = _pickHand == Hand.Blade2 ? Hand.Blade1 : Hand.Blade2;
  54. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  55. {
  56. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  57. }
  58. else
  59. {
  60. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for picking action");
  61. return RState.Failed;
  62. }
  63. if (WaferManager.Instance.CheckNoWafer(ModuleName.TM, (int)_placeHand))
  64. {
  65. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as TM Robot Arm: {_placeHand} has no wafer");
  66. return RState.Failed;
  67. }
  68. if (WaferManager.Instance.CheckHasWafer(ModuleName.TM, (int)_pickHand))
  69. {
  70. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as TM Robot Arm: {_pickHand} has a wafer");
  71. return RState.Failed;
  72. }
  73. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  74. {
  75. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as {_targetModule} Slot {_targetSlot} has no wafer");
  76. return RState.Failed;
  77. }
  78. Reset();
  79. _swapingTimeout = SC.GetValue<int>($"{Module}.SwapTimeout") * 1000;
  80. return Runner.Start(Module, Name);
  81. }
  82. public RState Monitor()
  83. {
  84. Runner.Wait((int)SwapStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  85. .Run((int)SwapStep.PickPrepare, PickPrepare, IsModuleReadyForPick)
  86. .Run((int)SwapStep.PickExtend, PickExtend, WaitRobotExtendDone)
  87. .Run((int)SwapStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
  88. .Run((int)SwapStep.PickRetract, PickRetract, WaitRobotRetractDone)
  89. .Run((int)SwapStep.PlacePrepare, PlacePrepare, IsModuleReadyForPlace)
  90. .Run((int)SwapStep.PlaceExtend, PlaceExtend, WaitRobotExtendDone)
  91. .Run((int)SwapStep.LiftUpWafer, NotifyLiftUpWafer, WaitPMWaferLiftUp)
  92. .Run((int)SwapStep.PlaceRetract, PlaceRetract, WaitRobotRetractDone)
  93. .End((int)SwapStep.NotifyDone, NotifyPMDone, _delay_50ms);
  94. return Runner.Status;
  95. }
  96. private bool PickPrepare()
  97. {
  98. _pmModule.PostMsg(PMEntity.MSG.PreparePick);
  99. return true;
  100. }
  101. private bool IsModuleReadyForPick()
  102. {
  103. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick && _pmModule.IsSlitDoorOpen;
  104. }
  105. private bool PickExtend()
  106. {
  107. return _robot.PickExtend(_targetModule, _targetSlot, _pickHand);
  108. }
  109. private bool PickRetract()
  110. {
  111. return _robot.PickRetract(_targetModule, _targetSlot, _pickHand);
  112. }
  113. private bool PlacePrepare()
  114. {
  115. _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
  116. return true;
  117. }
  118. private bool IsModuleReadyForPlace()
  119. {
  120. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
  121. }
  122. private bool PlaceExtend()
  123. {
  124. return _robot.PlaceExtend(_targetModule, _targetSlot, _placeHand);
  125. }
  126. private bool PlaceRetract()
  127. {
  128. return _robot.PlaceRetract(_targetModule, _targetSlot, _placeHand);
  129. }
  130. private bool WaitRobotExtendDone()
  131. {
  132. if (_robot.Status == RState.Running)
  133. {
  134. return false;
  135. }
  136. else if (_robot.Status == RState.End)
  137. {
  138. return true;
  139. }
  140. else
  141. {
  142. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  143. return true;
  144. }
  145. }
  146. private bool NotifyPMPickWafer()
  147. {
  148. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  149. return true;
  150. }
  151. private bool WaitPMWaferDropDown()
  152. {
  153. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  154. {
  155. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TM, (int)_pickHand);
  156. return true;
  157. }
  158. return false;
  159. }
  160. private bool WaitRobotRetractDone()
  161. {
  162. if (_robot.Status == RState.Running)
  163. {
  164. return false;
  165. }
  166. else if (_robot.Status == RState.End)
  167. {
  168. return true;
  169. }
  170. else
  171. {
  172. Runner.Stop($"TM Robot Swap Retract failed, {_robot.Status}");
  173. return true;
  174. }
  175. }
  176. private bool NotifyLiftUpWafer()
  177. {
  178. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  179. return true;
  180. }
  181. private bool WaitPMWaferLiftUp()
  182. {
  183. if(_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  184. {
  185. WaferManager.Instance.WaferMoved(ModuleName.TM, (int)_placeHand, _targetModule, _targetSlot);
  186. return true;
  187. }
  188. return false;
  189. }
  190. private bool NotifyPMDone()
  191. {
  192. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  193. return true;
  194. }
  195. public void Abort()
  196. {
  197. _robot.Halt();
  198. }
  199. }
  200. }