MFPMSwapRoutine.cs 21 KB

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