MFPMSwapRoutine.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. using Aitex.Core.RT.Routine;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Sorter.Common;
  4. using Venus_RT.Devices;
  5. using Aitex.Core.Common;
  6. using MECF.Framework.Common.Routine;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.SubstrateTrackings;
  9. using Venus_Core;
  10. using Aitex.Core.RT.Log;
  11. using Aitex.Core.Util;
  12. using Venus_RT.Modules.PMs;
  13. using MECF.Framework.Common.Schedulers;
  14. using System.Collections.Generic;
  15. namespace Venus_RT.Modules.TM
  16. {
  17. class MFPMSwapRoutine : ModuleRoutineBase, IRoutine
  18. {
  19. private enum SwapStep
  20. {
  21. WaitPMReady,
  22. PreRotation,
  23. OpenSlitDoor,
  24. PickPrepare,
  25. PickExtend,
  26. DropDownWafer,
  27. PickDelay,
  28. PickRetract,
  29. PlacePrepare,
  30. PlaceExtend,
  31. LiftUpWafer,
  32. PlaceDelay,
  33. PlaceRetract,
  34. CloseSlitDoor,
  35. NotifyDone,
  36. }
  37. private enum SwapWithHeaterStep
  38. {
  39. WaitPMReady,
  40. PreRotation,
  41. OpenSlitDoor,
  42. PickPrepare,
  43. Picking,
  44. PlacePrepare,
  45. Placing,
  46. CloseSlitDoor,
  47. NotifyDone,
  48. }
  49. private readonly JetTM _JetTM;
  50. private readonly ITransferRobot _robot;
  51. private int _swapingTimeout = 120 * 1000;
  52. private int _placeDelayTime = 0;
  53. private int _pickDelayTime = 0;
  54. private ModuleName _targetModule;
  55. private PMEntity _pmModule;
  56. private int _targetSlot;
  57. private Hand _pickHand;
  58. private Hand _placeHand;
  59. public MFPMSwapRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  60. {
  61. _JetTM = tm;
  62. _robot = robot;
  63. Name = "Swap with PM";
  64. }
  65. public RState Start(params object[] objs)
  66. {
  67. if (!_robot.IsHomed)
  68. {
  69. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  70. return RState.Failed;
  71. }
  72. var swapItem = (Queue<MoveItem>)objs[0];
  73. if (!WaferManager.Instance.CheckDuplicatedWafersBeforeMove(swapItem))
  74. return RState.Failed;
  75. _targetModule = swapItem.Peek().SourceModule;
  76. _targetSlot = swapItem.Peek().SourceSlot;
  77. _pickHand = swapItem.Peek().RobotHand;
  78. _placeHand = _pickHand == Hand.Blade2 ? Hand.Blade1 : Hand.Blade2;
  79. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  80. {
  81. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  82. }
  83. else
  84. {
  85. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for swap action");
  86. return RState.Failed;
  87. }
  88. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_placeHand))
  89. {
  90. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as TM Robot Arm: {_placeHand} has no wafer");
  91. return RState.Failed;
  92. }
  93. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_pickHand))
  94. {
  95. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as TM Robot Arm: {_pickHand} has a wafer");
  96. return RState.Failed;
  97. }
  98. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  99. {
  100. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as {_targetModule} Slot {_targetSlot + 1} has no wafer");
  101. return RState.Failed;
  102. }
  103. var wafer = WaferManager.Instance.GetWafer(_targetModule, _targetSlot);
  104. if (wafer.ChuckState == EnumWaferChuckStatus.Chucked)
  105. {
  106. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick the wafer in {_targetModule} as the wafer is chucked");
  107. return RState.Failed;
  108. }
  109. Reset();
  110. _swapingTimeout = SC.GetValue<int>($"TM.SwapTimeout") * 1000;
  111. _pickDelayTime = SC.GetValue<int>($"{_targetModule}.PickDelayTime");
  112. _placeDelayTime = SC.GetValue<int>($"{_targetModule}.PlaceDelayTime");
  113. return Runner.Start(Module, $"Swap with {_targetModule}");
  114. }
  115. public RState Monitor()
  116. {
  117. //Runner.Wait(SwapStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  118. // .RunIf(SwapStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  119. // .Run(SwapStep.PickPrepare, PickPrepare, IsModuleReadyForPick)
  120. // .Run(SwapStep.PickExtend, PickExtend, WaitRobotExtendDone)
  121. // .Run(SwapStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
  122. // .Delay(SwapStep.PickDelay, _pickDelayTime)
  123. // .Run(SwapStep.PickRetract, PickRetract, WaitRobotRetractDone)
  124. // .Run(SwapStep.PlacePrepare, PlacePrepare, IsModuleReadyForPlace)
  125. // .Run(SwapStep.PlaceExtend, PlaceExtend, WaitRobotExtendDone)
  126. // .Run(SwapStep.LiftUpWafer, NotifyLiftUpWafer, WaitPMWaferLiftUp)
  127. // .Delay(SwapStep.PlaceDelay, _placeDelayTime)
  128. // .Run(SwapStep.PlaceRetract, PlaceRetract, WaitRobotRetractDone)
  129. // .End(SwapStep.NotifyDone, NotifyPMDone, _delay_50ms);
  130. switch (_pmModule.ChamberType)
  131. {
  132. //case JetChamber.Venus:
  133. case JetChamber.Kepler2300:
  134. Runner.Wait(SwapStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  135. .RunIf(SwapStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  136. .Run(SwapStep.OpenSlitDoor, OpenPMSlitDoor, OpenPMSlitDoorIsOK)
  137. .Run(SwapStep.PickPrepare, PickPrepare, IsModuleReadyForPick)
  138. .Run(SwapStep.PickExtend, PickExtend, WaitRobotExtendDone)
  139. .Run(SwapStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
  140. .Delay(SwapStep.PickDelay, _pickDelayTime)
  141. .Run(SwapStep.PickRetract, PickRetract, WaitRobotRetractDone)
  142. .Run(SwapStep.PlacePrepare, PlacePrepare, IsModuleReadyForPlace)
  143. .Run(SwapStep.PlaceExtend, PlaceExtend, WaitRobotExtendDone)
  144. .Run(SwapStep.LiftUpWafer, NotifyLiftUpWafer, WaitPMWaferLiftUp)
  145. .Delay(SwapStep.PlaceDelay, _placeDelayTime)
  146. .Run(SwapStep.PlaceRetract, PlaceRetract, WaitRobotRetractDone)
  147. .Run(SwapStep.CloseSlitDoor, ClosePMSlitDoor, ClosePMSlitDoorIsOK)
  148. .End(SwapStep.NotifyDone, NotifyPMDone, _delay_50ms);
  149. break;
  150. case JetChamber.Kepler2200A:
  151. case JetChamber.Kepler2200B:
  152. Runner.Wait(SwapWithHeaterStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  153. .RunIf(SwapWithHeaterStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  154. .Run(SwapWithHeaterStep.OpenSlitDoor, OpenPMSlitDoor, OpenPMSlitDoorIsOK)
  155. .Run(SwapWithHeaterStep.PickPrepare, PickPrepare, IsModuleReadyForPick)
  156. .Run(SwapWithHeaterStep.Picking, Picking, WaitPickDone)
  157. .Run(SwapWithHeaterStep.PlacePrepare, PlacePrepare, IsModuleReadyForPlace)
  158. .Run(SwapWithHeaterStep.Placing, Placing, WaitPlaceDone)
  159. .Run(SwapWithHeaterStep.CloseSlitDoor, ClosePMSlitDoor, ClosePMSlitDoorIsOK)
  160. .End(SwapStep.NotifyDone, NotifyPMDone, _delay_50ms);
  161. break;
  162. }
  163. return Runner.Status;
  164. }
  165. private bool PickPrepare()
  166. {
  167. _pmModule.PostMsg(PMEntity.MSG.PreparePick);
  168. return true;
  169. }
  170. private bool OpenPMSlitDoor()
  171. {
  172. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  173. }
  174. private bool OpenPMSlitDoorIsOK()
  175. {
  176. return _JetTM.IsPMSlitdoorOpened(_targetModule);
  177. }
  178. private bool ClosePMSlitDoor()
  179. {
  180. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  181. }
  182. private bool ClosePMSlitDoorIsOK()
  183. {
  184. return _JetTM.IsPMSlitdoorClosed(_targetModule);
  185. }
  186. private bool IsModuleReadyForPick()
  187. {
  188. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick && _pmModule.IsSlitDoorOpen;
  189. //return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick;
  190. }
  191. private bool PickExtend()
  192. {
  193. return _robot.PickExtend(_targetModule, _targetSlot, _pickHand);
  194. }
  195. private bool PickRetract()
  196. {
  197. return _robot.PickRetract(_targetModule, _targetSlot, _pickHand);
  198. }
  199. private bool PlacePrepare()
  200. {
  201. _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
  202. return true;
  203. }
  204. private bool IsModuleReadyForPlace()
  205. {
  206. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
  207. //return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place;
  208. }
  209. private bool PlaceExtend()
  210. {
  211. return _robot.PlaceExtend(_targetModule, _targetSlot, _placeHand);
  212. }
  213. private bool PlaceRetract()
  214. {
  215. return _robot.PlaceRetract(_targetModule, _targetSlot, _placeHand);
  216. }
  217. private bool WaitRobotExtendDone()
  218. {
  219. if (_robot.Status == RState.Running)
  220. {
  221. return false;
  222. }
  223. else if (_robot.Status == RState.End)
  224. {
  225. return true;
  226. }
  227. else
  228. {
  229. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  230. return true;
  231. }
  232. }
  233. private bool Picking()
  234. {
  235. return _robot.Pick(_targetModule, _targetSlot, _pickHand);
  236. }
  237. private bool WaitPickDone()
  238. {
  239. if (_robot.Status == RState.Running)
  240. {
  241. return false;
  242. }
  243. else if (_robot.Status == RState.End)
  244. {
  245. //WaferManager.Instance.WaferMoved(ModuleName.TM, (int)_hand, _targetModule, _targetSlot);
  246. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  247. return true;
  248. }
  249. else
  250. {
  251. Runner.Stop($"TM Robot Picking failed, {_robot.Status}");
  252. return true;
  253. }
  254. }
  255. private bool Placing()
  256. {
  257. return _robot.Place(_targetModule, _targetSlot, _placeHand);
  258. }
  259. private bool WaitPlaceDone()
  260. {
  261. if (_robot.Status == RState.Running)
  262. {
  263. return false;
  264. }
  265. else if (_robot.Status == RState.End)
  266. {
  267. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  268. return true;
  269. }
  270. else
  271. {
  272. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  273. return true;
  274. }
  275. }
  276. private bool RotateArm()
  277. {
  278. _pmModule.PostMsg(PMEntity.MSG.PreparePick); // Notify PM to Serv pressure in advance for throughput enhancement
  279. return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _placeHand);
  280. }
  281. private bool WaitRotateDone()
  282. {
  283. if (_robot.Status == RState.Running)
  284. {
  285. return false;
  286. }
  287. else if (_robot.Status == RState.End)
  288. {
  289. return true;
  290. }
  291. else
  292. {
  293. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  294. return true;
  295. }
  296. }
  297. private bool NotifyPMPickWafer()
  298. {
  299. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  300. return true;
  301. }
  302. private bool WaitPMWaferDropDown()
  303. {
  304. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  305. {
  306. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  307. return true;
  308. }
  309. return false;
  310. }
  311. private bool WaitRobotRetractDone()
  312. {
  313. if (_robot.Status == RState.Running)
  314. {
  315. return false;
  316. }
  317. else if (_robot.Status == RState.End)
  318. {
  319. return true;
  320. }
  321. else
  322. {
  323. Runner.Stop($"TM Robot Swap Retract failed, {_robot.Status}");
  324. return true;
  325. }
  326. }
  327. private bool NotifyLiftUpWafer()
  328. {
  329. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  330. return true;
  331. }
  332. private bool WaitPMWaferLiftUp()
  333. {
  334. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  335. {
  336. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  337. return true;
  338. }
  339. return false;
  340. }
  341. private bool NotifyPMDone()
  342. {
  343. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  344. return true;
  345. }
  346. public void Abort()
  347. {
  348. _robot.Halt();
  349. }
  350. }
  351. }