SchedulerProcessTransporter.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Fsm;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.Util;
  5. using CyberX8_Core;
  6. using CyberX8_RT.Devices.AXIS;
  7. using CyberX8_RT.Modules;
  8. using CyberX8_RT.Modules.Loader;
  9. using CyberX8_RT.Modules.Metal;
  10. using CyberX8_RT.Modules.Prewet;
  11. using CyberX8_RT.Modules.Transporter;
  12. using CyberX8_RT.Schedulers.EfemRobot;
  13. using MECF.Framework.Common.CommonData;
  14. using MECF.Framework.Common.Equipment;
  15. using MECF.Framework.Common.RecipeCenter;
  16. using MECF.Framework.Common.Schedulers;
  17. using MECF.Framework.Common.WaferHolder;
  18. using MECF.Framework.RT.Core.Equipments;
  19. using System;
  20. using System.Collections.Generic;
  21. using System.Linq;
  22. using System.Text;
  23. using System.Threading.Tasks;
  24. using System.Windows.Markup;
  25. namespace CyberX8_RT.Schedulers.Transporter
  26. {
  27. public class SchedulerProcessTransporter : SchedulerModule
  28. {
  29. #region 内部变量
  30. /// <summary>
  31. /// Process Transporter
  32. /// </summary>
  33. private TransporterEntity _processTransporterEntity;
  34. /// <summary>
  35. /// Loader transporterEntity
  36. /// </summary>
  37. private TransporterEntity _loaderTransporterEntity;
  38. /// <summary>
  39. /// 调度发送消息
  40. /// </summary>
  41. private SchedulerPostMsg _schedulerPostMsg=new SchedulerPostMsg();
  42. /// <summary>
  43. /// 推送消息结果
  44. /// </summary>
  45. private bool _postMsgResult = false;
  46. #endregion
  47. #region 属性
  48. /// <summary>
  49. /// 是否空闲
  50. /// </summary>
  51. public override bool IsIdle
  52. {
  53. get { return _state == RState.End; }
  54. }
  55. /// <summary>
  56. /// 是否错误
  57. /// </summary>
  58. public override bool IsError
  59. {
  60. get { return _state == RState.Failed || _state == RState.Timeout; }
  61. }
  62. public bool IsBusy
  63. {
  64. get { return _state == RState.Running; }
  65. }
  66. #endregion
  67. /// <summary>
  68. /// 构造函数
  69. /// </summary>
  70. /// <param name="module"></param>
  71. public SchedulerProcessTransporter(ModuleName module) : base(module.ToString())
  72. {
  73. _processTransporterEntity = Singleton<RouteManager>.Instance.GetModule<TransporterEntity>(module.ToString());
  74. _loaderTransporterEntity = Singleton<RouteManager>.Instance.GetModule<TransporterEntity>(ModuleName.Transporter2.ToString());
  75. }
  76. /// <summary>
  77. /// 执行
  78. /// </summary>
  79. /// <param name="parameter"></param>
  80. /// <returns></returns>
  81. public override bool RunProcess(object recipe, object parameter, List<SchedulerSyncModuleMessage> syncMessages)
  82. {
  83. if (parameter == null || !(parameter is TransporterAction))
  84. {
  85. return false;
  86. }
  87. TransporterAction action = (TransporterAction)parameter;
  88. WaferHolderMoveItem waferHolderMoveItem = (WaferHolderMoveItem)action.Parameter;
  89. if (waferHolderMoveItem.SourceModule != ModuleName.Unknown && waferHolderMoveItem.DestModule != ModuleName.Unknown)
  90. {
  91. SchedulerLoaderTransporter schedulerLoaderTransporter = (SchedulerLoaderTransporter)SchedulerManager.Instance.GetScheduler(ModuleName.Transporter2);
  92. if (schedulerLoaderTransporter.IsBusy && _loaderTransporterEntity.IsIdle)
  93. {
  94. return false;
  95. }
  96. if (!_processTransporterEntity.CheckOtherEntityStatus(waferHolderMoveItem.SourceModule.ToString()))
  97. {
  98. return false;
  99. }
  100. if (!_processTransporterEntity.CheckOtherEntityStatus(waferHolderMoveItem.DestModule.ToString()))
  101. {
  102. return false;
  103. }
  104. if (!WaferHolderManager.Instance.HasWaferHolder(waferHolderMoveItem.SourceModule.ToString()))
  105. {
  106. return false;
  107. }
  108. if (WaferHolderManager.Instance.HasWaferHolder(waferHolderMoveItem.DestModule.ToString()))
  109. {
  110. return false;
  111. }
  112. return TransferWaferHolderNonLoader(waferHolderMoveItem);
  113. }
  114. return true;
  115. }
  116. /// <summary>
  117. /// 传输WaferHolder(无WaferHolder)
  118. /// </summary>
  119. /// <param name="waferHolderMoveItem"></param>
  120. private bool TransferWaferHolderNonLoader(WaferHolderMoveItem waferHolderMoveItem)
  121. {
  122. IModuleEntity moduleEntity = Singleton<RouteManager>.Instance.GetModule<IModuleEntity>(waferHolderMoveItem.DestModule.ToString());
  123. if (moduleEntity != null)
  124. {
  125. if (waferHolderMoveItem.SourceModule == ModuleName.Unknown || waferHolderMoveItem.DestModule == ModuleName.Unknown)
  126. {
  127. return false;
  128. }
  129. bool result = false;
  130. if (waferHolderMoveItem.DestModuleType != ModuleType.Metal)
  131. {
  132. result = _processTransporterEntity.CheckToPostMessage<TransporterState, TransporterMSG>(eEvent.WARN_TRANSPORTER,
  133. Module.ToString(), (int)TransporterMSG.Transfer, waferHolderMoveItem.SourceModule.ToString(), waferHolderMoveItem.DestModule.ToString());
  134. }
  135. else
  136. {
  137. result = _processTransporterEntity.CheckToPostMessage<TransporterState, TransporterMSG>(eEvent.WARN_TRANSPORTER,
  138. Module.ToString(), (int)TransporterMSG.PickUpMoveTo, waferHolderMoveItem.SourceModule.ToString(), waferHolderMoveItem.DestModule.ToString());
  139. }
  140. if (result)
  141. {
  142. _state = RState.Running;
  143. _postMsgResult = false;
  144. _schedulerPostMsg.Reset();
  145. }
  146. return result;
  147. }
  148. return false;
  149. }
  150. /// <summary>
  151. /// 监控执行
  152. /// </summary>
  153. /// <returns></returns>
  154. public override bool MonitorProcess(SchedulerSequence schedulerSequence,bool hasMatchWafer)
  155. {
  156. TransporterAction transporterAction = (TransporterAction)schedulerSequence.Parameters;
  157. WaferHolderMoveItem waferHolderMoveItem = (WaferHolderMoveItem)transporterAction.Parameter;
  158. //检验PostMsg的结果
  159. if (!_postMsgResult)
  160. {
  161. if (_processTransporterEntity.IsError)
  162. {
  163. return false;
  164. }
  165. _postMsgResult = CheckPostMsg(waferHolderMoveItem);
  166. if (!_postMsgResult)
  167. {
  168. return false;
  169. }
  170. }
  171. if (waferHolderMoveItem.DestModuleType != ModuleType.Metal)
  172. {
  173. if (_processTransporterEntity.IsIdle)
  174. {
  175. if (_processTransporterEntity.WaferHolderInfo != null)
  176. {
  177. return false;
  178. }
  179. if (waferHolderMoveItem.SourceModuleType == ModuleType.Prewet)
  180. {
  181. PrewetPickComplete();
  182. }
  183. _state = RState.End;
  184. }
  185. }
  186. else
  187. {
  188. if (waferHolderMoveItem.SourceModuleType == ModuleType.Prewet)
  189. {
  190. if (_processTransporterEntity.WaferHolderInfo != null)
  191. {
  192. PrewetPickComplete();
  193. }
  194. }
  195. //ProcessTransporter完成PickUp和MoveTo
  196. if (_processTransporterEntity.State == (int)TransporterState.PickUpMoveToComplete)
  197. {
  198. MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(waferHolderMoveItem.DestModule.ToString());
  199. if (metalEntity != null)
  200. {
  201. //关闭FlowValve
  202. if (metalEntity.State == (int)MetalState.WaitCloseFlow)
  203. {
  204. metalEntity.CheckToPostMessage<MetalState, MetalMsg>(eEvent.WARN_METAL, waferHolderMoveItem.DestModule.ToString(),
  205. (int)MetalMsg.CloseFlowValve);
  206. }
  207. //完成FlowValve关闭后状态变更为等待打开FlowValve,执行Place
  208. else if (metalEntity.State == (int)MetalState.WaitOpenFlow)
  209. {
  210. _processTransporterEntity.CheckToPostMessage<TransporterState, TransporterMSG>(eEvent.WARN_TRANSPORTER, Module.ToString(),
  211. (int)TransporterMSG.Place, waferHolderMoveItem.DestModule.ToString());
  212. }
  213. }
  214. }
  215. //Transporter完成Place后
  216. else if (_processTransporterEntity.IsIdle)
  217. {
  218. if(_processTransporterEntity.WaferHolderInfo!=null)
  219. {
  220. return false;
  221. }
  222. MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(waferHolderMoveItem.DestModule.ToString());
  223. if (metalEntity != null)
  224. {
  225. //打开FlowValve,完成传输任务
  226. if (metalEntity.State == (int)MetalState.WaitOpenFlow)
  227. {
  228. bool result= metalEntity.CheckToPostMessage<MetalState, MetalMsg>(eEvent.WARN_METAL, waferHolderMoveItem.DestModule.ToString(),
  229. (int)MetalMsg.OpenFlowValve);
  230. if(result)
  231. {
  232. _state = RState.End;
  233. }
  234. }
  235. }
  236. }
  237. }
  238. return true;
  239. }
  240. /// <summary>
  241. /// 检验PostMsg的结果
  242. /// </summary>
  243. /// <param name="waferHolderMoveItem"></param>
  244. /// <returns></returns>
  245. private bool CheckPostMsg(WaferHolderMoveItem waferHolderMoveItem)
  246. {
  247. if (waferHolderMoveItem.DestModuleType == ModuleType.Metal)
  248. {
  249. return _schedulerPostMsg.PostMsg<TransporterState, TransporterMSG>(_processTransporterEntity, _processTransporterEntity.State,
  250. eEvent.WARN_TRANSPORTER, Module.ToString(), (int)TransporterMSG.PickUpMoveTo,
  251. (int)TransporterState.PickUpMoveToing, waferHolderMoveItem.SourceModule.ToString(), waferHolderMoveItem.DestModule.ToString());
  252. }
  253. else
  254. {
  255. return _schedulerPostMsg.PostMsg<TransporterState, TransporterMSG>(_processTransporterEntity, _processTransporterEntity.State,
  256. eEvent.WARN_TRANSPORTER, Module.ToString(), (int)TransporterMSG.Transfer,
  257. (int)TransporterState.Transfering, waferHolderMoveItem.SourceModule.ToString(), waferHolderMoveItem.DestModule.ToString());
  258. }
  259. }
  260. /// <summary>
  261. /// PrewetPick完成事件
  262. /// </summary>
  263. private void PrewetPickComplete()
  264. {
  265. PrewetEntity prewetEntity = Singleton<RouteManager>.Instance.GetModule<PrewetEntity>(ModuleName.Prewet1.ToString());
  266. if (prewetEntity.State == (int)PrewetState.WaitForPick)
  267. {
  268. prewetEntity.CheckToPostMessage<PrewetState, PrewetMsg>(eEvent.WARN_PREWET, ModuleName.Prewet1.ToString(),
  269. (int)PrewetMsg.PickComplete);
  270. }
  271. }
  272. /// <summary>
  273. /// 检验前置条件
  274. /// </summary>
  275. /// <param name="sequenceIndex"></param>
  276. /// <param name="parameter"></param>
  277. /// <returns></returns>
  278. public override bool CheckPrecondition(List<SchedulerSequence> schedulerSequences, int sequenceIndex, object parameter, string materialId,ref string reason)
  279. {
  280. if (!(parameter is TransporterAction))
  281. {
  282. reason = "parameter is not TransporterAction";
  283. return false;
  284. }
  285. TransporterAction transporterAction= (TransporterAction)parameter;
  286. if (_state == RState.Running)
  287. {
  288. reason = "scheduler module is already running";
  289. return false;
  290. }
  291. if (_processTransporterEntity.WaferHolderInfo != null)
  292. {
  293. reason = "process transporter has wafer shuttle";
  294. return false;
  295. }
  296. //电机是否还在执行动作
  297. JetAxisBase gantryAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Transporter1}.Gantry");
  298. if(gantryAxis==null)
  299. {
  300. reason = "process transporter gantry is null";
  301. return false;
  302. }
  303. if (gantryAxis.Status == RState.Running)
  304. {
  305. reason = "process transporter gantry is running";
  306. return false;
  307. }
  308. JetAxisBase elevatorAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Transporter1}.Elevator");
  309. if (elevatorAxis == null)
  310. {
  311. reason = "process transporter elevator is null";
  312. return false;
  313. }
  314. if (elevatorAxis.Status == RState.Running)
  315. {
  316. reason = "process transporter elevator is running";
  317. return false;
  318. }
  319. if (_processTransporterEntity.IsBusy)
  320. {
  321. reason = "process transporter entity is busy";
  322. return false;
  323. }
  324. WaferHolderMoveItem waferHolderMoveItem = (WaferHolderMoveItem)transporterAction.Parameter;
  325. bool result = false;
  326. //更新未知源模块
  327. UpdateUnkownSourceModule(schedulerSequences, waferHolderMoveItem, sequenceIndex);
  328. //源为Prewet
  329. if (waferHolderMoveItem.SourceModule == ModuleName.Prewet1)
  330. {
  331. result= CheckSourcePrewetCondition();
  332. if(!result)
  333. {
  334. reason = "process transporter sourcemodule prewet condition is not avaible";
  335. return false;
  336. }
  337. }
  338. bool existEnableCell = false;
  339. //更新未知目标模块
  340. result = UpdateUnkownTargetModule(schedulerSequences, waferHolderMoveItem, sequenceIndex,materialId,ref existEnableCell);
  341. if (!result)
  342. {
  343. reason = "process transporter moveitem target module is unknown";
  344. return false;
  345. }
  346. if (waferHolderMoveItem.DestModuleType==ModuleType.Metal)
  347. {
  348. if(!ModuleHelper.IsMetal(waferHolderMoveItem.DestModule))
  349. {
  350. reason = "process transporter target module is not metal";
  351. return false;
  352. }
  353. UpdateNextMetalScheduler(schedulerSequences, sequenceIndex, waferHolderMoveItem.DestModule);
  354. result= CheckTargetMetalCondition(waferHolderMoveItem.DestModule.ToString(),waferHolderMoveItem, schedulerSequences, sequenceIndex);
  355. if(!result)
  356. {
  357. reason = $"process transporter target module {waferHolderMoveItem.DestModule} condition is false";
  358. return false;
  359. }
  360. }
  361. return true;
  362. }
  363. /// <summary>
  364. /// 更新下一块Metal
  365. /// </summary>
  366. /// <param name="schedulerSequences"></param>
  367. /// <param name="sequenceIndex"></param>
  368. private void UpdateNextMetalScheduler(List<SchedulerSequence> schedulerSequences,int sequenceIndex,ModuleName metalName)
  369. {
  370. if(sequenceIndex+1<schedulerSequences.Count)
  371. {
  372. SchedulerSequence nextSchedulerSequence=schedulerSequences[sequenceIndex+1];
  373. if(nextSchedulerSequence.SchedulerModule==null)
  374. {
  375. nextSchedulerSequence.SchedulerModule = SchedulerManager.Instance.GetScheduler(metalName);
  376. nextSchedulerSequence.ModuleName = metalName;
  377. }
  378. }
  379. }
  380. /// <summary>
  381. /// 更新未知目标模块
  382. /// </summary>
  383. private bool UpdateUnkownTargetModule(List<SchedulerSequence> schedulerSequences, WaferHolderMoveItem waferHolderMoveItem, int sequenceIndex,string materialId,ref bool existEnableCell)
  384. {
  385. if (waferHolderMoveItem.DestModule == ModuleName.Unknown)
  386. {
  387. if (sequenceIndex + 1 < schedulerSequences.Count)
  388. {
  389. SchedulerSequence sequence = schedulerSequences[sequenceIndex + 1];
  390. ModuleName moduleName = ModuleName.Unknown;
  391. if (waferHolderMoveItem.DestModuleType == ModuleType.Metal)
  392. {
  393. if (sequence.Recipe != null && sequence.Recipe is DepRecipe)
  394. {
  395. //获取可用的Metal以及Rinse
  396. DepRecipe depRecipe = (DepRecipe)sequence.Recipe;
  397. ModuleName tmpName = SchedulerSequenceManager.Instance.CalculateAvaibleMetalCellByChemistry(depRecipe.Chemistry,
  398. waferHolderMoveItem.SourceModule.ToString(),sequence.SequenceType,sequence.WaferSize,ref existEnableCell);
  399. if (tmpName != ModuleName.Unknown)
  400. {
  401. IModuleEntity moduleEntity = Singleton<RouteManager>.Instance.GetModule<IModuleEntity>(tmpName.ToString());
  402. if (SchedulerSequenceManager.Instance.CheckMetalCellRecipeTimeAvaible(moduleEntity, depRecipe))
  403. {
  404. moduleName = tmpName;
  405. }
  406. }
  407. }
  408. }
  409. else if(waferHolderMoveItem.DestModuleType==ModuleType.Rinse)
  410. {
  411. if (waferHolderMoveItem.SourceModuleType == ModuleType.Metal)
  412. {
  413. moduleName = SchedulerSequenceManager.Instance.GetAvaibleEmptyModuleCell(waferHolderMoveItem.DestModuleType,sequence.SequenceType,waferHolderMoveItem.SourceModule);
  414. }
  415. else
  416. {
  417. for(int i = sequenceIndex - 1; i >= 0; i--)
  418. {
  419. SchedulerSequence tmp=schedulerSequences[i];
  420. if (tmp.ModuleType == ModuleType.Metal&&ModuleHelper.IsMetal(tmp.ModuleName))
  421. {
  422. moduleName = SchedulerSequenceManager.Instance.GetAvaibleEmptyModuleCell(waferHolderMoveItem.DestModuleType,tmp.SequenceType, tmp.ModuleName);
  423. break;
  424. }
  425. }
  426. }
  427. }
  428. else
  429. {
  430. moduleName = SchedulerSequenceManager.Instance.GetAvaibleEmptyModuleCell(waferHolderMoveItem.DestModuleType,sequence.SequenceType,waferHolderMoveItem.SourceModule);
  431. }
  432. if (moduleName == ModuleName.Unknown)
  433. {
  434. return false;
  435. }
  436. else
  437. {
  438. LOG.WriteLog(eEvent.EV_SCHEDULER, Module.ToString(), $"{materialId} ProcessTransporter Confirm Next Cell {moduleName}");
  439. waferHolderMoveItem.DestModule = moduleName;
  440. if (sequence.SchedulerModule == null)
  441. {
  442. sequence.SchedulerModule = SchedulerManager.Instance.GetScheduler(moduleName);
  443. sequence.ModuleName = moduleName;
  444. }
  445. }
  446. }
  447. }
  448. return true;
  449. }
  450. /// <summary>
  451. /// 更新未知源模块
  452. /// </summary>
  453. private void UpdateUnkownSourceModule(List<SchedulerSequence> schedulerSequences, WaferHolderMoveItem waferHolderMoveItem, int sequenceIndex)
  454. {
  455. if (waferHolderMoveItem.SourceModule != ModuleName.Unknown)
  456. {
  457. return;
  458. }
  459. for (int i = sequenceIndex - 1; i >= 0; i--)
  460. {
  461. SchedulerSequence preSchedulerSequence = schedulerSequences[i];
  462. if (preSchedulerSequence.State != RState.End)
  463. {
  464. continue;
  465. }
  466. if (i == sequenceIndex - 1)
  467. {
  468. if (preSchedulerSequence != null && preSchedulerSequence.SchedulerModule != null)
  469. {
  470. waferHolderMoveItem.SourceModule = preSchedulerSequence.SchedulerModule.Module;
  471. break;
  472. }
  473. }
  474. else
  475. {
  476. //用于Metal出错后跳过了几个步骤,transporter源模块取至前面跳过的transporter1的目标模块
  477. if(preSchedulerSequence.ModuleName==ModuleName.Transporter1)
  478. {
  479. TransporterAction transporterAction = preSchedulerSequence.Parameters as TransporterAction;
  480. if (transporterAction.ActionMsg != TransporterMSG.Transfer)
  481. {
  482. continue;
  483. }
  484. WaferHolderMoveItem preWaferHolderMoveItem = transporterAction.Parameter as WaferHolderMoveItem;
  485. if (preSchedulerSequence != null && preWaferHolderMoveItem.DestModule != ModuleName.Unknown)
  486. {
  487. waferHolderMoveItem.SourceModule = preWaferHolderMoveItem.DestModule;
  488. break;
  489. }
  490. }
  491. }
  492. }
  493. }
  494. /// <summary>
  495. /// 检验源Prewet前置条件
  496. /// </summary>
  497. /// <returns></returns>
  498. private bool CheckSourcePrewetCondition()
  499. {
  500. PrewetEntity prewetEntity = Singleton<RouteManager>.Instance.GetModule<PrewetEntity>(ModuleName.Prewet1.ToString());
  501. if (prewetEntity.State == (int)PrewetState.WaitForPick)
  502. {
  503. return true;
  504. }
  505. return false;
  506. }
  507. /// <summary>
  508. /// 检验目标Metal前置条件
  509. /// </summary>
  510. /// <returns></returns>
  511. private bool CheckTargetMetalCondition(string metalName,WaferHolderMoveItem waferHolderMoveItem,List<SchedulerSequence> schedulerSequences,int sequenceIndex)
  512. {
  513. MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(metalName);
  514. if (metalEntity.IsIdle)
  515. {
  516. metalEntity.CheckToPostMessage<MetalState, MetalMsg>(eEvent.WARN_METAL, metalName,
  517. (int)MetalMsg.CurrentShortTest);
  518. }
  519. else if (metalEntity.State == (int)MetalState.WaitCloseFlow)
  520. {
  521. return true;
  522. }
  523. else if (metalEntity.IsError)
  524. {
  525. waferHolderMoveItem.DestModule = ModuleName.Unknown;
  526. SchedulerSequence nextSequence = schedulerSequences[sequenceIndex + 1];
  527. if (nextSequence != null)
  528. {
  529. nextSequence.SchedulerModule = null;
  530. nextSequence.ModuleName = ModuleName.Unknown;
  531. }
  532. }
  533. return false;
  534. }
  535. public override void ResetTask()
  536. {
  537. base.ResetTask();
  538. _schedulerPostMsg.Reset();
  539. _postMsgResult = false;
  540. }
  541. }
  542. }