MFPMSwapRoutine.cs 17 KB

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