MFPMSwapRoutine.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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(SwapStep.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)
  185. {
  186. return true;
  187. }
  188. else
  189. {
  190. return false;
  191. }
  192. }
  193. }
  194. private bool OpenPMSlitDoor()
  195. {
  196. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  197. }
  198. private bool OpenPMSlitDoorIsOK()
  199. {
  200. return _JetTM.IsPMSlitdoorOpened(_targetModule);
  201. }
  202. private bool ClosePMSlitDoor()
  203. {
  204. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  205. }
  206. private bool ClosePMSlitDoorIsOK()
  207. {
  208. return _JetTM.IsPMSlitdoorClosed(_targetModule);
  209. }
  210. private bool IsModuleReadyForPick()
  211. {
  212. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick && _pmModule.IsSlitDoorOpen;
  213. //return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick;
  214. }
  215. private bool PickExtend()
  216. {
  217. return _robot.PickExtend(_targetModule, _targetSlot, _pickHand);
  218. }
  219. private bool PickRetract()
  220. {
  221. return _robot.PickRetract(_targetModule, _targetSlot, _pickHand);
  222. }
  223. private bool PlacePrepare()
  224. {
  225. _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
  226. return true;
  227. }
  228. private bool IsModuleReadyForPlace()
  229. {
  230. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
  231. //return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place;
  232. }
  233. private bool PlaceExtend()
  234. {
  235. return _robot.PlaceExtend(_targetModule, _targetSlot, _placeHand);
  236. }
  237. private bool PlaceRetract()
  238. {
  239. return _robot.PlaceRetract(_targetModule, _targetSlot, _placeHand);
  240. }
  241. private bool WaitRobotExtendDone()
  242. {
  243. if (_robot.Status == RState.Running)
  244. {
  245. return false;
  246. }
  247. else if (_robot.Status == RState.End)
  248. {
  249. return true;
  250. }
  251. else
  252. {
  253. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  254. return true;
  255. }
  256. }
  257. private bool Picking()
  258. {
  259. return _robot.Pick(_targetModule, _targetSlot, _pickHand);
  260. }
  261. private bool WaitPickDone()
  262. {
  263. if (_robot.Status == RState.Running)
  264. {
  265. return false;
  266. }
  267. else if (_robot.Status == RState.End)
  268. {
  269. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  270. return true;
  271. }
  272. else
  273. {
  274. WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  275. Runner.Stop($"TM Robot Picking failed, {_robot.Status}");
  276. return true;
  277. }
  278. }
  279. private bool Placing()
  280. {
  281. return _robot.Place(_targetModule, _targetSlot, _placeHand);
  282. }
  283. private bool WaitPlaceDone()
  284. {
  285. if (_robot.Status == RState.Running)
  286. {
  287. return false;
  288. }
  289. else if (_robot.Status == RState.End)
  290. {
  291. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  292. return true;
  293. }
  294. else
  295. {
  296. WaferManager.Instance.CreateDuplicatedWafer(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  297. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  298. return true;
  299. }
  300. }
  301. private bool RotateArm()
  302. {
  303. _pmModule.PostMsg(PMEntity.MSG.PreparePick); // Notify PM to Serv pressure in advance for throughput enhancement
  304. return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _placeHand);
  305. }
  306. private bool WaitRotateDone()
  307. {
  308. if (_robot.Status == RState.Running)
  309. {
  310. return false;
  311. }
  312. else if (_robot.Status == RState.End)
  313. {
  314. return true;
  315. }
  316. else
  317. {
  318. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  319. return true;
  320. }
  321. }
  322. private bool NotifyPMPickWafer()
  323. {
  324. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  325. return true;
  326. }
  327. private bool WaitPMWaferDropDown()
  328. {
  329. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  330. {
  331. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  332. return true;
  333. }
  334. else if (Runner.StepElapsedMS > _liftPinTimeout)
  335. {
  336. WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  337. Runner.Stop($"Wait {_targetModule} Lift Pin down timeout, {Runner.StepElapsedMS}");
  338. }
  339. return false;
  340. }
  341. private bool WaitRobotRetractDone()
  342. {
  343. if (_robot.Status == RState.Running)
  344. {
  345. return false;
  346. }
  347. else if (_robot.Status == RState.End)
  348. {
  349. return true;
  350. }
  351. else
  352. {
  353. Runner.Stop($"TM Robot Swap Retract failed, {_robot.Status}");
  354. return true;
  355. }
  356. }
  357. private bool NotifyLiftUpWafer()
  358. {
  359. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  360. return true;
  361. }
  362. private bool WaitPMWaferLiftUp()
  363. {
  364. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  365. {
  366. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  367. return true;
  368. }
  369. else if (Runner.StepElapsedMS > _liftPinTimeout)
  370. {
  371. WaferManager.Instance.CreateDuplicatedWafer(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  372. Runner.Stop($"Wait {_targetModule} Lift Pin Up timeout, {Runner.StepElapsedMS}");
  373. }
  374. return false;
  375. }
  376. private bool NotifyPMDone()
  377. {
  378. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  379. return true;
  380. }
  381. public void Abort()
  382. {
  383. _robot.Halt();
  384. }
  385. }
  386. }