MFPMSwapRoutine.cs 9.4 KB

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