MFPMSwapRoutine.cs 8.8 KB

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