TMCycle.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Aitex.Core.Common;
  5. using Aitex.Core.RT.DataCenter;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.RT.Routine;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Sorter.Common;
  10. using MECF.Framework.Common.Equipment;
  11. using MECF.Framework.Common.Schedulers;
  12. using MECF.Framework.Common.SubstrateTrackings;
  13. using MECF.Framework.RT.ModuleLibrary.SystemModules;
  14. using EfemDualSchedulerLib.Schedulers;
  15. using Aitex.Core.Util;
  16. namespace EfemDualSchedulerLib
  17. {
  18. public class TMCycle : SchedulerModuleFactory, IRoutine
  19. {
  20. Dictionary<ModuleName, int> _checkPosition = new Dictionary<ModuleName, int>()
  21. {
  22. {ModuleName.TMRobot, SC.IsDoubleFork ? 4:2 },
  23. {ModuleName.PMA, 2},
  24. {ModuleName.PMB, 2},
  25. };
  26. Queue<Action> tmRobotActions = new Queue<Action>() { };
  27. private List<SchedulerPM> _lstPms = new List<SchedulerPM>();
  28. private List<SchedulerLoadLock> _lstLls = new List<SchedulerLoadLock>();
  29. public bool PMAIsInstalled
  30. {
  31. get
  32. {
  33. return SC.GetValueOrDefault<bool>("System.SetUp.PMA.IsInstalled");
  34. }
  35. }
  36. public bool PMBIsInstalled
  37. {
  38. get
  39. {
  40. return SC.GetValueOrDefault<bool>("System.SetUp.PMB.IsInstalled");
  41. }
  42. }
  43. public TMCycle(EquipmentManager equipment) : base()
  44. {
  45. DATA.Subscribe("TMCylce.RemainedCycleCount", () =>
  46. {
  47. return cycleCount - 1;
  48. });
  49. //有优先级,先处理pmb后pma
  50. if (PMBIsInstalled)
  51. _lstPms.Add(_pm2);
  52. if (PMAIsInstalled)
  53. _lstPms.Add(_pm1);
  54. _lstLls.Add(_loadlockA);
  55. _lstLls.Add(_loadlockB);
  56. tmRobotActions.Enqueue(MonitorTmRobotLoadLockPickTask);
  57. tmRobotActions.Enqueue(MonitorTMRobotPMPlaceTask);
  58. tmRobotActions.Enqueue(MonitorTMRobotPMPickTask);
  59. tmRobotActions.Enqueue(MonitorTmRobotLoadLockPlaceTask);
  60. }
  61. List<string> tmCycleRoutine = new List<string>() { "LLA", "PMA", "PMB", "LLB" };
  62. int cycleCount = 1;
  63. public Result Start(params object[] objs)
  64. {
  65. if (objs.Length == 2)
  66. {
  67. tmCycleRoutine = ((string[])objs[0]).ToList();
  68. cycleCount = (int)objs[1];
  69. }
  70. //if (!PMAIsInstalled && !PMBIsInstalled)
  71. //{
  72. // EV.PostWarningLog("System", $"TM Cycle, PMA & PMB Both UnInstalled.");
  73. // return Result.FAIL;
  74. //}
  75. if (!PMAIsInstalled && tmCycleRoutine.Contains("PMA"))
  76. {
  77. EV.PostWarningLog("System", $"TM Cycle, PMA is UnInstalled.");
  78. return Result.FAIL;
  79. }
  80. if (!PMBIsInstalled && tmCycleRoutine.Contains("PMB"))
  81. {
  82. EV.PostWarningLog("System", $"TM Cycle, PMB is UnInstalled.");
  83. return Result.FAIL;
  84. }
  85. foreach (var positions in _checkPosition)
  86. {
  87. for (int i = 0; i < positions.Value; i++)
  88. {
  89. WaferInfo wafer = WaferManager.Instance.GetWafer(positions.Key, i);
  90. if (!wafer.IsEmpty)
  91. {
  92. EV.PostWarningLog("System", $"TM Cycle, {positions.Key}.{i + 1} can not has wafer.");
  93. return Result.FAIL;
  94. }
  95. }
  96. }
  97. WaferInfo[] OriginWafers = WaferManager.Instance.GetWafers(ModuleHelper.Converter(tmCycleRoutine.First()));
  98. WaferInfo[] DestinationWafers = WaferManager.Instance.GetWafers(ModuleHelper.Converter(tmCycleRoutine.Last()));
  99. for (int i = 0; i < OriginWafers.Length; i++)
  100. {
  101. if (!OriginWafers[i].IsEmpty)
  102. {
  103. OriginWafers[i].OriginStation = (int)ModuleHelper.Converter(tmCycleRoutine.First());
  104. OriginWafers[i].OriginSlot = i;
  105. OriginWafers[i].ProcessState = EnumWaferProcessStatus.InProcess;
  106. OriginWafers[i].NextSequenceStep = 0;
  107. if (tmCycleRoutine.First() != tmCycleRoutine.Last() && !DestinationWafers[i].IsEmpty)
  108. {
  109. EV.PostWarningLog("System", $"TM Cycle, {tmCycleRoutine.Last()}.{i + 1} already has wafer.");
  110. return Result.FAIL;
  111. }
  112. }
  113. }
  114. if (tmCycleRoutine.First() != tmCycleRoutine.Last())
  115. {
  116. tmCycleRoutine.Add(tmCycleRoutine.First());
  117. }
  118. return Result.RUN;
  119. }
  120. public Result Monitor()
  121. {
  122. MonitorModuleTasks();
  123. if (MonitorTaskDone())
  124. {
  125. return Result.DONE;
  126. }
  127. return Result.RUN;
  128. }
  129. public void Clear()
  130. {
  131. }
  132. public void Abort()
  133. {
  134. _tmRobot?.ResetTask();
  135. foreach (var pm in _lstPms)
  136. {
  137. pm.ResetTask();
  138. }
  139. }
  140. public Result MonitorModuleTasks()
  141. {
  142. MonitorPMTask();
  143. MonitorTMRobotTask();
  144. return Result.RUN;
  145. }
  146. private void MonitorTMRobotTask()
  147. {
  148. if (!_tmRobot.IsAvailable)
  149. return;
  150. //_tmRobot is idle, release all the target
  151. foreach (var ll in _lstLls)
  152. {
  153. if (ll.IsWaitTransfer(ModuleName.TMRobot))
  154. ll.StopWaitTransfer(ModuleName.TMRobot);
  155. }
  156. foreach (var pm in _lstPms)
  157. {
  158. if (pm.IsWaitTransfer(ModuleName.TMRobot))
  159. pm.StopWaitTransfer(ModuleName.TMRobot);
  160. }
  161. if (!_tmRobot.IsAvailable)
  162. return;
  163. var act = tmRobotActions.Peek();
  164. act.Invoke();
  165. if (!_tmRobot.IsAvailable)
  166. return;
  167. tmRobotActions.Enqueue(tmRobotActions.Dequeue());
  168. //MonitorTMRobotPMTask();
  169. //if (!_tmRobot.IsAvailable)
  170. // return;
  171. //MonitorTMRobotLoadLockTask();
  172. }
  173. private void MonitorTmRobotLoadLockPlaceTask()
  174. {
  175. if (!_tmRobot.IsAvailable)
  176. return;
  177. //place to ll
  178. bool blade0HasWaferAndProcessed = _tmRobot.Blade1Enable && Converter.MapBladeToSlots(Hand.Blade1).Any(p=>WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, p));
  179. bool blade1HasWaferAndProcessed = _tmRobot.Blade2Enable && Converter.MapBladeToSlots(Hand.Blade2).Any(p=>WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, p));
  180. if (blade0HasWaferAndProcessed || blade1HasWaferAndProcessed)
  181. {
  182. Hand placeBlade = blade0HasWaferAndProcessed ? Hand.Blade1 : Hand.Blade2;
  183. var wafers = WaferManager.Instance.GetWafers(ModuleName.TMRobot);
  184. foreach (var ll in _lstLls)
  185. {
  186. if (!ll.IsAvailable)
  187. continue;
  188. var sourceSlot = new int[] { (int)placeBlade, ((int)placeBlade) + 2 };
  189. var targetSlot = new List<int>();
  190. for(int i=0;i< sourceSlot.Length;i++)
  191. {
  192. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, sourceSlot[i]);
  193. if (wafer == null || wafer.IsEmpty) continue;
  194. var slot = wafer.OriginSlot;
  195. if (!CheckWaferNextStep(ModuleName.TMRobot, sourceSlot[i], ll.Module))
  196. continue;
  197. targetSlot.Add(slot);
  198. }
  199. if (targetSlot.Count > 0 && targetSlot.All(p => ll.IsReadyForPlace(ModuleName.TMRobot, placeBlade, p)))
  200. {
  201. if (_tmRobot.Place(ll.Module, targetSlot.ToArray(), placeBlade, Converter.GetPanAndSlotFromPlace(placeBlade).Item1, 0, 0, false))
  202. {
  203. Array.ForEach(wafers, p=> {
  204. if (p.NextSequenceStep >= tmCycleRoutine.Count - 1)
  205. p.ProcessState = EnumWaferProcessStatus.Completed;
  206. });
  207. ll.WaitTransfer(ModuleName.TMRobot);
  208. return;
  209. }
  210. }
  211. }
  212. }
  213. }
  214. private void MonitorTmRobotLoadLockPickTask()
  215. {
  216. if (!_tmRobot.IsAvailable)
  217. return;
  218. //pick from ll
  219. bool blade1EmptyAndEnable = _tmRobot.Blade1Enable && Converter.MapBladeToSlots(Hand.Blade1).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  220. bool blade2EmptyAndEnable = _tmRobot.Blade2Enable && Converter.MapBladeToSlots(Hand.Blade2).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  221. if (blade1EmptyAndEnable || blade2EmptyAndEnable)
  222. {
  223. Hand pickBlade = blade1EmptyAndEnable ? Hand.Blade1 : Hand.Blade2;
  224. //if (_tmRobot.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0))
  225. //{
  226. // pickBlade = Hand.Blade1;
  227. //}
  228. //else if (_tmRobot.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  229. //{
  230. // pickBlade = Hand.Blade2;
  231. //}
  232. //else
  233. //{
  234. // return;
  235. //}
  236. foreach (var ll in _lstLls)
  237. {
  238. if (!ll.IsAvailable)
  239. continue;
  240. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  241. List<int> slots = new List<int>();
  242. for (int pickSlot = 0; pickSlot < wafers.Length; pickSlot++)
  243. {
  244. if (wafers[pickSlot].NextSequenceStep == 0)
  245. {
  246. ModuleName nextModule = ModuleHelper.Converter(tmCycleRoutine[1]);
  247. if (SC.IsDoubleFork && WaferManager.Instance.GetWafers(nextModule).Any(x => !x.IsEmpty))
  248. return;
  249. if (WaferManager.Instance.GetWafers(nextModule).All(x => !x.IsEmpty))
  250. return;
  251. }
  252. if (wafers[pickSlot].ProcessState != EnumWaferProcessStatus.InProcess)
  253. continue;
  254. slots.Add(pickSlot);
  255. if (SC.IsDoubleFork)
  256. {
  257. var nextSlot = (pickSlot % 2 > 0) ? pickSlot - 1 : pickSlot + 1;
  258. if (wafers[nextSlot].ProcessState == EnumWaferProcessStatus.InProcess) slots.Add(nextSlot);
  259. }
  260. break;
  261. }
  262. if (slots.Count > 0 && slots.All(p=> ll.IsReadyForPick(ModuleName.TMRobot, pickBlade, p)))
  263. {
  264. if (_tmRobot.Pick(ll.Module, slots.ToArray(), pickBlade, Converter.GetPanAndSlotFromPick(pickBlade, slots.ToArray()).Item1, 0, 0, false))
  265. {
  266. slots.ForEach(p=> wafers[p].NextSequenceStep++);
  267. ll.WaitTransfer(ModuleName.TMRobot);
  268. slots.Clear();
  269. return;
  270. }
  271. }
  272. }
  273. }
  274. }
  275. private void MonitorTMRobotLoadLockTask()
  276. {
  277. if (!_tmRobot.IsAvailable)
  278. return;
  279. //place to llb
  280. {
  281. bool blade1HasWafer = _tmRobot.Blade1Enable && WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) && WaferManager.Instance.GetWafer(ModuleName.TMRobot, 0).NextStation == (int)ModuleName.LLB;
  282. bool blade2HasWafer = _tmRobot.Blade2Enable && WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1) && WaferManager.Instance.GetWafer(ModuleName.TMRobot, 1).NextStation == (int)ModuleName.LLB;
  283. if (blade1HasWafer || blade2HasWafer)
  284. {
  285. Hand placeBlade = blade1HasWafer ? Hand.Blade1 : Hand.Blade2;
  286. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)placeBlade);
  287. {
  288. if (!_loadlockB.IsAvailable)
  289. return;
  290. var slot = wafer.OriginSlot;
  291. if (_loadlockB.IsReadyForPlace(ModuleName.TMRobot, placeBlade, (int)slot))
  292. {
  293. if (_tmRobot.Place(_loadlockB.Module, new int[] { (int)slot }, placeBlade, Converter.GetPanAndSlotFromPlace(placeBlade).Item1, 0, 0, false))
  294. {
  295. _loadlockB.WaitTransfer(ModuleName.TMRobot);
  296. return;
  297. }
  298. }
  299. }
  300. }
  301. }
  302. if (!_tmRobot.IsAvailable)
  303. return;
  304. //pick from lla
  305. if (PMAIsInstalled && PMBIsInstalled && WaferManager.Instance.CheckHasWafer(ModuleName.PMA, 0) && WaferManager.Instance.CheckHasWafer(ModuleName.PMA, 1))
  306. return;
  307. bool blade1EmptyAndEnable = _tmRobot.Blade1Enable && Converter.MapBladeToSlots(Hand.Blade1).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  308. bool blade2EmptyAndEnable = _tmRobot.Blade2Enable && Converter.MapBladeToSlots(Hand.Blade2).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  309. if (blade1EmptyAndEnable || blade2EmptyAndEnable)
  310. {
  311. Hand pickBlade = blade2EmptyAndEnable? Hand.Blade2: Hand.Blade1;
  312. //if (_tmRobot.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  313. //{
  314. // pickBlade = Hand.Blade2;
  315. //}
  316. //else if (_tmRobot.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0))
  317. //{
  318. // pickBlade = Hand.Blade1;
  319. //}
  320. //else
  321. //{
  322. // return;
  323. //}
  324. {
  325. if (!_loadlockA.IsAvailable)
  326. return;
  327. var wafers = WaferManager.Instance.GetWafers(_loadlockA.Module);
  328. for (int pickSlot = 0; pickSlot < wafers.Length; pickSlot++)
  329. {
  330. if (_loadlockA.IsReadyForPick(ModuleName.TMRobot, pickBlade, pickSlot))
  331. {
  332. if (_tmRobot.Pick(_loadlockA.Module, new int[] { pickSlot }, pickBlade, Converter.GetPanAndSlotFromPick(pickBlade, new int[] { pickSlot }).Item1, 0, 0, false))
  333. {
  334. _loadlockA.WaitTransfer(ModuleName.TMRobot);
  335. return;
  336. }
  337. }
  338. }
  339. }
  340. }
  341. }
  342. private void MonitorTMRobotPMPlaceTask()
  343. {
  344. if (!_tmRobot.IsAvailable)
  345. return;
  346. //place to pm
  347. bool blade0HasWafer = _tmRobot.Blade1Enable && Converter.MapBladeToSlots(Hand.Blade1).Any(p=>WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, p));
  348. bool blade1HasWafer = _tmRobot.Blade2Enable && Converter.MapBladeToSlots(Hand.Blade2).Any(p=>WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, p));
  349. if (blade0HasWafer || blade1HasWafer)
  350. {
  351. Hand placeBlade = blade0HasWafer ? Hand.Blade1 : Hand.Blade2;
  352. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)placeBlade);
  353. foreach (var schedulerPm in _lstPms)
  354. {
  355. if (!schedulerPm.IsAvailable)
  356. continue;
  357. if (!CheckWaferNextStep(ModuleName.TMRobot, (int)placeBlade, schedulerPm.Module))
  358. continue;
  359. var pmWafer0 = WaferManager.Instance.GetWafer(schedulerPm.Module, 0);
  360. var pmWafer1 = WaferManager.Instance.GetWafer(schedulerPm.Module, 1);
  361. //如果腔体中两片都满了,则不允许放入
  362. if (!pmWafer0.IsEmpty && !pmWafer1.IsEmpty)
  363. continue;
  364. if(WaferManager.Instance.CheckNoWafer(schedulerPm.Module, 0) &&
  365. WaferManager.Instance.CheckNoWafer(schedulerPm.Module, 1) &&
  366. SC.IsDoubleFork)
  367. {
  368. List<int> targetSlots = new List<int>();
  369. int[] tmSlots = new int[] { (int)placeBlade, ((int)placeBlade) + 2 };
  370. for(var i=0;i< tmSlots.Length; i++)
  371. {
  372. var tmWafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, tmSlots[i]);
  373. if (tmWafer != null && !tmWafer.IsEmpty) targetSlots.Add(i);
  374. }
  375. if (_tmRobot.Place(schedulerPm.Module, targetSlots.ToArray(), placeBlade, Converter.GetPanAndSlotFromPlace(placeBlade).Item1, 0, 0, false))
  376. {
  377. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  378. return;
  379. }
  380. }
  381. if (SC.IsDoubleFork) return;
  382. if (WaferManager.Instance.CheckNoWafer(schedulerPm.Module, 0))
  383. {
  384. if (_tmRobot.Place(schedulerPm.Module, new int[] { 0 }, placeBlade, Converter.GetPanAndSlotFromPlace(placeBlade).Item1, 0, 0, false))
  385. {
  386. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  387. return;
  388. }
  389. }
  390. if (WaferManager.Instance.CheckNoWafer(schedulerPm.Module, 1))
  391. {
  392. if (_tmRobot.Place(schedulerPm.Module, new int[] { 1 }, placeBlade, Converter.GetPanAndSlotFromPlace(placeBlade).Item1, 0, 0, false))
  393. {
  394. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  395. return;
  396. }
  397. }
  398. }
  399. }
  400. }
  401. private void MonitorTMRobotPMPickTask()
  402. {
  403. //pick from pm
  404. {
  405. bool blade1Empty = _tmRobot.Blade1Enable && Converter.MapBladeToSlots(Hand.Blade1).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  406. bool blade2Empty = _tmRobot.Blade2Enable && Converter.MapBladeToSlots(Hand.Blade2).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  407. if (blade1Empty || blade2Empty)
  408. {
  409. Hand pickBlade = blade1Empty ? Hand.Blade1 : Hand.Blade2;
  410. foreach (var pm in _lstPms)
  411. {
  412. if (!pm.IsAvailable)
  413. continue;
  414. var wafers = WaferManager.Instance.GetWafers(pm.Module);
  415. List<int> slots = new List<int>();
  416. for (int slot = 0; slot < wafers.Length; slot++)
  417. {
  418. if (pm.IsReadyForPick(ModuleName.TMRobot, pickBlade, slot))
  419. {
  420. slots.Add(slot);
  421. if (!SC.IsDoubleFork || slots.Count > 1) break;
  422. }
  423. }
  424. if (slots != null && slots.Count > 0)
  425. {
  426. if (_tmRobot.Pick(pm.Module, slots.ToArray(), pickBlade, Converter.GetPanAndSlotFromPick(pickBlade, slots.ToArray()).Item1, 0, 0, false))
  427. {
  428. slots.ForEach(p => wafers[p].NextSequenceStep++);
  429. pm.WaitTransfer(ModuleName.TMRobot);
  430. return;
  431. }
  432. }
  433. }
  434. }
  435. }
  436. }
  437. private void MonitorTMRobotPMTask()
  438. {
  439. if (!_tmRobot.IsAvailable)
  440. return;
  441. //place to pm
  442. bool blade0HasWafer = _tmRobot.Blade1Enable && Converter.MapBladeToSlots(Hand.Blade1).Any(p => WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, p));
  443. bool blade1HasWafer = _tmRobot.Blade2Enable && Converter.MapBladeToSlots(Hand.Blade2).Any(p => WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, p));
  444. if (blade0HasWafer || blade1HasWafer)
  445. {
  446. Hand placeBlade = blade0HasWafer ? Hand.Blade1 : Hand.Blade2;
  447. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)placeBlade);
  448. foreach (var schedulerPm in _lstPms)
  449. {
  450. if (!schedulerPm.IsAvailable)
  451. continue;
  452. if (wafer.NextStation != (int)schedulerPm.Module)
  453. continue;
  454. var pmWafer0 = WaferManager.Instance.GetWafer(schedulerPm.Module, 0);
  455. var pmWafer1 = WaferManager.Instance.GetWafer(schedulerPm.Module, 1);
  456. //如果腔体中两片都满了,则不允许放入
  457. if (!pmWafer0.IsEmpty && !pmWafer1.IsEmpty)
  458. continue;
  459. if (WaferManager.Instance.CheckNoWafer(schedulerPm.Module, 0))
  460. {
  461. if (_tmRobot.Place(schedulerPm.Module, new int[] { 0 }, placeBlade, Converter.GetPanAndSlotFromPlace(placeBlade).Item1, 0, 0, false))
  462. {
  463. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  464. return;
  465. }
  466. }
  467. if (WaferManager.Instance.CheckNoWafer(schedulerPm.Module, 1))
  468. {
  469. if (_tmRobot.Place(schedulerPm.Module, new int[] { 1 }, placeBlade, Converter.GetPanAndSlotFromPlace(placeBlade).Item1,0, 0, false))
  470. {
  471. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  472. return;
  473. }
  474. }
  475. }
  476. }
  477. if (!_tmRobot.IsAvailable)
  478. return;
  479. //pick from pm
  480. {
  481. bool blade1Empty = _tmRobot.Blade1Enable && Converter.MapBladeToSlots(Hand.Blade1).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));//WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0);
  482. bool blade2Empty = _tmRobot.Blade2Enable && Converter.MapBladeToSlots(Hand.Blade2).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));//WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1);
  483. if (blade1Empty || blade2Empty)
  484. {
  485. Hand pickBlade = blade1Empty ? Hand.Blade1 : Hand.Blade2;
  486. foreach (var pm in _lstPms)
  487. {
  488. if (!pm.IsAvailable)
  489. continue;
  490. var wafers = WaferManager.Instance.GetWafers(pm.Module);
  491. for (int slot = 0; slot < wafers.Length; slot++)
  492. {
  493. if (pm.IsReadyForPick(ModuleName.TMRobot, pickBlade, slot))
  494. {
  495. if (_tmRobot.Pick(pm.Module, new int[] { slot }, pickBlade, Converter.GetPanAndSlotFromPick(pickBlade, new int[] { slot }).Item1, 0, 0, false))
  496. {
  497. wafers[slot].NextSequenceStep++;
  498. pm.WaitTransfer(ModuleName.TMRobot);
  499. return;
  500. }
  501. }
  502. }
  503. }
  504. }
  505. }
  506. }
  507. private bool MonitorTaskDone()
  508. {
  509. foreach (var positions in _checkPosition)
  510. {
  511. for (int i = 0; i < positions.Value; i++)
  512. {
  513. WaferInfo wafer = WaferManager.Instance.GetWafer(positions.Key, i);
  514. if (!wafer.IsEmpty)
  515. {
  516. return false;
  517. }
  518. }
  519. }
  520. foreach (var ll in _lstLls)
  521. {
  522. var llWafers = WaferManager.Instance.GetWafers(ll.Module);
  523. for (int i = 0; i < llWafers.Length; i++)
  524. {
  525. if (!llWafers[i].IsEmpty && llWafers[i].ProcessState != EnumWaferProcessStatus.Completed)
  526. return false;
  527. }
  528. }
  529. if (!_tmRobot.IsAvailable)
  530. return false;
  531. WaferInfo[] originWafers = WaferManager.Instance.GetWafers(ModuleHelper.Converter(tmCycleRoutine.First()));
  532. if (cycleCount > 1 && originWafers.All(x => x.IsEmpty || x.ProcessState == EnumWaferProcessStatus.Completed))
  533. {
  534. cycleCount--;
  535. foreach (WaferInfo wafer in originWafers)
  536. {
  537. if(!wafer.IsEmpty)
  538. {
  539. wafer.NextSequenceStep = 0;
  540. wafer.ProcessState = EnumWaferProcessStatus.InProcess;
  541. }
  542. }
  543. return false;
  544. }
  545. return true;
  546. }
  547. private void MonitorPMTask()
  548. {
  549. foreach (var pm in _lstPms)
  550. {
  551. if (!pm.IsAvailable)
  552. continue;
  553. if (pm.Module == ModuleName.PMA && !PMAIsInstalled)
  554. continue;
  555. if (pm.Module == ModuleName.PMB && !PMBIsInstalled)
  556. continue;
  557. var wafers = WaferManager.Instance.GetWafers(pm.Module);
  558. int[] slots = new int[] { 0, 1 };
  559. if(wafers.Any(p=>!p.IsEmpty) && slots.Any(p=> !pm.IsReadyForPick(ModuleName.TMRobot, Hand.Blade1, p)))
  560. {
  561. var targetSlots = slots.Where(p=> WaferManager.Instance.CheckHasWafer(pm.Module,p)).ToArray();
  562. pm.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Pick, targetSlots);
  563. return;
  564. }
  565. if (wafers.Any(p => p.IsEmpty) && slots.Any(p=> !pm.IsReadyForPlace(ModuleName.TMRobot, Hand.Blade1, p)))
  566. {
  567. var targetSlots = slots.Where(p => WaferManager.Instance.CheckNoWafer(pm.Module, p)).ToArray();
  568. pm.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Place, targetSlots);
  569. return;
  570. }
  571. }
  572. }
  573. private bool CheckWaferNextStep(ModuleName module, int slot, ModuleName nextModule)
  574. {
  575. if (!WaferManager.Instance.CheckHasWafer(module, slot))
  576. return false;
  577. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  578. if (wafer.NextSequenceStep >= tmCycleRoutine.Count)
  579. return false;
  580. if (tmCycleRoutine[wafer.NextSequenceStep] != nextModule.ToString())
  581. return false;
  582. return true;
  583. }
  584. }
  585. }