MFPMSwapRoutine.cs 18 KB

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