SchedulerPuf.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. if(ModuleHelper.IsInstalled(ModuleName.PUF1))
  199. {
  200. PUFEntity puf1Entity = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(ModuleName.PUF1.ToString());
  201. //B面有Wafer
  202. if (!WaferManager.Instance.CheckHasWafer(ModuleName.PUF1,1))
  203. {
  204. return false;
  205. }
  206. }
  207. //Loader中没有WaferHolder
  208. if(_loaderEntity.WaferHolderInfo==null)
  209. {
  210. return false;
  211. }
  212. if (_loaderEntity.State == (int)LOADERSTATE.WaitForUnload)
  213. {
  214. JetAxisBase _loadTransporterGantryAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Transporter2}.Gantry");
  215. if (_loadTransporterGantryAxis != null && !_loadTransporterGantryAxis.JudgeCompareTargetStation("Loader", "Right"))
  216. {
  217. return false;
  218. }
  219. }
  220. return true;
  221. }
  222. /// <summary>
  223. /// LoaderEntity Unload All
  224. /// </summary>
  225. private void PostLoaderEntityUnloadAllSide()
  226. {
  227. //当前loader状态机为WaitForUnload,Unload放在SchedulerLoad中了
  228. //if (_loaderEntity.State == (int)LOADERSTATE.WaitForUnload&&_currentOperation==OperationStep.WaitForLoaderUnloadComplete)
  229. //{
  230. // //触发loaderEntity UnloadAll
  231. // _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, ModuleName.Loader1.ToString(),
  232. // (int)LoaderMSG.UnloadSide,_side);
  233. //}
  234. //若Loader Unload操作完成,状态变更为WaitForLoad,puf操作变更为Swap
  235. if (_loaderEntity.State == (int)LOADERSTATE.WaitForLoad)
  236. {
  237. _currentOperation = OperationStep.Swap;
  238. LOG.WriteLog(eEvent.INFO_PUF, Module.ToString(), "Current Operation is Swap");
  239. }
  240. else if (_loaderEntity.State == (int)LOADERSTATE.Unloading)
  241. {
  242. return;
  243. }
  244. //else
  245. //{
  246. // LOG.WriteLog(eEvent.ERR_PUF, Module.ToString(), $"Loader1 Current State {(LOADERSTATE)_loaderEntity.State} is not avaible");
  247. // _state = RState.Failed;
  248. //}
  249. }
  250. /// <summary>
  251. /// PUF Entity运动至Robot准备让robot pick
  252. /// </summary>
  253. private void PostPufEntityGotoRobotForPick()
  254. {
  255. if (_pufEntity.State == (int)PUFSTATE.AferSwapParkStation)
  256. {
  257. bool result = _pufEntity.CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(),
  258. (int)PUFMSG.ReadyForRobotPick);
  259. if (result)
  260. {
  261. NotifyWaferTaskSchedulerLoaderComplete();
  262. _currentOperation = OperationStep.GotoRobotForPick;
  263. LOG.WriteLog(eEvent.INFO_PUF, Module.ToString(), "Current Operation is GotoRobotForPick");
  264. }
  265. }
  266. }
  267. /// <summary>
  268. /// 通知Wafer对应的SchedulerLoader工序已经完成
  269. /// </summary>
  270. private void NotifyWaferTaskSchedulerLoaderComplete()
  271. {
  272. //puf A面是否存在Wafer
  273. if (WaferManager.Instance.CheckHasWafer(_pufEntity.Module, 0))
  274. {
  275. WaferInfo waferInfo = WaferManager.Instance.GetWafer(_pufEntity.Module, 0);
  276. if (waferInfo!=null&&waferInfo.WaferType==WaferType.Production)
  277. {
  278. _isProductionWafer = true;
  279. WaferTask waferTask = WaferTaskManager.Instance.GetWaferTask(waferInfo.WaferID);
  280. if (waferTask!=null)
  281. {
  282. waferTask.UpdateLoaderSchedulerSequenceComplete();
  283. }
  284. }
  285. }
  286. }
  287. /// <summary>
  288. /// 将Dummy片移动至Dummy Cassete
  289. /// </summary>
  290. private void PostEfemRobotTransferToDummyCassete()
  291. {
  292. if (_pufEntity.State == (int)PUFSTATE.WaitForRobotPick)
  293. {
  294. //生产片待EfemRobot取完片进行PufBackToPark状态
  295. if (_isProductionWafer)
  296. {
  297. bool hasWafer = WaferManager.Instance.CheckHasWafer(_pufEntity.Module, 0);
  298. if (!hasWafer)
  299. {
  300. _currentOperation = OperationStep.PufBackToPark;
  301. LOG.WriteLog(eEvent.INFO_PUF, Module.ToString(), "Current Operation is PufBackToPark");
  302. }
  303. }
  304. else
  305. {
  306. //A面Wafer
  307. WaferInfo waferInfo = WaferManager.Instance.GetWafer(_pufEntity.Module, 0);
  308. if (waferInfo == null)
  309. {
  310. return;
  311. }
  312. //Dummy片
  313. if (waferInfo.WaferType == WaferType.Assit)
  314. {
  315. if (_efemEntity.IsIdle)
  316. {
  317. var result = SchedulerSequenceManager.Instance.GetAvaibleDummySlots(waferInfo.Size);
  318. if (result.moduleName != ModuleName.Unknown)
  319. {
  320. MoveItem moveItem = new MoveItem(_pufEntity.Module, 0, result.moduleName, result.slot, Aitex.Sorter.Common.Hand.Blade1);
  321. if(RobotMoveHelper.Instance.IsIdle)
  322. {
  323. RobotMoveHelper.Instance.Start(moveItem,Module.ToString());
  324. _currentOperation = OperationStep.WaitForRobotPick;
  325. LOG.WriteLog(eEvent.INFO_PUF, Module.ToString(), "Current Operation is WaitForRobotPick");
  326. }
  327. }
  328. else
  329. {
  330. LOG.WriteBackgroundLog(eEvent.WARN_PUF, Module.ToString(), "dummy slot is empty");
  331. }
  332. }
  333. else
  334. {
  335. LOG.WriteBackgroundLog(eEvent.WARN_PUF, Module.ToString(), $"wafer {waferInfo.WaferID} efem is not idle");
  336. }
  337. }
  338. else
  339. {
  340. LOG.WriteBackgroundLog(eEvent.WARN_PUF, Module.ToString(), $"wafer {waferInfo.WaferID} is not dummy wafer");
  341. }
  342. }
  343. }
  344. }
  345. /// <summary>
  346. /// 检验前置条件
  347. /// </summary>
  348. /// <param name="sequenceIndex"></param>
  349. /// <param name="parameter"></param>
  350. /// <returns></returns>
  351. public override bool CheckPrecondition(List<SchedulerSequence> schedulerSequences, int sequenceIndex, object parameter, string materialId, ref string reason)
  352. {
  353. if (_state == RState.Running)
  354. {
  355. reason = "scheduler module is already running";
  356. return false;
  357. }
  358. if (_pufEntity==null)
  359. {
  360. reason = "Puf entity is null";
  361. return false;
  362. }
  363. PufSchedulerParameter pufParameter=(PufSchedulerParameter)parameter;
  364. if(pufParameter.IsForward)
  365. {
  366. if (_pufEntity.State == (int)PUFSTATE.WaitForRobotPlace)
  367. {
  368. return true;
  369. }
  370. else
  371. {
  372. reason = $"{_pufEntity.Module} forward,but state is not WaitForRobotPlace";
  373. return false;
  374. }
  375. }
  376. else
  377. {
  378. if (_pufEntity.State == (int)PUFSTATE.WaitForRobotPick)
  379. {
  380. return true;
  381. }
  382. else
  383. {
  384. reason = $"{_pufEntity.Module} backward,but state is not WaitForRobotPick";
  385. return false;
  386. }
  387. }
  388. }
  389. /// <summary>
  390. /// 获取可用资源
  391. /// </summary>
  392. /// <param name="sequenceIndex"></param>
  393. /// <param name="parameter"></param>
  394. /// <returns></returns>
  395. public override bool GetAvaibleMaterial(int sequenceIndex, object parameter)
  396. {
  397. return true;
  398. }
  399. }
  400. }