MFPMSwapRoutine.cs 7.2 KB

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