ReturnAllWafer.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Aitex.Core.Common;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.Routine;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Sorter.Common;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.Schedulers;
  11. using MECF.Framework.Common.SubstrateTrackings;
  12. using MECF.Framework.RT.ModuleLibrary.SystemModules;
  13. using EfemDualSchedulerLib.Schedulers;
  14. namespace EfemDualSchedulerLib
  15. {
  16. public class ReturnAllWafer : SchedulerModuleFactory, IRoutine
  17. {
  18. Dictionary<ModuleName, int> _checkPosition = new Dictionary<ModuleName, int>()
  19. {
  20. {ModuleName.EfemRobot, 2},
  21. {ModuleName.Aligner, 1},
  22. {ModuleName.LLA, 8},
  23. {ModuleName.LLB, 8},
  24. {ModuleName.TMRobot, 2},
  25. {ModuleName.PMA, 2},
  26. {ModuleName.PMB, 2},
  27. };
  28. private List<SchedulerPM> _lstPms = new List<SchedulerPM>();
  29. private List<SchedulerLoadPort> _lstLps = new List<SchedulerLoadPort>();
  30. private List<SchedulerLoadLock> _lstLls = new List<SchedulerLoadLock>();
  31. Queue<Action> tmRobotActions = new Queue<Action>() { };
  32. public ReturnAllWafer(EquipmentManager equipment) : base()
  33. {
  34. if (SC.GetValueOrDefault<bool>("System.SetUp.PMA.IsInstalled"))
  35. _lstPms.Add(_pm1);
  36. if (SC.GetValueOrDefault<bool>("System.SetUp.PMB.IsInstalled"))
  37. _lstPms.Add(_pm2);
  38. //if (SC.GetValueOrDefault<bool>("System.SetUp.PMC.IsInstalled"))
  39. // _lstPms.Add(_pm3);
  40. if (SC.GetValueOrDefault<bool>("System.SetUp.LLA.IsInstalled"))
  41. _lstLls.Add(_loadlockA);
  42. if (SC.GetValueOrDefault<bool>("System.SetUp.LLB.IsInstalled"))
  43. _lstLls.Add(_loadlockB);
  44. if (SC.GetValueOrDefault<bool>("System.SetUp.LP1.IsInstalled"))
  45. _lstLps.Add(_lp1);
  46. if (SC.GetValueOrDefault<bool>("System.SetUp.LP2.IsInstalled"))
  47. _lstLps.Add(_lp2);
  48. if (SC.GetValueOrDefault<bool>("System.SetUp.LP3.IsInstalled"))
  49. _lstLps.Add(_lp3);
  50. tmRobotActions.Enqueue(MonitorTMRobotPMATask);
  51. tmRobotActions.Enqueue(MonitorTMRobotPMBTask);
  52. tmRobotActions.Enqueue(MonitorTMRobotLoadLockTask);
  53. }
  54. public Result Start(params object[] objs)
  55. {
  56. foreach (var positions in _checkPosition)
  57. {
  58. for (int i = 0; i < positions.Value; i++)
  59. {
  60. WaferInfo wafer = WaferManager.Instance.GetWafer(positions.Key, i);
  61. if (!wafer.IsEmpty)
  62. {
  63. ModuleName originLoadPort = (ModuleName)wafer.OriginStation;
  64. if (!ModuleHelper.IsLoadPort(originLoadPort))
  65. {
  66. EV.PostWarningLog("System", $"Wafer {positions.Key}.{i + 1} can not return, origin is not LP");
  67. return Result.FAIL;
  68. }
  69. if (wafer.Status == WaferStatus.Dummy)
  70. {
  71. EV.PostWarningLog("System", $"Wafer {positions.Key}.{i + 1} can not return, wafer is dummy");
  72. return Result.FAIL;
  73. }
  74. if (WaferManager.Instance.CheckHasWafer(originLoadPort, wafer.OriginSlot))
  75. {
  76. EV.PostWarningLog("System", $"Wafer {positions.Key}.{i + 1} can not return, origin has wafer");
  77. return Result.FAIL;
  78. }
  79. if (!(GetModule(originLoadPort.ToString()) as SchedulerLoadPort).IsReadyForPlace(ModuleName.EfemRobot, Hand.Blade1, wafer.OriginSlot))
  80. {
  81. EV.PostWarningLog("System", $"{originLoadPort} not ready to place Wafer");
  82. return Result.FAIL;
  83. }
  84. EV.PostInfoLog("System", $"Wafer return, {positions.Key}.{i + 1}=>{(ModuleName)wafer.OriginStation}.{wafer.OriginSlot + 1}");
  85. }
  86. }
  87. }
  88. return Result.RUN;
  89. }
  90. public Result Monitor()
  91. {
  92. MonitorModuleTasks();
  93. if (MonitorTaskDone())
  94. {
  95. return Result.DONE;
  96. }
  97. return Result.RUN;
  98. }
  99. public void Clear()
  100. {
  101. }
  102. public void Abort()
  103. {
  104. }
  105. public Result MonitorModuleTasks()
  106. {
  107. MonitorPMTask();
  108. MonitorTMRobotTask();
  109. MonitorEfemRobotTask();
  110. return Result.RUN;
  111. }
  112. private void MonitorTMRobotTask()
  113. {
  114. if (!_tmRobot.IsAvailable)
  115. return;
  116. //_tmRobot is idle, release all the target
  117. foreach (var ll in _lstLls)
  118. {
  119. if (ll.IsWaitTransfer(ModuleName.TMRobot))
  120. ll.StopWaitTransfer(ModuleName.TMRobot);
  121. }
  122. foreach (var pm in _lstPms)
  123. {
  124. if (pm.IsWaitTransfer(ModuleName.TMRobot))
  125. pm.StopWaitTransfer(ModuleName.TMRobot);
  126. }
  127. if (!_tmRobot.IsAvailable)
  128. return;
  129. var act = tmRobotActions.Peek();
  130. act.Invoke();
  131. if (!_tmRobot.IsAvailable)
  132. return;
  133. if (act == MonitorTMRobotLoadLockTask && _lstLls.Any(x => !x.IsAvailable))
  134. return;
  135. tmRobotActions.Enqueue(tmRobotActions.Dequeue());
  136. //MonitorTMRobotPMATask();
  137. //if (!_tmRobot.IsAvailable)
  138. // return;
  139. //MonitorTMRobotPMBTask();
  140. //if (!_tmRobot.IsAvailable)
  141. // return;
  142. //MonitorTMRobotLoadLockTask();
  143. }
  144. private void MonitorTMRobotLoadLockTask()
  145. {
  146. if (!_tmRobot.IsAvailable)
  147. return;
  148. //place to loadlock
  149. {
  150. bool blade1HasWafer = _tmRobot.Blade1Enable && WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0);
  151. bool blade2HasWafer = _tmRobot.Blade2Enable && WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1);
  152. if (blade1HasWafer || blade2HasWafer)
  153. {
  154. Hand placeBlade = blade1HasWafer ? Hand.Blade1 : Hand.Blade2;
  155. foreach (var ll in _lstLls)
  156. {
  157. if (!ll.IsAvailable)
  158. continue;
  159. var slot = GetSlotCouldBePlace(ll.Module);
  160. if (slot != null && ll.IsReadyForPlace(ModuleName.TMRobot, placeBlade, (int)slot))
  161. {
  162. if (_tmRobot.Place(ll.Module, (int)slot, placeBlade, 0, 0, false))
  163. {
  164. ll.WaitTransfer(ModuleName.TMRobot);
  165. return;
  166. }
  167. }
  168. }
  169. }
  170. }
  171. }
  172. private void MonitorTMRobotPMATask()
  173. {
  174. if (!_tmRobot.IsAvailable)
  175. return;
  176. //pick from pm
  177. {
  178. bool blade1Empty = _tmRobot.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0);
  179. bool blade2Empty = _tmRobot.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1);
  180. if (blade1Empty || blade2Empty)
  181. {
  182. Hand pickBlade = blade1Empty ? Hand.Blade1 : Hand.Blade2;
  183. //foreach (var pm in _lstPms)
  184. {
  185. var pm = _pm1;
  186. if (!pm.IsAvailable)
  187. return;
  188. var slot = GetWaferCouldBeReturn(pm.Module);
  189. if (slot != null /*&& pm.IsReadyForPick(ModuleName.TMRobot, pickBlade, (int)slot)*/)
  190. {
  191. if (_tmRobot.Pick(pm.Module, (int)slot, pickBlade, 0, 0, false))
  192. {
  193. pm.WaitTransfer(ModuleName.TMRobot);
  194. return;
  195. }
  196. }
  197. }
  198. }
  199. }
  200. }
  201. private void MonitorTMRobotPMBTask()
  202. {
  203. if (!_tmRobot.IsAvailable)
  204. return;
  205. //pick from pm
  206. {
  207. bool blade1Empty = _tmRobot.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0);
  208. bool blade2Empty = _tmRobot.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1);
  209. if (blade1Empty || blade2Empty)
  210. {
  211. Hand pickBlade = blade1Empty ? Hand.Blade1 : Hand.Blade2;
  212. //foreach (var pm in _lstPms)
  213. {
  214. var pm = _pm2;
  215. if (!pm.IsAvailable)
  216. return;
  217. var slot = GetWaferCouldBeReturn(pm.Module);
  218. if (slot != null /*&& pm.IsReadyForPick(ModuleName.TMRobot, pickBlade, (int)slot)*/)
  219. {
  220. if (_tmRobot.Pick(pm.Module, (int)slot, pickBlade, 0, 0, false))
  221. {
  222. pm.WaitTransfer(ModuleName.TMRobot);
  223. return;
  224. }
  225. }
  226. }
  227. }
  228. }
  229. }
  230. private bool MonitorTaskDone()
  231. {
  232. foreach (var positions in _checkPosition)
  233. {
  234. for (int i = 0; i < positions.Value; i++)
  235. {
  236. if (CheckWaferCouldBeReturn(positions.Key, i))
  237. {
  238. return false;
  239. }
  240. }
  241. }
  242. foreach (var lp in _lstLps)
  243. {
  244. if (!lp.IsAvailable)
  245. return false;
  246. }
  247. if (!_tmRobot.IsAvailable)
  248. return false;
  249. if (!_efem.IsAvailable)
  250. return false;
  251. return true;
  252. }
  253. private void MonitorPMTask()
  254. {
  255. foreach (var pm in _lstPms)
  256. {
  257. if (!pm.IsAvailable)
  258. continue;
  259. var wafers = WaferManager.Instance.GetWafers(pm.Module);
  260. for (int i = 0; i < wafers.Length; i++)
  261. {
  262. if (!pm.IsAvailable)
  263. break;
  264. if (CheckWaferCouldBeReturn(pm.Module, i))
  265. {
  266. if (!pm.IsReadyForPick(ModuleName.TMRobot, Hand.Blade1, i))
  267. {
  268. pm.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Pick, i);
  269. }
  270. }
  271. }
  272. }
  273. }
  274. private void MonitorEfemRobotTask()
  275. {
  276. if (!_efem.IsAvailable)
  277. return;
  278. //efem robot is idle, release all the target
  279. if (_aligner.IsWaitTransfer(ModuleName.EfemRobot))
  280. _aligner.StopWaitTransfer(ModuleName.EfemRobot);
  281. foreach (var ll in _lstLls)
  282. {
  283. if (ll.IsWaitTransfer(ModuleName.EfemRobot))
  284. ll.StopWaitTransfer(ModuleName.EfemRobot);
  285. }
  286. foreach (var lp in _lstLps)
  287. {
  288. if (lp.IsWaitTransfer(ModuleName.EfemRobot))
  289. lp.StopWaitTransfer(ModuleName.EfemRobot);
  290. }
  291. MonitorEfemRobotAlignerTask();
  292. if (!_efem.IsAvailable)
  293. return;
  294. MonitorEfemRobotLoadLockTask();
  295. MonitorEfemRobotLoadPortTask();
  296. }
  297. private void MonitorEfemRobotLoadPortTask()
  298. {
  299. if (!_efem.IsAvailable)
  300. return;
  301. //place
  302. bool blade0HasWaferAndProcessed = _efem.Blade1Enable && CheckWaferCouldBeReturn(ModuleName.EfemRobot, 0);
  303. bool blade1HasWaferAndProcessed = _efem.Blade2Enable && CheckWaferCouldBeReturn(ModuleName.EfemRobot, 1);
  304. if (blade0HasWaferAndProcessed || blade1HasWaferAndProcessed)
  305. {
  306. Hand placeBlade = blade0HasWaferAndProcessed ? Hand.Blade1 : Hand.Blade2;
  307. if (blade0HasWaferAndProcessed && blade1HasWaferAndProcessed)
  308. {
  309. if (WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 1).OriginSlot <
  310. WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0).OriginSlot)
  311. {
  312. placeBlade = Hand.Blade2;
  313. }
  314. }
  315. SlotItem destination = GetWaferReturnLoadPort(ModuleName.EfemRobot, (int)placeBlade);
  316. if (destination != null)
  317. {
  318. SchedulerLoadPort lp = (SchedulerLoadPort)GetModule(destination.Module.ToString());
  319. if (lp.IsReadyForPlace(ModuleName.EfemRobot, Hand.Blade1, destination.Slot))
  320. {
  321. if (_efem.Place(destination.Module, destination.Slot, (Hand)placeBlade))
  322. {
  323. lp.WaitTransfer(ModuleName.EfemRobot);
  324. return;
  325. }
  326. }
  327. }
  328. }
  329. }
  330. private void MonitorEfemRobotLoadLockTask()
  331. {
  332. if (!_efem.IsAvailable)
  333. return;
  334. foreach (var ll in _lstLls)
  335. {
  336. if (!ll.IsAvailable)
  337. continue;
  338. {
  339. bool blade1Empty = _efem.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0);
  340. bool blade2Empty = _efem.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
  341. if (blade1Empty || blade2Empty)
  342. {
  343. Hand pickBlade = blade1Empty ? Hand.Blade1 : Hand.Blade2;
  344. var slot = GetWaferCouldBeReturn(ll.Module);
  345. if (slot != null)
  346. {
  347. if (ll.IsReadyForPick(ModuleName.EfemRobot, pickBlade, (int)slot))
  348. {
  349. if (_efem.Pick(ll.Module, (int)slot, pickBlade))
  350. {
  351. ll.WaitTransfer(ModuleName.EfemRobot);
  352. return;
  353. }
  354. }
  355. }
  356. }
  357. }
  358. }
  359. }
  360. private void MonitorEfemRobotAlignerTask()
  361. {
  362. if (!_efem.IsAvailable)
  363. return;
  364. if (!_aligner.IsAvailable)
  365. return;
  366. //pick from aligner
  367. if (WaferManager.Instance.CheckHasWafer(ModuleName.Aligner, 0))
  368. {
  369. bool blade1Empty = _efem.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0);
  370. bool blade2Empty = _efem.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
  371. if (blade1Empty || blade2Empty)
  372. {
  373. Hand pickBlade = blade1Empty ? Hand.Blade1 : Hand.Blade2;
  374. if (_aligner.IsReadyForPick(ModuleName.EfemRobot, pickBlade, 0))
  375. {
  376. if (_efem.Pick(_aligner.Module, 0, pickBlade))
  377. {
  378. _aligner.WaitTransfer(ModuleName.EfemRobot);
  379. return;
  380. }
  381. }
  382. }
  383. }
  384. }
  385. private int? GetWaferCouldBeReturn(ModuleName module)
  386. {
  387. var wafers = WaferManager.Instance.GetWafers(module);
  388. for (int i = 0; i < wafers.Length; i++)
  389. {
  390. if (CheckWaferCouldBeReturn(wafers[i]))
  391. return i;
  392. }
  393. return null;
  394. }
  395. private int? GetSlotCouldBePlace(ModuleName module)
  396. {
  397. var wafers = WaferManager.Instance.GetWafers(module);
  398. for (int i = 0; i < wafers.Length; i++)
  399. {
  400. if (wafers[i].IsEmpty)
  401. return i;
  402. }
  403. return null;
  404. }
  405. private bool CheckWaferCouldBeReturn(WaferInfo wafer)
  406. {
  407. if (!wafer.IsEmpty)
  408. {
  409. return ModuleHelper.IsLoadPort((ModuleName)wafer.OriginStation)
  410. && wafer.Status != WaferStatus.Dummy
  411. && WaferManager.Instance.CheckNoWafer((ModuleName)wafer.OriginStation, wafer.OriginSlot);
  412. }
  413. return false;
  414. }
  415. private bool CheckWaferCouldBeReturn(ModuleName module, int slot)
  416. {
  417. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  418. if (!wafer.IsEmpty)
  419. {
  420. return ModuleHelper.IsLoadPort((ModuleName)wafer.OriginStation)
  421. && wafer.Status != WaferStatus.Dummy
  422. && WaferManager.Instance.CheckNoWafer((ModuleName)wafer.OriginStation, wafer.OriginSlot);
  423. }
  424. return false;
  425. }
  426. private SlotItem GetWaferReturnLoadPort(ModuleName module, int slot)
  427. {
  428. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  429. if (!wafer.IsEmpty)
  430. {
  431. return new SlotItem((ModuleName)wafer.OriginStation, wafer.OriginSlot);
  432. }
  433. return null;
  434. }
  435. }
  436. }