MFPMSwapRoutine.cs 7.7 KB

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