SchedulerSequenceManager.cs 62 KB

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