SchedulerSequenceManager.cs 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  1. using MECF.Framework.Common.RecipeCenter;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.Schedulers;
  9. using Aitex.Core.Common;
  10. using MECF.Framework.Common.WaferHolder;
  11. using MECF.Framework.Common.CommonData;
  12. using System.Windows;
  13. using Aitex.Core.RT.IOCore;
  14. using Aitex.Core.RT.Log;
  15. using Aitex.Core.Util;
  16. using MECF.Framework.Common.Routine;
  17. using CyberX8_RT.Modules;
  18. using Aitex.Core.RT.Fsm;
  19. using CyberX8_RT.Modules.PUF;
  20. using CyberX8_RT.Modules.Dummy;
  21. using MECF.Framework.Common.SubstrateTrackings;
  22. using MECF.Framework.Common.ToolLayout;
  23. using CyberX8_RT.Modules.Metal;
  24. using CyberX8_RT.Modules.Rinse;
  25. using MECF.Framework.RT.Core.Equipments;
  26. using MECF.Framework.Common.ProcessCell;
  27. using SecsGem.Core.ItemModel;
  28. using CyberX8_RT.Modules.Transporter;
  29. using CyberX8_Core;
  30. using Aitex.Core.RT.SCCore;
  31. using CyberX8_RT.Modules.Dryer;
  32. using CyberX8_RT.Modules.Prewet;
  33. using CyberX8_RT.Modules.SRD;
  34. using CyberX8_RT.Modules.Reservoir;
  35. using CyberX8_RT.Schedulers.Puf;
  36. using CyberX8_RT.Modules.Loader;
  37. using CyberX8_RT.Schedulers.Transporter;
  38. using CyberX8_RT.Schedulers.Loader;
  39. using CyberX8_RT.Devices.EFEM;
  40. namespace CyberX8_RT.Schedulers
  41. {
  42. public class SchedulerSequenceManager : Singleton<SchedulerSequenceManager>
  43. {
  44. #region 常量
  45. private const string ENGINEERING = "Engineering";
  46. private const string PRODUCTION = "Production";
  47. private const string TRNPA = "TRNPA";
  48. private const string TRNPB = "TRNPB";
  49. #endregion
  50. /// <summary>
  51. /// 解析Wafer所有调度工序
  52. /// </summary>
  53. /// <param name="sequenceRecipe"></param>
  54. /// <returns></returns>
  55. public List<SchedulerSequence> AnalyWaferAllSchedulerSequence(WaferInfo waferInfo,ModuleName pufModule,string side,WaferHolderInfo waferHolderInfo,SequenceRecipe sequenceRecipe)
  56. {
  57. waferInfo.LoaderSide = side;
  58. List<SchedulerSequence> schedulerSequences = new List<SchedulerSequence>();
  59. int index = 0;
  60. MoveItem moveItem = new MoveItem((ModuleName)waferInfo.OriginStation, waferInfo.OriginSlot, ModuleName.Aligner1, 0, Aitex.Sorter.Common.Hand.Blade1);
  61. SchedulerSequence efemRobotSequence = CreateEfemRobotSequence(moveItem,null,sequenceRecipe.SubstrateSize,ref index);
  62. schedulerSequences.Add(efemRobotSequence);
  63. SchedulerSequence alignerSequence=CreateAlignerSequence(sequenceRecipe.AlignmentAngle,sequenceRecipe.SubstrateSize,ref index);
  64. schedulerSequences.Add(alignerSequence);
  65. //从Aligner至Puf B面
  66. MoveItem moveItem2 = new MoveItem(ModuleName.Aligner1, 0, pufModule, 1, Aitex.Sorter.Common.Hand.Blade1);
  67. SchedulerSequence secondEfemRobotSequence = CreateEfemRobotSequence(moveItem2,null,sequenceRecipe.SubstrateSize, ref index);
  68. schedulerSequences.Add(secondEfemRobotSequence);
  69. SchedulerSequence pufSequence=CreatePufSequence(pufModule,sequenceRecipe,side,true,ref index);
  70. schedulerSequences.Add(pufSequence);
  71. ////Loader
  72. //SchedulerSequence loaderSequence = CreateLoaderSequence(ref index);
  73. //schedulerSequences.Add(loaderSequence);
  74. ////wafer holder装载后的recipe工序
  75. //List<SchedulerSequence> waferHolderAfterLoadedAllSequences = WaferHolderAfterLoadedAllSchedulerSequences(waferHolderInfo, sequenceRecipe, ref index);
  76. //schedulerSequences.AddRange(waferHolderAfterLoadedAllSequences);
  77. ////buffer模块至Loader
  78. //ModuleName bufferModule = ConvertToBufferModule(waferHolderInfo.BufferId);
  79. //WaferHolderMoveItem bufferToLoaderItem = new WaferHolderMoveItem(bufferModule,ModuleType.Buffer , ModuleName.Loader1, ModuleType.Loader);
  80. //SchedulerSequence bufferToLoaderSequence = CreateLoaderTransporterSequence(bufferToLoaderItem, ref index);
  81. //schedulerSequences.Add(bufferToLoaderSequence);
  82. ////Loader
  83. //SchedulerSequence backLoaderSequence = CreateLoaderSequence(ref index);
  84. //schedulerSequences.Add(backLoaderSequence);
  85. //puf模块
  86. SchedulerSequence backPufSequence = CreatePufSequence(pufModule,sequenceRecipe,"",false, ref index);
  87. schedulerSequences.Add(backPufSequence);
  88. //若经过srd
  89. if(SequenceRecipeManager.Instance.IsContainedSrd(sequenceRecipe))
  90. {
  91. SrdRecipe srdRecipe=SequenceRecipeManager.Instance.GetSrdRecipeBySequenceRecipe(sequenceRecipe);
  92. if(srdRecipe!=null)
  93. {
  94. MoveItem pufToSrdItem = new MoveItem();
  95. pufToSrdItem.SourceModule = pufModule;
  96. //A面
  97. pufToSrdItem.SourceSlot = 0;
  98. pufToSrdItem.DestinationType = ModuleType.SRD;
  99. pufToSrdItem.SourceSlot = 0;
  100. pufToSrdItem.DestinationModule = ModuleName.Unknown;
  101. pufToSrdItem.RobotHand = Aitex.Sorter.Common.Hand.Blade1;
  102. SchedulerSequence backEfemRobotSequence = CreateEfemRobotSequence(pufToSrdItem,null,sequenceRecipe.SubstrateSize, ref index);
  103. schedulerSequences.Add(backEfemRobotSequence);
  104. SchedulerSequence srdSequence = CreateSRDSequence(srdRecipe, ref index);
  105. schedulerSequences.Add(srdSequence);
  106. MoveItem srdToLoadPortItem = new MoveItem();
  107. srdToLoadPortItem.SourceModule = ModuleName.Unknown;
  108. srdToLoadPortItem.SourceType = ModuleType.SRD;
  109. srdToLoadPortItem.SourceSlot = 0;
  110. srdToLoadPortItem.DestinationType = ModuleType.LoadPort;
  111. srdToLoadPortItem.DestinationModule = (ModuleName)waferInfo.OriginStation;
  112. srdToLoadPortItem.DestinationSlot = waferInfo.OriginSlot;
  113. srdToLoadPortItem.RobotHand = Aitex.Sorter.Common.Hand.Blade1;
  114. SchedulerSequence srdToLoadPortSequence = CreateEfemRobotSequence(srdToLoadPortItem,null,sequenceRecipe.SubstrateSize, ref index);
  115. schedulerSequences.Add(srdToLoadPortSequence);
  116. }
  117. else
  118. {
  119. LOG.WriteLog(eEvent.ERR_SEQUENCE, "System", $"{sequenceRecipe.Ppid} srd recipe is invalid");
  120. return new List<SchedulerSequence>();
  121. }
  122. }
  123. else
  124. {
  125. MoveItem pufToLoadPortItem=new MoveItem(pufModule,0,(ModuleName)waferInfo.OriginStation,
  126. waferInfo.OriginSlot,Aitex.Sorter.Common.Hand.Blade1);
  127. SchedulerSequence pufToLoaderSequence=CreateEfemRobotSequence(pufToLoadPortItem,null,sequenceRecipe.SubstrateSize, ref index);
  128. schedulerSequences.Add(pufToLoaderSequence);
  129. }
  130. return schedulerSequences;
  131. }
  132. /// <summary>
  133. /// 解析WaferHolder的所有工序
  134. /// </summary>
  135. /// <param name="waferHolderInfo"></param>
  136. /// <param name="sequenceRecipe"></param>
  137. /// <returns></returns>
  138. public List<SchedulerSequence> AnalyWaferHolderAllSchedulerSequence(WaferHolderInfo waferHolderInfo, SequenceRecipe sequenceRecipe,int productWaferCount,int dummyWaferCount)
  139. {
  140. int totalWaferCount = productWaferCount + dummyWaferCount;
  141. int index = 0;
  142. List<SchedulerSequence> schedulerSequences = new List<SchedulerSequence>();
  143. //Buffer To Loader
  144. ModuleName currentLocationModuleName = (ModuleName)Enum.Parse(typeof(ModuleName), waferHolderInfo.CurrentLocation);
  145. TransporterAction transporterAction = GenerateTransporterTransferAction(currentLocationModuleName, ModuleType.Buffer, ModuleName.Loader1, ModuleType.Loader);
  146. string strTRNP = AnalyseLoadTransporterSide(sequenceRecipe, productWaferCount,dummyWaferCount);
  147. List<SchedulerSyncModuleMessage> synModules = GenerateLoaderTransporterSyncModuleMessage(strTRNP);
  148. SchedulerSequence bufferToLoaderSequence = CreateLoaderTransporterSequence(transporterAction,synModules,waferHolderInfo.WaferSize, ref index);
  149. schedulerSequences.Add(bufferToLoaderSequence);
  150. //尺寸不一致
  151. bool needFlip = CheckLoaderWaferSizeNotEqual() && totalWaferCount == 2;
  152. //Loader
  153. LoaderParameter parameter = new LoaderParameter();
  154. parameter.WaferCount= needFlip?1: totalWaferCount;
  155. parameter.LoadCompleteToTransporterSide = strTRNP;
  156. parameter.NeedWaitFlip = needFlip;
  157. SchedulerSequence loaderSequence = CreateLoaderSequence(parameter,sequenceRecipe.SubstrateSize, ref index);
  158. schedulerSequences.Add(loaderSequence);
  159. if (needFlip)
  160. {
  161. string reverse = GetReverseTransporterLocation(strTRNP);
  162. TransporterAction flipAction = GenerateTransporterFlipAction(reverse);
  163. SchedulerSequence flipSequence=CreateLoaderTransporterSequence(flipAction,null,sequenceRecipe.SubstrateSize, ref index);
  164. schedulerSequences.Add(flipSequence);
  165. //Loader
  166. LoaderParameter reverseParameter = new LoaderParameter();
  167. reverseParameter.WaferCount = 1;
  168. reverseParameter.LoadCompleteToTransporterSide = reverse;
  169. reverseParameter.NeedWaitFlip = false;
  170. SchedulerSequence reverseLoadSequence = CreateLoaderSequence(reverseParameter,sequenceRecipe.SubstrateSize, ref index);
  171. schedulerSequences.Add(reverseLoadSequence);
  172. }
  173. //wafer holder装载后的recipe工序
  174. List<SchedulerSequence> waferHolderAfterLoadedAllSequences = WaferHolderAfterLoadedAllSchedulerSequences(waferHolderInfo, sequenceRecipe,ref index);
  175. schedulerSequences.AddRange(waferHolderAfterLoadedAllSequences);
  176. return schedulerSequences;
  177. }
  178. /// <summary>
  179. /// 解析LoaderTransporter放至Loader第一次确定TRNP的方向
  180. /// </summary>
  181. /// <param name="sequenceRecipe"></param>
  182. /// <param name="waferCount"></param>
  183. /// <returns></returns>
  184. private string AnalyseLoadTransporterSide(SequenceRecipe sequenceRecipe,int productWaferCount,int dummyWaferCount)
  185. {
  186. int sideAWaferSize = SC.GetValue<int>($"Loader1.SideAWaferSize");
  187. int sideBWaferSize = SC.GetValue<int>($"Loader1.SideBWaferSize");
  188. //单片,同时loader两边尺寸不一致
  189. if ((productWaferCount == 1||dummyWaferCount==1) && sideAWaferSize != sideBWaferSize)
  190. {
  191. //recipe使用B面工艺,但loader A面与recipe尺寸一致
  192. if (sequenceRecipe.LastSingleWaferToSideB && sequenceRecipe.SubstrateSize == sideAWaferSize)
  193. {
  194. return "TRNPB";
  195. }
  196. //recipe使用A面工艺,但loader B面与recipe尺寸一致
  197. else if (!sequenceRecipe.LastSingleWaferToSideB && sequenceRecipe.SubstrateSize == sideBWaferSize)
  198. {
  199. return "TRNPB";
  200. }
  201. }
  202. return "TRNPA";
  203. }
  204. private string GetReverseTransporterLocation(string strTrn)
  205. {
  206. return strTrn == TRNPA ? TRNPB : TRNPA;
  207. }
  208. /// <summary>
  209. /// 创建Transporter transfer指令
  210. /// </summary>
  211. /// <param name="source"></param>
  212. /// <param name="sourceType"></param>
  213. /// <param name="dest"></param>
  214. /// <param name="destType"></param>
  215. /// <returns></returns>
  216. private TransporterAction GenerateTransporterTransferAction(ModuleName source,ModuleType sourceType,ModuleName dest,ModuleType destType)
  217. {
  218. TransporterAction transporterAction = new TransporterAction();
  219. transporterAction.ActionMsg = TransporterMSG.Transfer;
  220. WaferHolderMoveItem waferHolderMoveItem = new WaferHolderMoveItem(source, sourceType, dest, destType);
  221. transporterAction.Parameter = waferHolderMoveItem;
  222. return transporterAction;
  223. }
  224. /// <summary>
  225. /// 创建Transporter pickup指令
  226. /// </summary>
  227. /// <param name="source"></param>
  228. /// <param name="sourceType"></param>
  229. /// <param name="dest"></param>
  230. /// <param name="destType"></param>
  231. /// <returns></returns>
  232. private TransporterAction GenerateTransporterFlipAction(string strTransporter)
  233. {
  234. TransporterAction transporterAction = new TransporterAction();
  235. transporterAction.ActionMsg = TransporterMSG.Flip;
  236. transporterAction.Parameter = strTransporter;
  237. return transporterAction;
  238. }
  239. /// <summary>
  240. /// 检验Loader两边waferSize不一致
  241. /// </summary>
  242. /// <returns></returns>
  243. private bool CheckLoaderWaferSizeNotEqual()
  244. {
  245. int sideAWaferSize = SC.GetValue<int>($"Loader1.SideAWaferSize");
  246. int sideBWaferSize = SC.GetValue<int>($"Loader1.SideBWaferSize");
  247. return sideAWaferSize != sideBWaferSize;
  248. }
  249. /// <summary>
  250. /// 创建LoaderTrasporter同步模块消息
  251. /// </summary>
  252. /// <param name="tranporter"></param>
  253. /// <returns></returns>
  254. private List<SchedulerSyncModuleMessage> GenerateLoaderTransporterSyncModuleMessage(string tranporter)
  255. {
  256. List<SchedulerSyncModuleMessage> synModules = new List<SchedulerSyncModuleMessage>();
  257. SchedulerSyncModuleMessage syncModuleMessage = new SchedulerSyncModuleMessage();
  258. syncModuleMessage.ModuleEntity = Singleton<RouteManager>.Instance.GetModule<IModuleEntity>(ModuleName.Loader1.ToString());
  259. syncModuleMessage.ModuleMsg = LoaderMSG.PrepareForPlace.ToString();
  260. syncModuleMessage.parameters = new object[] { tranporter };
  261. synModules.Add(syncModuleMessage);
  262. return synModules;
  263. }
  264. /// <summary>
  265. /// Dummy Wafer对应WaferHolder任务
  266. /// </summary>
  267. /// <param name="waferHolderInfo"></param>
  268. /// <returns></returns>
  269. public List<SchedulerSequence> AnalyseDummyWaferHolderAllSchedulerSequence(WaferHolderInfo waferHolderInfo,int productWaferCount,int dummyWaferCount)
  270. {
  271. int index = 0;
  272. List<SchedulerSequence> schedulerSequences = new List<SchedulerSequence>();
  273. string strTRNP = AnalyseLoadTransporterSide(waferHolderInfo.SequenceRecipe, productWaferCount,dummyWaferCount);
  274. //Buffer To Loader
  275. ModuleName currentLocationModuleName = (ModuleName)Enum.Parse(typeof(ModuleName), waferHolderInfo.CurrentLocation);
  276. ModuleName bufferModule = (ModuleName)Enum.Parse(typeof(ModuleName), waferHolderInfo.OriginalBuffer);
  277. List<SchedulerSyncModuleMessage> synModules = GenerateLoaderTransporterSyncModuleMessage(strTRNP);
  278. TransporterAction transporterAction = GenerateTransporterTransferAction(currentLocationModuleName, ModuleType.Buffer, ModuleName.Loader1, ModuleType.Loader);
  279. SchedulerSequence bufferToLoaderSequence = CreateLoaderTransporterSequence(transporterAction,synModules,waferHolderInfo.WaferSize, ref index);
  280. schedulerSequences.Add(bufferToLoaderSequence);
  281. //尺寸不一致
  282. bool needFlip = CheckLoaderWaferSizeNotEqual() && dummyWaferCount == 2;
  283. //Loader
  284. LoaderParameter parameter = new LoaderParameter();
  285. parameter.WaferCount = needFlip ? 1 : dummyWaferCount; ;
  286. parameter.LoadCompleteToTransporterSide = strTRNP;
  287. parameter.NeedWaitFlip = needFlip;
  288. SchedulerSequence loaderSequence = CreateLoaderSequence(parameter,waferHolderInfo.WaferSize,ref index);
  289. schedulerSequences.Add(loaderSequence);
  290. if (needFlip)
  291. {
  292. string reverse = GetReverseTransporterLocation(strTRNP);
  293. TransporterAction flipAction = GenerateTransporterFlipAction(reverse);
  294. SchedulerSequence flipSequence = CreateLoaderTransporterSequence(flipAction, null,waferHolderInfo.WaferSize, ref index);
  295. schedulerSequences.Add(flipSequence);
  296. //Loader
  297. LoaderParameter reverseParameter = new LoaderParameter();
  298. reverseParameter.WaferCount = 1;
  299. reverseParameter.LoadCompleteToTransporterSide = reverse;
  300. reverseParameter.NeedWaitFlip = false;
  301. SchedulerSequence reverseLoadSequence = CreateLoaderSequence(reverseParameter,waferHolderInfo.WaferSize, ref index);
  302. schedulerSequences.Add(reverseLoadSequence);
  303. }
  304. //Loader To Buffer
  305. TransporterAction loaderMoveToBufferAction=GenerateTransporterTransferAction (ModuleName.Loader1, ModuleType.Loader,
  306. bufferModule, ModuleType.Buffer);
  307. SchedulerSequence loaderToBufferSequence = CreateLoaderTransporterSequence(loaderMoveToBufferAction,null,waferHolderInfo.WaferSize, ref index);
  308. schedulerSequences.Add(loaderToBufferSequence);
  309. return schedulerSequences;
  310. }
  311. /// <summary>
  312. /// 解析Dummy Wafer所有调度工序
  313. /// </summary>
  314. /// <param name="sequenceRecipe"></param>
  315. /// <returns></returns>
  316. public List<SchedulerSequence> AnalyDummyWaferAllSchedulerSequence(SequenceRecipe sequenceRecipe,WaferInfo waferInfo, ModuleName pufModule,string side)
  317. {
  318. waferInfo.LoaderSide = side;
  319. List<SchedulerSequence> schedulerSequences = new List<SchedulerSequence>();
  320. int index = 0;
  321. //DummyCassete至Aligner
  322. MoveItem moveItem = new MoveItem((ModuleName)waferInfo.Station, waferInfo.Slot, ModuleName.Aligner1, 0, Aitex.Sorter.Common.Hand.Blade1);
  323. SchedulerSequence secondEfemRobotSequence = CreateEfemRobotSequence(moveItem, null,sequenceRecipe.SubstrateSize, ref index);
  324. schedulerSequences.Add(secondEfemRobotSequence);
  325. //Aligner
  326. SchedulerSequence alignerSequence = null;
  327. if (sequenceRecipe == null)
  328. {
  329. alignerSequence= CreateAlignerSequence(0,sequenceRecipe.SubstrateSize, ref index);
  330. }
  331. else
  332. {
  333. alignerSequence=CreateAlignerSequence(sequenceRecipe.AlignmentAngle,sequenceRecipe.SubstrateSize, ref index);
  334. }
  335. schedulerSequences.Add(alignerSequence);
  336. //Aligner至Puf
  337. MoveItem alignerToPufMoveItem = new MoveItem(ModuleName.Aligner1, 0, pufModule, 1, Aitex.Sorter.Common.Hand.Blade1);
  338. SchedulerSequence alignerToPufEfemRobotSequence = CreateEfemRobotSequence(alignerToPufMoveItem, null,sequenceRecipe.SubstrateSize, ref index);
  339. schedulerSequences.Add(alignerToPufEfemRobotSequence);
  340. SchedulerSequence pufSequence = CreatePufSequence(pufModule,sequenceRecipe, side,true, ref index);
  341. schedulerSequences.Add(pufSequence);
  342. return schedulerSequences;
  343. }
  344. /// <summary>
  345. /// Loader装载后Recipe工序
  346. /// </summary>
  347. /// <param name="waferHolderInfo"></param>
  348. /// <param name="sequenceRecipe"></param>
  349. /// <param name="index"></param>
  350. /// <returns></returns>
  351. private List<SchedulerSequence> WaferHolderAfterLoadedAllSchedulerSequences(WaferHolderInfo waferHolderInfo,SequenceRecipe sequenceRecipe,ref int index)
  352. {
  353. List<SchedulerSequence> schedulerSequences = new List<SchedulerSequence>();
  354. if(!Enum.TryParse(waferHolderInfo.OriginalBuffer,out ModuleName moduleName))
  355. {
  356. return schedulerSequences;
  357. }
  358. //Loader To Buffer
  359. TransporterAction loaderMoveToBufferAction = GenerateTransporterTransferAction(ModuleName.Loader1, ModuleType.Loader,
  360. moduleName, ModuleType.Buffer);
  361. SchedulerSequence loaderToBufferSequence = CreateLoaderTransporterSequence(loaderMoveToBufferAction,null,sequenceRecipe.SubstrateSize, ref index);
  362. schedulerSequences.Add(loaderToBufferSequence);
  363. //解析sequence recipe后续的工序
  364. var result = AnalyseSequenceRecipeScheduler(sequenceRecipe);
  365. //buffer to recipe第一个工序
  366. TransporterAction bufferToFirstAction = GenerateTransporterTransferAction(moduleName, ModuleType.Buffer, ModuleName.Unknown, result.firstModuleType);
  367. SchedulerSequence bufferSequence = CreateLoaderTransporterSequence(bufferToFirstAction,null,sequenceRecipe.SubstrateSize, ref index);
  368. schedulerSequences.Add(bufferSequence);
  369. //调整工序后面的索引
  370. foreach (SchedulerSequence item in result.sequences)
  371. {
  372. item.SequenceIndex = index;
  373. index++;
  374. }
  375. schedulerSequences.AddRange(result.sequences);
  376. //从recipe最后工序
  377. TransporterAction lastToBufferAction = GenerateTransporterTransferAction(ModuleName.Unknown, result.lastModuleType, moduleName, ModuleType.Buffer);
  378. SchedulerSequence lastToBufferSequence = CreateLoaderTransporterSequence(lastToBufferAction,null,sequenceRecipe.SubstrateSize, ref index);
  379. schedulerSequences.Add(lastToBufferSequence);
  380. return schedulerSequences;
  381. }
  382. /// <summary>
  383. /// 分析Sequence recipe对应的调度步骤
  384. /// </summary>
  385. /// <param name="sequenceRecipe"></param>
  386. /// <returns></returns>
  387. private (ModuleType firstModuleType,List<SchedulerSequence> sequences,ModuleType lastModuleType) AnalyseSequenceRecipeScheduler(SequenceRecipe sequenceRecipe)
  388. {
  389. ModuleType firstModuleType = default;
  390. ModuleType lastModuleType = default;
  391. List<SchedulerSequence> schedulerSequences= new List<SchedulerSequence>();
  392. List<SchedulerSequence> tmpLst = new List<SchedulerSequence>();
  393. var processResult = AnalyseLastProcessRecipeIndex(sequenceRecipe.Recipes);
  394. bool isExistSrd = sequenceRecipe.Recipes.FindIndex(O=>O.ToLower().EndsWith("srd.rcp"))!=-1;
  395. int lastIndex = isExistSrd ? sequenceRecipe.Recipes.Count - 2 : sequenceRecipe.Recipes.Count - 1;
  396. for(int i=0;i<sequenceRecipe.Recipes.Count;i++)
  397. {
  398. string item = sequenceRecipe.Recipes[i];
  399. if(item.ToLower().EndsWith("srd.rcp"))//跳过SRD
  400. {
  401. continue;
  402. }
  403. SchedulerSequence schedulerSequence = new SchedulerSequence();
  404. schedulerSequence.ModuleName = ModuleName.Unknown;
  405. schedulerSequence.ModuleType=SequenceRecipeManager.Instance.GetModuleType(item);
  406. schedulerSequence.SequenceIndex=i;
  407. schedulerSequence.WaferSize = sequenceRecipe.SubstrateSize;
  408. MECF.Framework.Common.RecipeCenter.RecipeType recipeType =SequenceRecipeManager.Instance.GetRecipeType(item);
  409. schedulerSequence.Recipe = SequenceRecipeManager.Instance.LoadSequenceTypeRecipe(sequenceRecipe.SequenceType,item, recipeType);
  410. schedulerSequence.SequenceType = sequenceRecipe.SequenceType;
  411. schedulerSequence.State = RState.Init;
  412. schedulerSequence.MaterialType = MaterialType.WaferHolder;
  413. tmpLst.Add(schedulerSequence);
  414. if (i == 0)
  415. {
  416. firstModuleType = schedulerSequence.ModuleType;
  417. }
  418. if(i==lastIndex)
  419. {
  420. lastModuleType = schedulerSequence.ModuleType;
  421. }
  422. else
  423. {
  424. string nextModule = sequenceRecipe.Recipes[i + 1];
  425. schedulerSequence.NextModuleType= SequenceRecipeManager.Instance.GetModuleType(nextModule);
  426. MECF.Framework.Common.RecipeCenter.RecipeType nextRecipeType = SequenceRecipeManager.Instance.GetRecipeType(nextModule);
  427. schedulerSequence.NextRecipe= SequenceRecipeManager.Instance.LoadSequenceTypeRecipe(sequenceRecipe.SequenceType,nextModule,nextRecipeType);
  428. }
  429. schedulerSequence.IsProcessSequece = true;
  430. if(i==processResult.lastIndex)
  431. {
  432. schedulerSequence.IsLastProcessSequence = true;
  433. }
  434. }
  435. int index = 0;
  436. for(int i=0;i<tmpLst.Count;i++)
  437. {
  438. tmpLst[i].SequenceIndex = 0;
  439. schedulerSequences.Add(tmpLst[i]);
  440. index++;
  441. if(i<tmpLst.Count-1)
  442. {
  443. TransporterAction transporterAction = new TransporterAction();
  444. transporterAction.ActionMsg = TransporterMSG.Transfer;
  445. WaferHolderMoveItem moveItem = new WaferHolderMoveItem(ModuleName.Unknown, tmpLst[i].ModuleType, ModuleName.Unknown, tmpLst[i + 1].ModuleType);
  446. transporterAction.Parameter = moveItem;
  447. SchedulerSequence schedulerSequence=CreateProcessTransporterSequence(transporterAction,sequenceRecipe.SubstrateSize,ref index);
  448. schedulerSequences.Add(schedulerSequence);
  449. }
  450. }
  451. return (firstModuleType,schedulerSequences,lastModuleType);
  452. }
  453. /// <summary>
  454. /// 分析最后加工recipe索引
  455. /// </summary>
  456. /// <param name="recipes"></param>
  457. /// <returns></returns>
  458. private (int lastIndex,List<int> processIndexList) AnalyseLastProcessRecipeIndex(List<string> recipes)
  459. {
  460. int index = 0;
  461. List<int> lst = new List<int>();
  462. for(int i=0;i<recipes.Count; i++)
  463. {
  464. string item=recipes[i];
  465. if(item.ToLower().EndsWith("dep.rcp"))
  466. {
  467. index = i;
  468. if(lst.Contains(i))
  469. {
  470. lst.Add(i);
  471. }
  472. }
  473. }
  474. if(lst.Count==0)
  475. {
  476. lst.Add(0);
  477. }
  478. return (index,lst);
  479. }
  480. /// <summary>
  481. /// 创建EFEM Robot步骤
  482. /// </summary>
  483. /// <param name="index"></param>
  484. /// <returns></returns>
  485. private SchedulerSequence CreateEfemRobotSequence(MoveItem moveItem,List<SchedulerSyncModuleMessage> synModules,int waferSize,ref int index)
  486. {
  487. SchedulerSequence sequence = new SchedulerSequence();
  488. sequence.SchedulerModule = SchedulerManager.Instance.GetScheduler(ModuleName.EfemRobot);
  489. sequence.SequenceIndex= index;
  490. sequence.ModuleName=ModuleName.EfemRobot;
  491. sequence.State = RState.Init;
  492. sequence.Recipe = null;
  493. sequence.ModuleType=ModuleType.EfemRobot;
  494. sequence.Parameters =moveItem;
  495. sequence.MaterialType = MaterialType.Wafer;
  496. sequence.SynchronousModuleMessages = synModules;
  497. sequence.WaferSize = waferSize;
  498. index++;
  499. return sequence;
  500. }
  501. /// <summary>
  502. /// 创建Aligner步骤
  503. /// </summary>
  504. /// <param name="index"></param>
  505. /// <returns></returns>
  506. private SchedulerSequence CreateAlignerSequence(double angle,int waferSize,ref int index)
  507. {
  508. SchedulerSequence sequence = new SchedulerSequence();
  509. sequence.SchedulerModule = SchedulerManager.Instance.GetScheduler(ModuleName.Aligner1);
  510. sequence.SequenceIndex = index;
  511. sequence.ModuleName = ModuleName.Aligner1;
  512. sequence.State = RState.Init;
  513. sequence.Recipe = null;
  514. sequence.ModuleType = ModuleType.Aligner;
  515. sequence.Parameters = angle;
  516. sequence.MaterialType = MaterialType.Wafer;
  517. sequence.WaferSize = waferSize;
  518. index++;
  519. return sequence;
  520. }
  521. /// <summary>
  522. /// 创建PUF步骤
  523. /// </summary>
  524. /// <param name="pufModuleName"></param>
  525. /// <param name="index"></param>
  526. /// <returns></returns>
  527. private SchedulerSequence CreatePufSequence(ModuleName pufModuleName,SequenceRecipe sequenceRecipe,string side,bool forward,ref int index)
  528. {
  529. SchedulerSequence sequence = new SchedulerSequence();
  530. sequence.SchedulerModule = SchedulerManager.Instance.GetScheduler(pufModuleName);
  531. sequence.SequenceIndex = index;
  532. sequence.ModuleName = pufModuleName;
  533. sequence.State = RState.Init;
  534. sequence.Recipe = sequenceRecipe;
  535. PufSchedulerParameter parameter = new PufSchedulerParameter()
  536. {
  537. IsForward = forward,
  538. Side = side,
  539. };
  540. sequence.Parameters = parameter;
  541. sequence.IsWaitNotify = !forward;
  542. sequence.ModuleType = ModuleType.PUF;
  543. sequence.MaterialType = MaterialType.Wafer;
  544. sequence.WaferSize = sequenceRecipe.SubstrateSize;
  545. index++;
  546. return sequence;
  547. }
  548. /// <summary>
  549. /// 创建Loader步骤
  550. /// </summary>
  551. /// <param name="index"></param>
  552. /// <returns></returns>
  553. private SchedulerSequence CreateLoaderSequence(LoaderParameter parameter,int waferSize,ref int index)
  554. {
  555. SchedulerSequence sequence = new SchedulerSequence();
  556. sequence.SchedulerModule = SchedulerManager.Instance.GetScheduler(ModuleName.Loader1);
  557. sequence.SequenceIndex = index;
  558. sequence.ModuleName = ModuleName.Loader1;
  559. sequence.State = RState.Init;
  560. sequence.Recipe = null;
  561. sequence.Parameters = parameter;
  562. sequence.ModuleType = ModuleType.Loader;
  563. sequence.MaterialType = MaterialType.WaferHolder;
  564. sequence.WaferSize = waferSize;
  565. index++;
  566. return sequence;
  567. }
  568. /// <summary>
  569. /// 创建Loader步骤
  570. /// </summary>
  571. /// <param name="index"></param>
  572. /// <returns></returns>
  573. private SchedulerSequence CreateSRDSequence(SrdRecipe recipe,ref int index)
  574. {
  575. SchedulerSequence sequence = new SchedulerSequence();
  576. sequence.SequenceIndex = index;
  577. sequence.State = RState.Init;
  578. sequence.Recipe = recipe;
  579. sequence.ModuleType = ModuleType.SRD;
  580. sequence.MaterialType = MaterialType.Wafer;
  581. index++;
  582. return sequence;
  583. }
  584. /// <summary>
  585. /// 创建LoaderTransporter步骤
  586. /// </summary>
  587. /// <param name="index"></param>
  588. /// <returns></returns>
  589. private SchedulerSequence CreateLoaderTransporterSequence(TransporterAction transporterAction, List<SchedulerSyncModuleMessage> synModules,int waferSize, ref int index)
  590. {
  591. SchedulerSequence sequence = new SchedulerSequence();
  592. sequence.ModuleType = ModuleType.Transporter;
  593. sequence.ModuleName = ModuleName.Transporter2;
  594. sequence.SequenceIndex = index;
  595. sequence.State = RState.Init;
  596. sequence.Recipe = null;
  597. sequence.SchedulerModule = SchedulerManager.Instance.GetScheduler(ModuleName.Transporter2);
  598. sequence.Parameters = transporterAction;
  599. sequence.MaterialType = MaterialType.WaferHolder;
  600. sequence.SynchronousModuleMessages = synModules;
  601. sequence.WaferSize = waferSize;
  602. index++;
  603. return sequence;
  604. }
  605. /// <summary>
  606. /// 创建LoaderTransporter步骤
  607. /// </summary>
  608. /// <param name="index"></param>
  609. /// <returns></returns>
  610. private SchedulerSequence CreateProcessTransporterSequence(TransporterAction transporterAction,int waferSize, ref int index)
  611. {
  612. SchedulerSequence sequence = new SchedulerSequence();
  613. sequence.ModuleType = ModuleType.Transporter;
  614. sequence.ModuleName = ModuleName.Transporter1;
  615. sequence.SequenceIndex = index;
  616. sequence.State = RState.Init;
  617. sequence.Recipe = null;
  618. sequence.SchedulerModule = SchedulerManager.Instance.GetScheduler(ModuleName.Transporter1);
  619. sequence.Parameters= transporterAction;
  620. sequence.MaterialType = MaterialType.WaferHolder;
  621. sequence.WaferSize = waferSize;
  622. index++;
  623. return sequence;
  624. }
  625. /// <summary>
  626. /// 获取可用Dummy slot
  627. /// </summary>
  628. /// <param name="moduleType"></param>
  629. /// <returns></returns>
  630. public (ModuleName moduleName, int slot) GetAvaibleDummySlots(WaferSize waferSize)
  631. {
  632. if (ModuleHelper.IsInstalled(ModuleName.Dummy1))
  633. {
  634. DummyEntity dummyEntity = Singleton<RouteManager>.Instance.GetModule<DummyEntity>(ModuleName.Dummy1.ToString());
  635. DummyDevice dummyDevice = Singleton<RouteManager>.Instance.EFEM.GetDummyDevice(0);
  636. if (dummyDevice != null && dummyDevice.HasCassette && dummyDevice.WaferSize == waferSize)
  637. {
  638. for (int i = 0; i < dummyEntity.MaxSlotNumber; i++)
  639. {
  640. if (WaferManager.Instance.CheckNoWafer(ModuleName.Dummy1, i))
  641. {
  642. return (ModuleName.Dummy1, i);
  643. }
  644. }
  645. }
  646. }
  647. if (ModuleHelper.IsInstalled(ModuleName.Dummy2))
  648. {
  649. DummyEntity dummyEntity = Singleton<RouteManager>.Instance.GetModule<DummyEntity>(ModuleName.Dummy2.ToString());
  650. DummyDevice dummyDevice = Singleton<RouteManager>.Instance.EFEM.GetDummyDevice(1);
  651. if (dummyDevice != null && dummyDevice.HasCassette && dummyDevice.WaferSize == waferSize)
  652. {
  653. for (int i = 0; i < dummyEntity.MaxSlotNumber; i++)
  654. {
  655. if (WaferManager.Instance.CheckNoWafer(ModuleName.Dummy2, i))
  656. {
  657. return (ModuleName.Dummy2, i);
  658. }
  659. }
  660. }
  661. }
  662. return (ModuleName.Unknown, -1);
  663. }
  664. /// <summary>
  665. /// 根据模块类型获取可用模块
  666. /// </summary>
  667. /// <param name="moduleType"></param>
  668. /// <returns></returns>
  669. public ModuleName GetAvaibleModuleCell(string sequenceType,ModuleType moduleType, ModuleName moduleName = ModuleName.Unknown)
  670. {
  671. if (ModuleHelper.IsMetal(moduleName))
  672. {
  673. List<IModuleEntity> entities = Singleton<RouteManager>.Instance.GetModulesByModuleType(moduleType);
  674. return GetMetalAvaibleRinseModule(entities, moduleName);
  675. }
  676. else
  677. {
  678. List<IModuleEntity> entities = Singleton<RouteManager>.Instance.GetModulesByModuleType(moduleType);
  679. List<IModuleEntity> avaibles = new List<IModuleEntity>();
  680. foreach (var item in entities)
  681. {
  682. bool result = CheckAvaibleModule(item,moduleType,sequenceType);
  683. if (result)
  684. {
  685. avaibles.Add(item);
  686. }
  687. }
  688. return GetMinTimeToReadyModule(avaibles,moduleType);
  689. }
  690. }
  691. /// <summary>
  692. /// 根据模块类型获取可用模块(不包含WH)
  693. /// </summary>
  694. /// <param name="moduleType"></param>
  695. /// <returns></returns>
  696. public ModuleName GetAvaibleEmptyModuleCell(ModuleType moduleType,string sequenceType, ModuleName moduleName = ModuleName.Unknown)
  697. {
  698. if (ModuleHelper.IsMetal(moduleName))
  699. {
  700. List<IModuleEntity> entities = Singleton<RouteManager>.Instance.GetModulesByModuleType(moduleType);
  701. return GetMetalAvaibleEmptyRinseModule(entities, moduleName);
  702. }
  703. else
  704. {
  705. List<IModuleEntity> entities = Singleton<RouteManager>.Instance.GetModulesByModuleType(moduleType);
  706. List<IModuleEntity> avaibles = new List<IModuleEntity>();
  707. foreach (var item in entities)
  708. {
  709. bool result = CheckAvaibleModule(item,moduleType,sequenceType);
  710. if (result&&!WaferHolderManager.Instance.HasWaferHolder(item.Module.ToString()))
  711. {
  712. avaibles.Add(item);
  713. }
  714. }
  715. return avaibles.Count != 0 ? avaibles[0].Module : ModuleName.Unknown;
  716. }
  717. }
  718. /// <summary>
  719. /// 根据化学液计算时间获取可用MetalCell(参考其他Metal剩余时间)
  720. /// </summary>
  721. /// <param name="chemistry"></param>
  722. /// <returns></returns>
  723. public ModuleName CalculateAvaibleMetalCellByChemistry(string chemistry,string startRinse,string sequenceType,int waferSize,ref bool isExistEnableMetal)
  724. {
  725. if(!Enum.TryParse(startRinse,out ModuleName startRinseModule)||!ModuleHelper.IsRinse(startRinseModule))
  726. {
  727. startRinse = "";
  728. }
  729. isExistEnableMetal = false;
  730. List<MetalEntity> moduleEntities = GetAvaibleMetalList(chemistry,sequenceType,waferSize,true);
  731. List<IModuleEntity> avaibleMetalEntities = new List<IModuleEntity>();
  732. foreach (var item in moduleEntities)
  733. {
  734. if(CheckAvaibleModule(item,ModuleType.Metal,sequenceType))
  735. {
  736. if (item.WaferHolderInfo == null)
  737. {
  738. if (CheckMetalModuleRinseAvaible(item, startRinse))
  739. {
  740. avaibleMetalEntities.Add(item);
  741. }
  742. }
  743. isExistEnableMetal = true;
  744. }
  745. }
  746. if (avaibleMetalEntities.Count > 0)
  747. {
  748. return GetMinUsageMetal(avaibleMetalEntities);
  749. }
  750. return ModuleName.Unknown;
  751. }
  752. /// <summary>
  753. /// 根据化学液获取可用Metal
  754. /// </summary>
  755. /// <param name="chemistry"></param>
  756. /// <param name="sequenceType"></param>
  757. /// <returns></returns>
  758. public bool CalculateAvaibleMetalCellByChemistry(string chemistry,string sequenceType,int waferSize)
  759. {
  760. List<MetalEntity> moduleEntities = GetAvaibleMetalList(chemistry, sequenceType,waferSize,false);
  761. return moduleEntities.Count != 0;
  762. }
  763. /// <summary>
  764. /// 检验Metal模块Rinse可用性
  765. /// </summary>
  766. /// <param name="item"></param>
  767. /// <returns></returns>
  768. private bool CheckMetalModuleRinseAvaible(MetalEntity item,string startRinse)
  769. {
  770. List<LayoutCellItem> rinseItems = CellItemManager.Instance.GetRinseItemsByMetal(item.Module.ToString());
  771. List<string> sharedRinseItems = new List<string>();
  772. List<string> singleRinseItems = new List<string>();
  773. foreach (var cellItem in rinseItems)
  774. {
  775. RinseEntity rinseEntity = Singleton<RouteManager>.Instance.GetModule<RinseEntity>(cellItem.ModuleName);
  776. if (!CellItemManager.Instance.CheckRinseIsShared(cellItem.ModuleName))
  777. {
  778. if (CheckAvaibleModule(rinseEntity, ModuleType.Rinse, "") && rinseEntity.WaferHolderInfo == null)
  779. {
  780. singleRinseItems.Add(cellItem.ModuleName);
  781. }
  782. }
  783. else
  784. {
  785. if (CheckAvaibleModule(rinseEntity,ModuleType.Rinse,"") && rinseEntity.WaferHolderInfo == null)
  786. {
  787. sharedRinseItems.Add(cellItem.ModuleName);
  788. }
  789. //增加自己
  790. if (cellItem.ModuleName == startRinse && rinseEntity != null && (rinseEntity.IsIdle||rinseEntity.State==(int)RinseState.KeepWeting))
  791. {
  792. sharedRinseItems.Add(startRinse);
  793. }
  794. }
  795. }
  796. //独立的Rinse集合
  797. if(singleRinseItems.Count!=0)
  798. {
  799. bool result = CheckSingleRinseItemsCanUsed(singleRinseItems, item.Module.ToString());
  800. if(result)
  801. {
  802. return true;
  803. }
  804. }
  805. //仅剩下共享Rinse
  806. List<string> avaibleSharedList = new List<string>();
  807. if (sharedRinseItems.Count != 0)
  808. {
  809. foreach (string sharedRinse in sharedRinseItems)
  810. {
  811. RinseEntity rinseEntity = Singleton<RouteManager>.Instance.GetModule<RinseEntity>(sharedRinse);
  812. if (rinseEntity.IsBusy&&sharedRinse!=startRinse)
  813. {
  814. continue;
  815. }
  816. //检验共享Rinse是否可用
  817. if (CheckShardRinseCanUse(sharedRinse, item.Module.ToString(),startRinse))
  818. {
  819. avaibleSharedList.Add(sharedRinse);
  820. }
  821. }
  822. }
  823. if (avaibleSharedList.Count != 0)
  824. {
  825. var result = CalculateMetalReservoirAllBusyMetalCount(item.Module.ToString());
  826. if (result.success)
  827. {
  828. bool transporterTransfering = CheckProcessTransporterTransfering(avaibleSharedList);
  829. if(transporterTransfering)
  830. {
  831. return result.busyCount + 1 < avaibleSharedList.Count;
  832. }
  833. else
  834. {
  835. return result.busyCount < avaibleSharedList.Count+singleRinseItems.Count;
  836. }
  837. }
  838. }
  839. return false;
  840. }
  841. /// <summary>
  842. /// 检验Process transporter正在Transfer WH移动至Rinse
  843. /// </summary>
  844. /// <returns></returns>
  845. private bool CheckProcessTransporterTransfering(List<string> rinseList)
  846. {
  847. TransporterEntity processTransporterEntity = Singleton<RouteManager>.Instance.GetModule<TransporterEntity>(ModuleName.Transporter1.ToString());
  848. if(processTransporterEntity!=null)
  849. {
  850. if (processTransporterEntity.IsBusy)
  851. {
  852. string targetCell = processTransporterEntity.TargetCell;
  853. if (rinseList.Contains(targetCell))
  854. {
  855. return true;
  856. }
  857. }
  858. }
  859. return false;
  860. }
  861. /// <summary>
  862. /// 计算Metal所在Reservoir Busy Metal数量
  863. /// </summary>
  864. /// <param name="item"></param>
  865. /// <returns></returns>
  866. private (bool success,int busyCount) CalculateMetalReservoirAllBusyMetalCount(string metalName)
  867. {
  868. string reservoirName = ReservoirItemManager.Instance.GetReservoirByMetal(metalName);
  869. if (string.IsNullOrEmpty(reservoirName))
  870. {
  871. return (false,0);
  872. }
  873. List<string> metals = ReservoirItemManager.Instance.GetMetalsByReservoir(reservoirName);
  874. int count = 0;
  875. foreach (string item in metals)
  876. {
  877. if (metalName == item)
  878. {
  879. continue;
  880. }
  881. MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(item);
  882. if (metalEntity.IsBusy || metalEntity.WaferHolderInfo != null)
  883. {
  884. count++;
  885. }
  886. }
  887. return (true,count);
  888. }
  889. /// <summary>
  890. /// 检验独立Rinse是否可用
  891. /// </summary>
  892. /// <param name="singleRinseItems"></param>
  893. /// <param name="metalName"></param>
  894. /// <returns></returns>
  895. private bool CheckSingleRinseItemsCanUsed(List<string> singleRinseItems, string metalName)
  896. {
  897. var result = CalculateMetalReservoirAllBusyMetalCount(metalName);
  898. if(result.success)
  899. {
  900. bool transporterTransfering = CheckProcessTransporterTransfering(singleRinseItems);
  901. if (transporterTransfering)
  902. {
  903. return result.busyCount + 1 < singleRinseItems.Count;
  904. }
  905. else
  906. {
  907. return result.busyCount < singleRinseItems.Count;
  908. }
  909. }
  910. return false;
  911. }
  912. /// <summary>
  913. /// 检验共享Rinse是否可用
  914. /// </summary>
  915. /// <param name="sharedRinse"></param>
  916. /// <param name="metalName"></param>
  917. /// <returns></returns>
  918. private bool CheckShardRinseCanUse(string sharedRinse, string metalName,string startRinse)
  919. {
  920. string reservoirName = ReservoirItemManager.Instance.GetReservoirByMetal(metalName);
  921. List<string> shardReservoirs = CellItemManager.Instance.GetReservoirsBySharedRinse(sharedRinse);
  922. if (shardReservoirs == null || shardReservoirs.Count == 0)
  923. {
  924. return false;
  925. }
  926. foreach (string reservoir in shardReservoirs)
  927. {
  928. if (reservoir==reservoirName)
  929. {
  930. continue;
  931. }
  932. List<string> metals=ReservoirItemManager.Instance.GetMetalsByReservoir(reservoir);
  933. int metalCount = 0;
  934. int busyMetalCount = 0;
  935. foreach(string metal in metals)
  936. {
  937. MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(metal);
  938. if(metalEntity.IsAuto&&metalEntity.IsInitialized)
  939. {
  940. metalCount++;
  941. }
  942. if(metalEntity.IsBusy||metalEntity.WaferHolderInfo!=null)
  943. {
  944. busyMetalCount++;
  945. }
  946. }
  947. List<string> reservoirRinseLst = CellItemManager.Instance.GetRinsesByReservoir(reservoir);
  948. int rinseCount = 0;
  949. int busyRinseCount = 0;
  950. foreach(string rinseItem in reservoirRinseLst)
  951. {
  952. RinseEntity rinseEntity = Singleton<RouteManager>.Instance.GetModule<RinseEntity>(rinseItem);
  953. if(rinseEntity.IsAuto&&rinseEntity.IsInitialized)
  954. {
  955. rinseCount++;
  956. }
  957. if (rinseItem == sharedRinse)
  958. {
  959. continue;
  960. }
  961. if (rinseItem == startRinse)
  962. {
  963. continue;
  964. }
  965. if(rinseEntity.IsBusy||rinseEntity.WaferHolderInfo!=null)
  966. {
  967. busyRinseCount++;
  968. }
  969. }
  970. int resRinseCount=rinseCount- busyRinseCount;
  971. //计算剩余Rinse数量小于等于busy metal数量,则不可用
  972. if (resRinseCount <= busyMetalCount)
  973. {
  974. return false;
  975. }
  976. }
  977. return true;
  978. }
  979. /// <summary>
  980. /// 检验模块是否可用(不包含WH)
  981. /// </summary>
  982. /// <param name="item"></param>
  983. /// <returns></returns>
  984. private bool CheckAvaibleEmptyModule(IModuleEntity item,ModuleType moduleType,string sequenceType)
  985. {
  986. if (!CheckAvaibleModule(item, moduleType, sequenceType))
  987. {
  988. return false;
  989. }
  990. if (!ModuleHelper.IsSRD(item.Module))
  991. {
  992. WaferHolderInfo waferHolderInfo = WaferHolderManager.Instance.GetWaferHolder(item.Module.ToString());
  993. if (waferHolderInfo == null)
  994. {
  995. return true;
  996. }
  997. }
  998. else
  999. {
  1000. if (!WaferManager.Instance.CheckHasWafer(item.Module, 0))
  1001. {
  1002. return true;
  1003. }
  1004. }
  1005. return false;
  1006. }
  1007. /// <summary>
  1008. /// 检验模块是否可用
  1009. /// </summary>
  1010. /// <param name="item"></param>
  1011. /// <returns></returns>
  1012. public bool CheckAvaibleModule(IModuleEntity item,ModuleType moduleType,string sequenceType)
  1013. {
  1014. if (item.IsDisable)
  1015. {
  1016. return false;
  1017. }
  1018. if (!item.IsAuto)
  1019. {
  1020. return false;
  1021. }
  1022. if (item.IsError)
  1023. {
  1024. return false;
  1025. }
  1026. if (item.IsInit)
  1027. {
  1028. return false;
  1029. }
  1030. if (moduleType==ModuleType.Metal)
  1031. {
  1032. if(item.IsProduction && sequenceType == ENGINEERING)
  1033. return false;
  1034. if (item.IsEngineering && sequenceType == PRODUCTION)
  1035. return false;
  1036. }
  1037. return true;
  1038. }
  1039. /// <summary>
  1040. /// 获取剩余时间最小的模块
  1041. /// </summary>
  1042. /// <param name="avaibles"></param>
  1043. /// <returns></returns>
  1044. private ModuleName GetMinTimeToReadyModule(List<IModuleEntity> avaibles,ModuleType moduleType)
  1045. {
  1046. if (avaibles.Count == 1)
  1047. {
  1048. return avaibles[0].Module;
  1049. }
  1050. int timeToReady = int.MaxValue;
  1051. IModuleEntity selectedModule = null;
  1052. List<IModuleEntity> idleModuleEtities = new List<IModuleEntity>();
  1053. foreach (var item in avaibles)
  1054. {
  1055. if (item.IsIdle)
  1056. {
  1057. if(moduleType!=ModuleType.Metal)
  1058. {
  1059. return item.Module;
  1060. }
  1061. idleModuleEtities.Add(item);
  1062. }
  1063. if (item.TimeToReady < timeToReady&&idleModuleEtities.Count==0)
  1064. {
  1065. timeToReady = item.TimeToReady;
  1066. selectedModule = item;
  1067. }
  1068. }
  1069. if (idleModuleEtities.Count != 0)
  1070. {
  1071. return GetMinUsageMetal(idleModuleEtities);
  1072. }
  1073. if (selectedModule != null)
  1074. {
  1075. return selectedModule.Module;
  1076. }
  1077. return ModuleName.Unknown;
  1078. }
  1079. /// <summary>
  1080. /// 获取电量最小的Metal
  1081. /// </summary>
  1082. /// <param name="idleModuleEntities"></param>
  1083. /// <returns></returns>
  1084. private ModuleName GetMinUsageMetal(List<IModuleEntity> idleModuleEntities)
  1085. {
  1086. double usage = double.MaxValue;
  1087. ModuleName selectedModuleName = ModuleName.Unknown;
  1088. foreach (var item in idleModuleEntities)
  1089. {
  1090. MetalEntity metalEntity= item as MetalEntity;
  1091. if(metalEntity!=null)
  1092. {
  1093. MetalUsage metalUsage = metalEntity.MetalUsage;
  1094. if (metalUsage == null)
  1095. {
  1096. return metalEntity.Module;
  1097. }
  1098. if (metalUsage.TotalUsage < usage)
  1099. {
  1100. usage= metalUsage.TotalUsage;
  1101. selectedModuleName = metalEntity.Module;
  1102. }
  1103. }
  1104. }
  1105. return selectedModuleName;
  1106. }
  1107. /// <summary>
  1108. /// 获取Metal可用的Rinse模块
  1109. /// </summary>
  1110. /// <param name="metalName"></param>
  1111. /// <returns></returns>
  1112. private ModuleName GetMetalAvaibleRinseModule(List<IModuleEntity> items, ModuleName metalName)
  1113. {
  1114. int metalId = CellItemManager.Instance.GetCellIdByModuleName(metalName.ToString());
  1115. if (metalId == 0)
  1116. {
  1117. return ModuleName.Unknown;
  1118. }
  1119. List<LayoutCellItem> rinseItems = CellItemManager.Instance.GetRinseItemsByMetal(metalName.ToString());
  1120. if (rinseItems.Count == 0)
  1121. {
  1122. return ModuleName.Unknown;
  1123. }
  1124. List<IModuleEntity> avaibles = new List<IModuleEntity>();
  1125. foreach (var item in items)
  1126. {
  1127. LayoutCellItem cellItem = rinseItems.Find(O => O.ModuleName == item.Module.ToString());
  1128. if (cellItem != null)
  1129. {
  1130. RinseEntity rinseEntity = (RinseEntity)item;
  1131. if (rinseEntity.IsInitialized && rinseEntity.IsAuto)
  1132. {
  1133. avaibles.Add(rinseEntity);
  1134. }
  1135. }
  1136. }
  1137. int minInterval = int.MaxValue;
  1138. IModuleEntity moduleEntity = null;
  1139. foreach (var item in avaibles)
  1140. {
  1141. LayoutCellItem cellItem = rinseItems.Find(O => O.ModuleName == item.Module.ToString());
  1142. if (cellItem != null)
  1143. {
  1144. int abiasId = Math.Abs(metalId - cellItem.CellID);
  1145. if (abiasId < minInterval)
  1146. {
  1147. minInterval = abiasId;
  1148. moduleEntity = item;
  1149. }
  1150. }
  1151. }
  1152. if (moduleEntity != null)
  1153. {
  1154. return moduleEntity.Module;
  1155. }
  1156. return ModuleName.Unknown;
  1157. }
  1158. /// <summary>
  1159. /// 检验Metal可用的Rinse模块
  1160. /// </summary>
  1161. /// <param name="metalName"></param>
  1162. /// <returns></returns>
  1163. private ModuleName GetMetalAvaibleEmptyRinseModule(List<IModuleEntity> items, ModuleName metalName)
  1164. {
  1165. int metalId = CellItemManager.Instance.GetCellIdByModuleName(metalName.ToString());
  1166. if (metalId == 0)
  1167. {
  1168. return ModuleName.Unknown;
  1169. }
  1170. List<LayoutCellItem> rinseItems = CellItemManager.Instance.GetRinseItemsByMetal(metalName.ToString());
  1171. if (rinseItems.Count == 0)
  1172. {
  1173. return ModuleName.Unknown;
  1174. }
  1175. List<IModuleEntity> avaibles = new List<IModuleEntity>();
  1176. List<ModuleName> sharedRinseList = new List<ModuleName>();
  1177. foreach (var item in items)
  1178. {
  1179. LayoutCellItem cellItem = rinseItems.Find(O => O.ModuleName == item.Module.ToString());
  1180. if (cellItem != null)
  1181. {
  1182. RinseEntity rinseEntity = (RinseEntity)item;
  1183. if (rinseEntity.IsIdle && rinseEntity.IsAuto && rinseEntity.WaferHolderInfo == null)
  1184. {
  1185. avaibles.Add(rinseEntity);
  1186. if(CellItemManager.Instance.CheckRinseIsShared(rinseEntity.Module.ToString()))
  1187. {
  1188. sharedRinseList.Add(rinseEntity.Module);
  1189. }
  1190. }
  1191. }
  1192. }
  1193. int minInterval = int.MaxValue;
  1194. IModuleEntity moduleEntity = null;
  1195. foreach (var item in avaibles)
  1196. {
  1197. if (sharedRinseList.Contains(item.Module))
  1198. {
  1199. continue;
  1200. }
  1201. LayoutCellItem cellItem = rinseItems.Find(O => O.ModuleName == item.Module.ToString());
  1202. if (cellItem != null)
  1203. {
  1204. int abiasId = Math.Abs(metalId - cellItem.CellID);
  1205. if (abiasId < minInterval)
  1206. {
  1207. minInterval = abiasId;
  1208. moduleEntity = item;
  1209. }
  1210. }
  1211. }
  1212. if (moduleEntity != null)
  1213. {
  1214. return moduleEntity.Module;
  1215. }
  1216. else if(sharedRinseList.Count!=0)
  1217. {
  1218. return sharedRinseList[0];
  1219. }
  1220. return ModuleName.Unknown;
  1221. }
  1222. /// <summary>
  1223. /// 检验Metal cell recipe时间是否可用
  1224. /// </summary>
  1225. /// <param name="depRecipe"></param>
  1226. /// <returns></returns>
  1227. public bool CheckMetalCellRecipeTimeAvaible(IModuleEntity metalEntity,DepRecipe depRecipe)
  1228. {
  1229. List<IModuleEntity> metalEntities=Singleton<RouteManager>.Instance.GetModulesByModuleType(ModuleType.Metal);
  1230. int maxTimeToReady = 0;
  1231. foreach (MetalEntity item in metalEntities)
  1232. {
  1233. if (metalEntity.Module == item.Module)
  1234. {
  1235. continue;
  1236. }
  1237. if(item.IsBusy)
  1238. {
  1239. if(maxTimeToReady>item.TimeToReady)
  1240. {
  1241. maxTimeToReady = item.TimeToReady;
  1242. }
  1243. }
  1244. }
  1245. int transferOffSecond = SC.GetValue<int>("Transporter.TransporterTransferOffSeconds");
  1246. int recipeTotalTime = depRecipe.CalculateRecipeTotalTime();
  1247. //增加了Transporter最大传输时间和最小传输时间的差值
  1248. if (recipeTotalTime>=maxTimeToReady+transferOffSecond)
  1249. {
  1250. return true;
  1251. }
  1252. return false;
  1253. }
  1254. /// <summary>
  1255. /// 根据化学液获取可用的metal集合
  1256. /// </summary>
  1257. /// <param name="chemistry"></param>
  1258. /// <returns></returns>
  1259. public List<MetalEntity> GetAvaibleMetalList(string chemistry, string sequenceType,int waferSize, bool isEmpty)
  1260. {
  1261. List<IModuleEntity> reservoirEntities = Singleton<RouteManager>.Instance.GetModulesByModuleType(ModuleType.Reservoir);
  1262. List<string> avaibles = new List<string>();
  1263. foreach (IModuleEntity item in reservoirEntities)
  1264. {
  1265. ReservoirEntity entity = item as ReservoirEntity;
  1266. if (entity.Chemistry == chemistry && entity.IsAuto && entity.IsInitialized)
  1267. {
  1268. avaibles.Add(entity.Module.ToString());
  1269. }
  1270. }
  1271. List<MetalEntity> metals = new List<MetalEntity>();
  1272. foreach (string item in avaibles)
  1273. {
  1274. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(item);
  1275. if (reservoirItem == null)
  1276. {
  1277. continue;
  1278. }
  1279. foreach (MetalItem subItem in reservoirItem.MetalCells)
  1280. {
  1281. MetalEntity entity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>($"Metal{subItem.MetalID}");
  1282. if (!CheckAvaibleModule(entity, ModuleType.Metal, sequenceType))
  1283. {
  1284. continue;
  1285. }
  1286. if (entity.MetalWaferSize != waferSize)
  1287. {
  1288. continue;
  1289. }
  1290. if (!isEmpty || (isEmpty && entity.WaferHolderInfo == null))
  1291. {
  1292. metals.Add(entity);
  1293. }
  1294. }
  1295. }
  1296. return metals;
  1297. }
  1298. /// <summary>
  1299. /// 获取上一个Metal
  1300. /// </summary>
  1301. /// <param name="sequenceIndex"></param>
  1302. /// <param name="sequences"></param>
  1303. /// <returns></returns>
  1304. public ModuleName GetPreMetalModuleName(int sequenceIndex,List<SchedulerSequence> sequences)
  1305. {
  1306. for(int i = sequenceIndex - 1; i >= 0; i--)
  1307. {
  1308. SchedulerSequence schedulerSequence= sequences[i];
  1309. if (schedulerSequence.ModuleType == ModuleType.Metal && ModuleHelper.IsMetal(schedulerSequence.ModuleName))
  1310. {
  1311. return schedulerSequence.ModuleName;
  1312. }
  1313. }
  1314. return ModuleName.Unknown;
  1315. }
  1316. }
  1317. }