MFPMSwapRoutine.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. .Run(SwapWithHeaterStep.PickPrepare, PickPrepare, IsModuleReadyForPick)
  160. .Wait(SwapWithHeaterStep.WaitPressreStable, TMPMPressureIsOK, _delay_60s)
  161. .Run(SwapWithHeaterStep.OpenSlitDoor, OpenPMSlitDoor, OpenPMSlitDoorIsOK)
  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-2))
  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;
  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;
  231. }
  232. private bool PlaceExtend()
  233. {
  234. return _robot.PlaceExtend(_targetModule, _targetSlot, _placeHand);
  235. }
  236. private bool PlaceRetract()
  237. {
  238. return _robot.PlaceRetract(_targetModule, _targetSlot, _placeHand);
  239. }
  240. private bool WaitRobotExtendDone()
  241. {
  242. if (_robot.Status == RState.Running)
  243. {
  244. return false;
  245. }
  246. else if (_robot.Status == RState.End)
  247. {
  248. return true;
  249. }
  250. else
  251. {
  252. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  253. return true;
  254. }
  255. }
  256. private bool Picking()
  257. {
  258. return _robot.Pick(_targetModule, _targetSlot, _pickHand);
  259. }
  260. private bool WaitPickDone()
  261. {
  262. if (_robot.Status == RState.Running)
  263. {
  264. return false;
  265. }
  266. else if (_robot.Status == RState.End)
  267. {
  268. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  269. return true;
  270. }
  271. else
  272. {
  273. WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  274. Runner.Stop($"TM Robot Picking failed, {_robot.Status}");
  275. return true;
  276. }
  277. }
  278. private bool Placing()
  279. {
  280. return _robot.Place(_targetModule, _targetSlot, _placeHand);
  281. }
  282. private bool WaitPlaceDone()
  283. {
  284. if (_robot.Status == RState.Running)
  285. {
  286. return false;
  287. }
  288. else if (_robot.Status == RState.End)
  289. {
  290. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  291. return true;
  292. }
  293. else
  294. {
  295. WaferManager.Instance.CreateDuplicatedWafer(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  296. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  297. return true;
  298. }
  299. }
  300. private bool RotateArm()
  301. {
  302. _pmModule.PostMsg(PMEntity.MSG.PreparePick); // Notify PM to Serv pressure in advance for throughput enhancement
  303. return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _placeHand);
  304. }
  305. private bool WaitRotateDone()
  306. {
  307. if (_robot.Status == RState.Running)
  308. {
  309. return false;
  310. }
  311. else if (_robot.Status == RState.End)
  312. {
  313. return true;
  314. }
  315. else
  316. {
  317. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  318. return true;
  319. }
  320. }
  321. private bool NotifyPMPickWafer()
  322. {
  323. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  324. return true;
  325. }
  326. private bool WaitPMWaferDropDown()
  327. {
  328. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  329. {
  330. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  331. return true;
  332. }
  333. else if (Runner.StepElapsedMS > _liftPinTimeout)
  334. {
  335. WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  336. Runner.Stop($"Wait {_targetModule} Lift Pin down timeout, {Runner.StepElapsedMS}");
  337. }
  338. return false;
  339. }
  340. private bool WaitRobotRetractDone()
  341. {
  342. if (_robot.Status == RState.Running)
  343. {
  344. return false;
  345. }
  346. else if (_robot.Status == RState.End)
  347. {
  348. return true;
  349. }
  350. else
  351. {
  352. Runner.Stop($"TM Robot Swap Retract failed, {_robot.Status}");
  353. return true;
  354. }
  355. }
  356. private bool NotifyLiftUpWafer()
  357. {
  358. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  359. return true;
  360. }
  361. private bool WaitPMWaferLiftUp()
  362. {
  363. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  364. {
  365. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  366. return true;
  367. }
  368. else if (Runner.StepElapsedMS > _liftPinTimeout)
  369. {
  370. WaferManager.Instance.CreateDuplicatedWafer(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  371. Runner.Stop($"Wait {_targetModule} Lift Pin Up timeout, {Runner.StepElapsedMS}");
  372. }
  373. return false;
  374. }
  375. private bool NotifyPMDone()
  376. {
  377. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  378. return true;
  379. }
  380. public void Abort()
  381. {
  382. //_robot.Halt();
  383. }
  384. }
  385. }