SchedulerPuf.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. using Aitex.Core.RT.Fsm;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.Util;
  4. using MECF.Framework.Common.Equipment;
  5. using MECF.Framework.Common.Schedulers;
  6. using CyberX8_Core;
  7. using CyberX8_RT.Modules.PUF;
  8. using CyberX8_RT.Modules;
  9. using CyberX8_RT.Schedulers.EfemRobot;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using CyberX8_RT.Modules.Loader;
  16. using Aitex.Core.RT.Log;
  17. using MECF.Framework.Common.SubstrateTrackings;
  18. using Aitex.Core.Common;
  19. using MECF.Framework.Common.Utilities;
  20. using CyberX8_RT.Devices.AXIS;
  21. using Aitex.Core.RT.Device;
  22. using CyberX8_RT.Dispatch;
  23. using MECF.Framework.Common.RecipeCenter;
  24. namespace CyberX8_RT.Schedulers.Puf
  25. {
  26. public class SchedulerPuf : SchedulerModule
  27. {
  28. private enum OperationStep
  29. {
  30. None,
  31. ReadyForSwap,
  32. WaitForLoaderUnloadComplete,
  33. Swap,
  34. CheckSwapComplete,
  35. GotoRobotForPick,
  36. WaitForRobotPick,
  37. PufBackToPark,
  38. CheckParkComplete
  39. }
  40. #region 内部变量
  41. private PUFEntity _pufEntity;
  42. private LoaderEntity _loaderEntity;
  43. private OperationStep _currentOperation;
  44. private EfemEntity _efemEntity;
  45. private bool _forward = false;
  46. private string _side = "";
  47. private bool _isProductionWafer = false;
  48. #endregion
  49. #region 属性
  50. /// <summary>
  51. /// 是否空闲
  52. /// </summary>
  53. public override bool IsIdle
  54. {
  55. get { return _state == RState.End; }
  56. }
  57. /// <summary>
  58. /// 是否错误
  59. /// </summary>
  60. public override bool IsError
  61. {
  62. get { return _state == RState.Failed || _state == RState.Timeout; }
  63. }
  64. #endregion
  65. /// <summary>
  66. /// 构造函数
  67. /// </summary>
  68. /// <param name="module"></param>
  69. public SchedulerPuf(ModuleName moduleName) : base(moduleName.ToString())
  70. {
  71. _efemEntity = Singleton<RouteManager>.Instance.EFEM;
  72. _pufEntity = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(moduleName.ToString());
  73. _loaderEntity = Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(ModuleName.Loader1.ToString());
  74. }
  75. /// <summary>
  76. /// 执行
  77. /// </summary>
  78. /// <param name="parameter"></param>
  79. /// <returns></returns>
  80. public override bool RunProcess(object recipe, object parameter, List<SchedulerSyncModuleMessage> syncMessages)
  81. {
  82. _isProductionWafer = false;
  83. PufSchedulerParameter pufSchedulerParameter = parameter as PufSchedulerParameter;
  84. _forward = pufSchedulerParameter.IsForward;
  85. _side = pufSchedulerParameter.Side;
  86. if (_forward)
  87. {
  88. _currentOperation = OperationStep.ReadyForSwap;
  89. //B面是否有片
  90. if (WaferManager.Instance.CheckHasWafer(Module, 1))
  91. {
  92. _state = RState.Running;
  93. return _pufEntity.CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(),
  94. (int)PUFMSG.ReadyForSwap);
  95. }
  96. return false;
  97. }
  98. else
  99. {
  100. _currentOperation = OperationStep.None;
  101. return true;
  102. }
  103. }
  104. /// <summary>
  105. /// 监控执行
  106. /// </summary>
  107. /// <returns></returns>
  108. public override bool MonitorProcess(SchedulerSequence schedulerSequence,bool hasMatchWafer)
  109. {
  110. //当前状态为ReadyForSwap
  111. if (_currentOperation == OperationStep.ReadyForSwap)
  112. {
  113. //若Puf已经完成ReadyForSwap动作,状态变更为WaitForSwap
  114. if (_pufEntity.State == (int)PUFSTATE.WaitForSwap)
  115. {
  116. //当前操作变量为WaitFor LoaderUnload Complete
  117. _currentOperation = OperationStep.WaitForLoaderUnloadComplete;
  118. LOG.WriteLog(eEvent.INFO_PUF, Module.ToString(), "Current Operation is WaitForLoaderUnloadComplete");
  119. }
  120. }
  121. else if (_currentOperation == OperationStep.WaitForLoaderUnloadComplete)
  122. {
  123. //Loader Entity Unload all
  124. if (CheckDualPufStateCanExecuteLoaderUnloadAll())
  125. {
  126. PostLoaderEntityUnloadAllSide();
  127. }
  128. }
  129. //puf 进行Swap
  130. else if(_currentOperation==OperationStep.Swap)
  131. {
  132. bool result = _pufEntity.CheckToPostMessage<PUFSTATE,PUFMSG>(eEvent.ERR_PUF, Module.ToString(),
  133. (int)PUFMSG.Swap);
  134. if(result)
  135. {
  136. _currentOperation = OperationStep.CheckSwapComplete;
  137. LOG.WriteLog(eEvent.INFO_PUF, Module.ToString(), "Current Operation is CheckSwapComplete");
  138. }
  139. }
  140. else if(_currentOperation==OperationStep.CheckSwapComplete)
  141. {
  142. //puf完成Swap后运动至Robot让Robot取片
  143. PostPufEntityGotoRobotForPick();
  144. }
  145. else if(_currentOperation==OperationStep.GotoRobotForPick)
  146. {
  147. //Efem 将Dummy片运输至Dummy Casstete
  148. PostEfemRobotTransferToDummyCassete();
  149. }
  150. else if(_currentOperation==OperationStep.WaitForRobotPick)
  151. {
  152. //等待Efem Robot完成传片
  153. if (RobotMoveHelper.Instance.IsBusy)
  154. {
  155. RobotMoveHelper.Instance.Monitor(Module.ToString());
  156. }
  157. if(RobotMoveHelper.Instance.IsPickCompleted)
  158. {
  159. _currentOperation = OperationStep.PufBackToPark;
  160. LOG.WriteLog(eEvent.INFO_PUF, Module.ToString(), "Current Operation is PufBackToBack");
  161. }
  162. }
  163. else if(_currentOperation==OperationStep.PufBackToPark)
  164. {
  165. if (RobotMoveHelper.Instance.IsBusy)
  166. {
  167. RobotMoveHelper.Instance.Monitor(Module.ToString());
  168. }
  169. //Puf运动至Park安全位置
  170. bool result = _pufEntity.CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(),
  171. (int)PUFMSG.RobotPickComplete);
  172. if (result)
  173. {
  174. _currentOperation = OperationStep.CheckParkComplete;
  175. LOG.WriteLog(eEvent.INFO_PUF, Module.ToString(), "Current Operation is CheckParkComplete");
  176. }
  177. }
  178. else if(_currentOperation==OperationStep.CheckParkComplete)
  179. {
  180. if (RobotMoveHelper.Instance.IsBusy)
  181. {
  182. RobotMoveHelper.Instance.Monitor(Module.ToString());
  183. }
  184. //判定Puf运动是否完成
  185. if (_pufEntity.IsIdle&&RobotMoveHelper.Instance.IsIdle)
  186. {
  187. _state = RState.End;
  188. }
  189. }
  190. return false;
  191. }
  192. /// <summary>
  193. /// 检验Dual puf 是不是都处于WaitForSwap 状态,保证Loader可以UnloadAll
  194. /// </summary>
  195. /// <returns></returns>
  196. private bool CheckDualPufStateCanExecuteLoaderUnloadAll()
  197. {
  198. bool pufReady = true;
  199. if(ModuleHelper.IsInstalled(ModuleName.PUF1))
  200. {
  201. PUFEntity puf1Entity = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(ModuleName.PUF1.ToString());
  202. //B面有Wafer
  203. if (WaferManager.Instance.CheckHasWafer(ModuleName.PUF1,1))
  204. {
  205. pufReady = puf1Entity.State == (int)PUFSTATE.WaitForSwap;
  206. }
  207. else
  208. {
  209. pufReady = false;
  210. }
  211. }
  212. if(!pufReady)
  213. {
  214. return false;
  215. }
  216. //Loader中没有WaferHolder
  217. if(_loaderEntity.WaferHolderInfo==null)
  218. {
  219. return false;
  220. }
  221. if (_loaderEntity.State == (int)LOADERSTATE.WaitForUnload)
  222. {
  223. JetAxisBase _loadTransporterGantryAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Transporter2}.Gantry");
  224. if (_loadTransporterGantryAxis != null && !_loadTransporterGantryAxis.JudgeCompareTargetStation("Loader", "Right"))
  225. {
  226. return false;
  227. }
  228. }
  229. return true;
  230. }
  231. /// <summary>
  232. /// LoaderEntity Unload All
  233. /// </summary>
  234. private void PostLoaderEntityUnloadAllSide()
  235. {
  236. //当前loader状态机为WaitForUnload
  237. if (_loaderEntity.State == (int)LOADERSTATE.WaitForUnload&&_currentOperation==OperationStep.WaitForLoaderUnloadComplete)
  238. {
  239. //触发loaderEntity UnloadAll
  240. _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, ModuleName.Loader1.ToString(),
  241. (int)LoaderMSG.UnloadSide,_side);
  242. }
  243. //若Loader Unload操作完成,状态变更为WaitForLoad,puf操作变更为Swap
  244. else if (_loaderEntity.State == (int)LOADERSTATE.WaitForLoad)
  245. {
  246. _currentOperation = OperationStep.Swap;
  247. LOG.WriteLog(eEvent.INFO_PUF, Module.ToString(), "Current Operation is Swap");
  248. }
  249. else if (_loaderEntity.State == (int)LOADERSTATE.Unloading)
  250. {
  251. return;
  252. }
  253. //else
  254. //{
  255. // LOG.WriteLog(eEvent.ERR_PUF, Module.ToString(), $"Loader1 Current State {(LOADERSTATE)_loaderEntity.State} is not avaible");
  256. // _state = RState.Failed;
  257. //}
  258. }
  259. /// <summary>
  260. /// PUF Entity运动至Robot准备让robot pick
  261. /// </summary>
  262. private void PostPufEntityGotoRobotForPick()
  263. {
  264. if (_pufEntity.State == (int)PUFSTATE.AferSwapParkStation)
  265. {
  266. bool result = _pufEntity.CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(),
  267. (int)PUFMSG.ReadyForRobotPick);
  268. if (result)
  269. {
  270. NotifyWaferTaskSchedulerLoaderComplete();
  271. _currentOperation = OperationStep.GotoRobotForPick;
  272. LOG.WriteLog(eEvent.INFO_PUF, Module.ToString(), "Current Operation is GotoRobotForPick");
  273. }
  274. }
  275. }
  276. /// <summary>
  277. /// 通知Wafer对应的SchedulerLoader工序已经完成
  278. /// </summary>
  279. private void NotifyWaferTaskSchedulerLoaderComplete()
  280. {
  281. //puf A面是否存在Wafer
  282. if (WaferManager.Instance.CheckHasWafer(_pufEntity.Module, 0))
  283. {
  284. WaferInfo waferInfo = WaferManager.Instance.GetWafer(_pufEntity.Module, 0);
  285. if (waferInfo!=null&&waferInfo.WaferType==WaferType.Production)
  286. {
  287. _isProductionWafer = true;
  288. WaferTask waferTask = WaferTaskManager.Instance.GetWaferTask(waferInfo.WaferID);
  289. if (waferTask!=null)
  290. {
  291. waferTask.UpdateLoaderSchedulerSequenceComplete();
  292. }
  293. }
  294. }
  295. }
  296. /// <summary>
  297. /// 将Dummy片移动至Dummy Cassete
  298. /// </summary>
  299. private void PostEfemRobotTransferToDummyCassete()
  300. {
  301. if (_pufEntity.State == (int)PUFSTATE.WaitForRobotPick)
  302. {
  303. //生产片待EfemRobot取完片进行PufBackToPark状态
  304. if (_isProductionWafer)
  305. {
  306. bool hasWafer = WaferManager.Instance.CheckHasWafer(_pufEntity.Module, 0);
  307. if (!hasWafer)
  308. {
  309. _currentOperation = OperationStep.PufBackToPark;
  310. LOG.WriteLog(eEvent.INFO_PUF, Module.ToString(), "Current Operation is PufBackToPark");
  311. }
  312. }
  313. else
  314. {
  315. //A面Wafer
  316. WaferInfo waferInfo = WaferManager.Instance.GetWafer(_pufEntity.Module, 0);
  317. if (waferInfo == null)
  318. {
  319. return;
  320. }
  321. //Dummy片
  322. if (waferInfo.WaferType == WaferType.Assit)
  323. {
  324. if (_efemEntity.IsIdle)
  325. {
  326. var result = SchedulerSequenceManager.Instance.GetAvaibleDummySlots();
  327. if (result.moduleName != ModuleName.Unknown)
  328. {
  329. MoveItem moveItem = new MoveItem(_pufEntity.Module, 0, result.moduleName, result.slot, Aitex.Sorter.Common.Hand.Blade1);
  330. if(RobotMoveHelper.Instance.IsIdle)
  331. {
  332. RobotMoveHelper.Instance.Start(moveItem,Module.ToString());
  333. _currentOperation = OperationStep.WaitForRobotPick;
  334. LOG.WriteLog(eEvent.INFO_PUF, Module.ToString(), "Current Operation is WaitForRobotPick");
  335. }
  336. }
  337. else
  338. {
  339. LOG.WriteBackgroundLog(eEvent.WARN_PUF, Module.ToString(), "dummy slot is empty");
  340. }
  341. }
  342. else
  343. {
  344. LOG.WriteBackgroundLog(eEvent.WARN_PUF, Module.ToString(), $"wafer {waferInfo.WaferID} efem is not idle");
  345. }
  346. }
  347. else
  348. {
  349. LOG.WriteBackgroundLog(eEvent.WARN_PUF, Module.ToString(), $"wafer {waferInfo.WaferID} is not dummy wafer");
  350. }
  351. }
  352. }
  353. }
  354. /// <summary>
  355. /// 检验前置条件
  356. /// </summary>
  357. /// <param name="sequenceIndex"></param>
  358. /// <param name="parameter"></param>
  359. /// <returns></returns>
  360. public override bool CheckPrecondition(List<SchedulerSequence> schedulerSequences, int sequenceIndex, object parameter, string materialId, ref string reason)
  361. {
  362. if (_state == RState.Running)
  363. {
  364. reason = "scheduler module is already running";
  365. return false;
  366. }
  367. if (_pufEntity==null)
  368. {
  369. reason = "Puf entity is null";
  370. return false;
  371. }
  372. PufSchedulerParameter pufParameter=(PufSchedulerParameter)parameter;
  373. if(pufParameter.IsForward)
  374. {
  375. if (_pufEntity.State == (int)PUFSTATE.WaitForRobotPlace)
  376. {
  377. return true;
  378. }
  379. else
  380. {
  381. reason = $"{_pufEntity.Module} forward,but state is not WaitForRobotPlace";
  382. return false;
  383. }
  384. }
  385. else
  386. {
  387. if (_pufEntity.State == (int)PUFSTATE.WaitForRobotPick)
  388. {
  389. return true;
  390. }
  391. else
  392. {
  393. reason = $"{_pufEntity.Module} backward,but state is not WaitForRobotPick";
  394. return false;
  395. }
  396. }
  397. }
  398. /// <summary>
  399. /// 获取可用资源
  400. /// </summary>
  401. /// <param name="sequenceIndex"></param>
  402. /// <param name="parameter"></param>
  403. /// <returns></returns>
  404. public override bool GetAvaibleMaterial(int sequenceIndex, object parameter)
  405. {
  406. return true;
  407. }
  408. }
  409. }