WaferHolderTaskDispatcher.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1.  using Aitex.Core.RT.Log;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Core.Util;
  4. using CyberX8_Core;
  5. using CyberX8_RT.Modules;
  6. using CyberX8_RT.Modules.Dryer;
  7. using CyberX8_RT.Modules.Metal;
  8. using CyberX8_RT.Modules.Prewet;
  9. using CyberX8_RT.Modules.Transporter;
  10. using CyberX8_RT.Schedulers;
  11. using CyberX8_RT.Schedulers.Transporter;
  12. using MECF.Framework.Common.CommonData;
  13. using MECF.Framework.Common.Equipment;
  14. using MECF.Framework.Common.ToolLayout;
  15. using MECF.Framework.Common.WaferHolder;
  16. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TMs;
  17. using SecsGem.Core.ItemModel;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. namespace CyberX8_RT.Dispatch
  24. {
  25. public class WaferHolderTaskDispatcher : Singleton<WaferHolderTaskDispatcher>
  26. {
  27. /// <summary>
  28. /// 分析
  29. /// </summary>
  30. public void Analyse()
  31. {
  32. List <WaferHolderTask> waferHolderTasks = WaferHolderTaskManager.Instance.LoaderWaferHolderTaskList().ToList();
  33. bool exsitTransport2FromBuffer = false;
  34. List<WaferHolderTask> canceledWaferHolderTask = new List<WaferHolderTask>();
  35. foreach (var item in waferHolderTasks)
  36. {
  37. SchedulerSequence currentSequence = item.GetCurrentSchedulerSequence();
  38. if (currentSequence == null)
  39. {
  40. item.Run();
  41. continue;
  42. }
  43. //处理ProcessTransporter逻辑
  44. if (currentSequence.ModuleName == ModuleName.Transporter1)
  45. {
  46. DealProcessTransporterScheduler(currentSequence, item, waferHolderTasks);
  47. }
  48. //处理LoaderTransporter逻辑
  49. else if(currentSequence.ModuleName==ModuleName.Transporter2)
  50. {
  51. DealLoaderTransporterScheduler(currentSequence, item, waferHolderTasks,canceledWaferHolderTask,ref exsitTransport2FromBuffer);
  52. }
  53. else
  54. {
  55. item.Run();
  56. }
  57. }
  58. RemoveCanceledTask(canceledWaferHolderTask);
  59. }
  60. /// <summary>
  61. /// 处理ProcessTransporter
  62. /// </summary>
  63. /// <param name="sequence"></param>
  64. private void DealProcessTransporterScheduler(SchedulerSequence currentSequence,WaferHolderTask item,List<WaferHolderTask> waferHolderTasks)
  65. {
  66. int transporterTransferSeconds = SC.GetValue<int>("Transporter.TransporterTransferSeconds");
  67. if (currentSequence.State == RState.End)
  68. {
  69. item.Run();
  70. return;
  71. }
  72. if (currentSequence.State == RState.Running)
  73. {
  74. item.Run();
  75. return;
  76. }
  77. if (CheckOtherTransporterIsRunning(waferHolderTasks, item,ModuleName.Transporter1))
  78. {
  79. return;
  80. }
  81. //存在其他任务当前source为prewet同时prewet状态为WaitForPick
  82. if (CheckPrewetIsWaitForPick(waferHolderTasks, item) && currentSequence.State == RState.Init)
  83. {
  84. return;
  85. }
  86. if (currentSequence.State == RState.Init)
  87. {
  88. AnalyseProcessTransporterSchedulerSequence(currentSequence, item, transporterTransferSeconds);
  89. }
  90. }
  91. /// <summary>
  92. /// 处理LoaderTransPorter
  93. /// </summary>
  94. /// <param name="currentSequence"></param>
  95. /// <param name="item"></param>
  96. /// <param name="waferHolderTasks"></param>
  97. private void DealLoaderTransporterScheduler(SchedulerSequence currentSequence,WaferHolderTask item, List<WaferHolderTask> waferHolderTasks,
  98. List<WaferHolderTask> canceledWaferHolderTask, ref bool exsitTransport2FromBuffer)
  99. {
  100. if (currentSequence.State == RState.End)
  101. {
  102. item.Run();
  103. return;
  104. }
  105. if (currentSequence.State == RState.Running)
  106. {
  107. item.Run();
  108. return;
  109. }
  110. if (CheckOtherTransporterIsRunning(waferHolderTasks, item, ModuleName.Transporter2))
  111. {
  112. return;
  113. }
  114. if (!(currentSequence.Parameters is TransporterAction))
  115. {
  116. return;
  117. }
  118. TransporterAction action=currentSequence.Parameters as TransporterAction;
  119. if (action.ActionMsg == TransporterMSG.Transfer)
  120. {
  121. WaferHolderMoveItem waferHolderMoveItem = action.Parameter as WaferHolderMoveItem;
  122. if (waferHolderMoveItem.SourceModuleType == ModuleType.Buffer && waferHolderMoveItem.DestModuleType == ModuleType.Prewet)
  123. {
  124. if (item.State == WaferHolderTaskState.Canceled)
  125. {
  126. canceledWaferHolderTask.Add(item);
  127. return;
  128. }
  129. if (!exsitTransport2FromBuffer)
  130. {
  131. exsitTransport2FromBuffer = true;
  132. item.Run();
  133. }
  134. }
  135. else if (waferHolderMoveItem.SourceModuleType == ModuleType.Dryer)
  136. {
  137. if (waferHolderMoveItem.DestModuleType == ModuleType.Buffer)
  138. {
  139. if (WaferHolderManager.Instance.HasWaferHolder("Loader"))
  140. {
  141. item.Run();
  142. return;
  143. }
  144. if (CheckExistWaferHolderTaskIsCreateState(waferHolderTasks, item))
  145. {
  146. item.Run();
  147. return;
  148. }
  149. if (CheckDryerWaferHolderIdle(waferHolderTasks, item))
  150. {
  151. item.Run();
  152. return;
  153. }
  154. else
  155. {
  156. item.UpdateDryerLastSchedulerComplete();
  157. }
  158. }
  159. else
  160. {
  161. item.Run();
  162. }
  163. }
  164. else
  165. {
  166. item.Run();
  167. }
  168. }
  169. else
  170. {
  171. item.Run();
  172. }
  173. }
  174. /// <summary>
  175. /// 是否存在未启动的WaferHolderTask
  176. /// </summary>
  177. /// <param name="waferHolderTasks"></param>
  178. /// <param name="waferHolderTask"></param>
  179. /// <returns></returns>
  180. private bool CheckExistWaferHolderTaskIsCreateState(List<WaferHolderTask> waferHolderTasks, WaferHolderTask waferHolderTask)
  181. {
  182. foreach(WaferHolderTask item in waferHolderTasks)
  183. {
  184. if (item.ID == waferHolderTask.ID)
  185. {
  186. continue;
  187. }
  188. if (item.State == WaferHolderTaskState.Created)
  189. {
  190. return true;
  191. }
  192. }
  193. return false;
  194. }
  195. /// <summary>
  196. /// 检验是否存在Dryer WaferHolder空闲(WaferHolder不存在WaferHolderTask中)
  197. /// </summary>
  198. /// <param name="waferHolderTasks"></param>
  199. /// <param name="module"></param>
  200. /// <returns></returns>
  201. private bool CheckDryerWaferHolderIdle(List<WaferHolderTask> waferHolderTasks,WaferHolderTask waferHolderTask)
  202. {
  203. List<string> dryerModules = DryerItemManager.Instance.InstalledModules;
  204. foreach (string item in dryerModules)
  205. {
  206. if (WaferHolderManager.Instance.HasWaferHolder(item))
  207. {
  208. DryerEntity dryerEntity = Singleton<RouteManager>.Instance.GetModule<DryerEntity>(item);
  209. if (dryerEntity == null)
  210. {
  211. continue;
  212. }
  213. if (!dryerEntity.IsIdle)
  214. {
  215. continue;
  216. }
  217. WaferHolderInfo waferHolderInfo=WaferHolderManager.Instance.GetWaferHolder(item);
  218. if(waferHolderInfo == null)
  219. {
  220. continue;
  221. }
  222. if (waferHolderInfo.Id == waferHolderTask.WaferHolderInfo.Id)
  223. {
  224. continue;
  225. }
  226. int index = waferHolderTasks.FindIndex(O => O.WaferHolderInfo.Id == waferHolderInfo.Id);
  227. if (index == -1)
  228. {
  229. return true;
  230. }
  231. else
  232. {
  233. WaferHolderTask task = waferHolderTasks[index];
  234. if (task.State == WaferHolderTaskState.Created)
  235. {
  236. return true;
  237. }
  238. }
  239. }
  240. }
  241. return false;
  242. }
  243. /// <summary>
  244. /// 移除状态为取消的WaferHolderTask
  245. /// </summary>
  246. /// <param name="waferHolderTasks"></param>
  247. private void RemoveCanceledTask(List<WaferHolderTask> waferHolderTasks)
  248. {
  249. foreach(WaferHolderTask item in waferHolderTasks)
  250. {
  251. WaferHolderTaskManager.Instance.RemoveById(item.ID);
  252. LOG.WriteLog(eEvent.EV_SCHEDULER, "System", $"remove wafer shuttle {item.WaferHolderInfo.Id} task");
  253. //List<string> mathedWaferIds = WaferTaskManager.Instance.GetWaferHolderMathWaferId(item.WaferHolderInfo.Id);
  254. //foreach(string waferId in mathedWaferIds)
  255. //{
  256. // WaferTaskManager.Instance.RemoveWaferTask(waferId);
  257. // WaferTaskManager.Instance.RemoveWaferIdMatchWaferHolderTaskDic(waferId);
  258. //}
  259. }
  260. }
  261. /// <summary>
  262. /// 检验其他任务是否也是Transporter并且正在执行
  263. /// </summary>
  264. /// <param name="waferHolderTasks"></param>
  265. /// <param name="waferHolderTask"></param>
  266. /// <returns></returns>
  267. private bool CheckOtherTransporterIsRunning(List<WaferHolderTask> waferHolderTasks,WaferHolderTask waferHolderTask,ModuleName moduleName)
  268. {
  269. foreach(WaferHolderTask item in waferHolderTasks)
  270. {
  271. if (item.ID == waferHolderTask.ID)
  272. {
  273. continue;
  274. }
  275. SchedulerSequence schedulerSequence = item.GetCurrentSchedulerSequence();
  276. if (schedulerSequence == null)
  277. {
  278. continue;
  279. }
  280. if (schedulerSequence.ModuleName == moduleName)
  281. {
  282. if(schedulerSequence.State==RState.Running)
  283. {
  284. return true;
  285. }
  286. }
  287. }
  288. return false;
  289. }
  290. /// <summary>
  291. /// 检验其他任务是否也是Transporter1并且正在执行
  292. /// </summary>
  293. /// <param name="waferHolderTasks"></param>
  294. /// <param name="waferHolderTask"></param>
  295. /// <returns></returns>
  296. private bool CheckPrewetIsWaitForPick(List<WaferHolderTask> waferHolderTasks, WaferHolderTask waferHolderTask)
  297. {
  298. foreach (WaferHolderTask item in waferHolderTasks)
  299. {
  300. if (item.ID == waferHolderTask.ID)
  301. {
  302. continue;
  303. }
  304. SchedulerSequence schedulerSequence = item.GetCurrentSchedulerSequence();
  305. if (schedulerSequence == null)
  306. {
  307. continue;
  308. }
  309. if (schedulerSequence.ModuleName != ModuleName.Transporter1)
  310. {
  311. continue;
  312. }
  313. TransporterAction action = schedulerSequence.Parameters as TransporterAction;
  314. if (action.ActionMsg == TransporterMSG.Transfer)
  315. {
  316. WaferHolderMoveItem waferHolderMoveItem = action.Parameter as WaferHolderMoveItem;
  317. if (waferHolderMoveItem != null && waferHolderMoveItem.SourceModule == ModuleName.Prewet1)
  318. {
  319. PrewetEntity prewetEntity = Singleton<RouteManager>.Instance.GetModule<PrewetEntity>(ModuleName.Prewet1.ToString());
  320. if (prewetEntity != null && (prewetEntity.State == (int)PrewetState.PreparingToPick ||
  321. prewetEntity.State == (int)PrewetState.WaitForPick))
  322. {
  323. return true;
  324. }
  325. }
  326. }
  327. }
  328. return false;
  329. }
  330. /// <summary>
  331. /// 解析Transporter1调度逻辑
  332. /// </summary>
  333. /// <param name="sequence"></param>
  334. private void AnalyseProcessTransporterSchedulerSequence(SchedulerSequence sequence,WaferHolderTask waferHolderTask,int transporterTransferSeconds)
  335. {
  336. SchedulerSequence preSequence = waferHolderTask.GetPreSchedulerSequence();
  337. if (preSequence == null)
  338. {
  339. waferHolderTask.Run();
  340. return;
  341. }
  342. if (preSequence.ModuleType == ModuleType.Metal)
  343. {
  344. //Metal处于Error
  345. if (preSequence.SchedulerModule.IsError)
  346. {
  347. waferHolderTask.Run();
  348. return;
  349. }
  350. }
  351. if(CheckExistMetalRemainTime(transporterTransferSeconds))
  352. {
  353. return;
  354. }
  355. else
  356. {
  357. waferHolderTask.Run();
  358. }
  359. }
  360. /// <summary>
  361. /// 是否存在当前阶段为Metal,剩余时间比Transporter搬运时间更小时
  362. /// </summary>
  363. /// <param name="transporterTransferSeconds"></param>
  364. /// <returns></returns>
  365. private bool CheckExistMetalRemainTime(int transporterTransferSeconds)
  366. {
  367. List<WaferHolderTask> waferHolderTasks = WaferHolderTaskManager.Instance.LoaderWaferHolderTaskList().ToList();
  368. foreach (var item in waferHolderTasks)
  369. {
  370. SchedulerSequence currentSequence = item.GetCurrentSchedulerSequence();
  371. if (currentSequence == null)
  372. {
  373. continue;
  374. }
  375. if(currentSequence.ModuleType==ModuleType.Metal&&ModuleHelper.IsMetal(currentSequence.ModuleName))
  376. {
  377. MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(currentSequence.ModuleName.ToString());
  378. if (metalEntity == null)
  379. {
  380. continue;
  381. }
  382. if (metalEntity.IsIdle && metalEntity.WaferHolderInfo != null)
  383. {
  384. return true;
  385. }
  386. if(metalEntity.TimeToReady<=transporterTransferSeconds&&metalEntity.IsBusy)
  387. {
  388. return true;
  389. }
  390. }
  391. if (currentSequence.ModuleName == ModuleName.Transporter1)
  392. {
  393. SchedulerSequence preSequence = item.GetPreSchedulerSequence();
  394. if (preSequence.ModuleType==ModuleType.Metal&&WaferHolderManager.Instance.HasWaferHolder(preSequence.ModuleName.ToString()))
  395. {
  396. WaferHolderInfo waferHolderInfo = WaferHolderManager.Instance.GetWaferHolder(preSequence.ModuleName.ToString());
  397. if (DateTime.Now.Subtract(waferHolderInfo.LastMetalRecipeCompleteTime).TotalMilliseconds <= 1000)
  398. {
  399. return true;
  400. }
  401. }
  402. }
  403. }
  404. return false;
  405. }
  406. }
  407. }