MFPMSwapRoutine.cs 21 KB

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