SchedulerLoader.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. using Aitex.Core.RT.Fsm;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.Util;
  4. using MECF.Framework.Common.CommonData;
  5. using MECF.Framework.Common.Equipment;
  6. using CyberX8_Core;
  7. using CyberX8_RT.Modules;
  8. using CyberX8_RT.Modules.Loader;
  9. using CyberX8_RT.Modules.PUF;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using MECF.Framework.Common.SubstrateTrackings;
  16. using CyberX8_RT.Modules.Metal;
  17. using CyberX8_RT.Devices.AXIS;
  18. using Aitex.Core.RT.Device;
  19. using MECF.Framework.Common.WaferHolder;
  20. using Aitex.Core.Common;
  21. using CyberX8_RT.Dispatch;
  22. namespace CyberX8_RT.Schedulers.Loader
  23. {
  24. public class SchedulerLoader : SchedulerModule
  25. {
  26. private enum SchedulerStep
  27. {
  28. None,
  29. WaitUnload,
  30. WaitLoad,
  31. LoadingFirst,
  32. ReadyForPuf,
  33. LoadingSecond
  34. }
  35. #region 内部变量
  36. private LoaderEntity _loaderEntity;
  37. private PUFEntity _puf1Entity;
  38. private SchedulerStep _currentStep;
  39. private int _currentWaferIndex = 1;
  40. private string _waferGroup = "";
  41. #endregion
  42. #region 属性
  43. public override bool IsIdle
  44. {
  45. get { return _state == RState.End; }
  46. }
  47. public override bool IsError
  48. {
  49. get { return _state == RState.Failed || _state == RState.Timeout; }
  50. }
  51. #endregion
  52. /// <summary>
  53. /// 构造函数
  54. /// </summary>
  55. /// <param name="module"></param>
  56. public SchedulerLoader(ModuleName module) : base(module.ToString())
  57. {
  58. _loaderEntity = Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(module.ToString());
  59. _puf1Entity = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(ModuleName.PUF1.ToString());
  60. }
  61. /// <summary>
  62. /// 执行
  63. /// </summary>
  64. /// <param name="parameter"></param>
  65. /// <returns></returns>
  66. public override bool RunProcess(object recipe, object parameter, List<SchedulerSyncModuleMessage> syncModuleMessages)
  67. {
  68. _state = RState.Running;
  69. _currentStep = SchedulerStep.WaitUnload;
  70. _currentWaferIndex = 1;
  71. _waferGroup = "";
  72. return true;
  73. }
  74. /// <summary>
  75. /// 监控执行
  76. /// </summary>
  77. /// <returns></returns>
  78. public override bool MonitorProcess(SchedulerSequence schedulerSequence, bool hasMatchWafer)
  79. {
  80. if (_currentStep == SchedulerStep.WaitUnload)
  81. {
  82. if (_loaderEntity.State == (int)LOADERSTATE.WaitForUnload && WaferHolderManager.Instance.HasWaferHolder("Loader"))
  83. {
  84. JetAxisBase _loadTransporterGantryAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Transporter2}.Gantry");
  85. if (_loadTransporterGantryAxis != null && _loadTransporterGantryAxis.JudgeCompareTargetStation("Loader", "Right"))
  86. {
  87. WaferInfo preLoaderWaferInfo = WaferHolderTaskManager.Instance.GetPreLoaderHasWafer();
  88. //触发loaderEntity UnloadAll
  89. if (preLoaderWaferInfo != null && !string.IsNullOrEmpty(preLoaderWaferInfo.LoaderSide))
  90. {
  91. _waferGroup = AnalyseWaferGroup(preLoaderWaferInfo);
  92. _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, ModuleName.Loader1.ToString(),
  93. (int)LoaderMSG.UnloadSide, preLoaderWaferInfo.LoaderSide,_waferGroup);
  94. }
  95. }
  96. }
  97. else if(_loaderEntity.State==(int)LOADERSTATE.Unloading)
  98. {
  99. _currentStep = SchedulerStep.WaitLoad;
  100. }
  101. else if (_loaderEntity.State == (int)LOADERSTATE.WaitForLoad)
  102. {
  103. _currentStep = SchedulerStep.WaitLoad;
  104. }
  105. return true;
  106. }
  107. LoaderParameter loaderParameter =(LoaderParameter)schedulerSequence.Parameters;
  108. bool loadComplete = loaderParameter.WaferCount == _currentWaferIndex;
  109. bool needFlip = loaderParameter.NeedWaitFlip;
  110. if (_currentStep == SchedulerStep.WaitLoad)
  111. {
  112. if (_loaderEntity.State != (int)LOADERSTATE.WaitForLoad)
  113. {
  114. return false;
  115. }
  116. if (_puf1Entity.State == (int)PUFSTATE.AferSwapParkStation)
  117. {
  118. bool result = ExecuteLoadSide(loadComplete, loaderParameter.LoadCompleteToTransporterSide);
  119. if (result)
  120. {
  121. _currentStep = SchedulerStep.LoadingFirst;
  122. }
  123. }
  124. }
  125. else if (_currentStep == SchedulerStep.LoadingFirst)
  126. {
  127. if (_loaderEntity.IsIdle)
  128. {
  129. if (loaderParameter.WaferCount == 1)
  130. {
  131. if (needFlip)
  132. {
  133. bool loaderResult= _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, Module.ToString(),
  134. (int)LoaderMSG.WaitFlip);
  135. if (loaderResult)
  136. {
  137. _state = RState.End;
  138. _currentStep = SchedulerStep.None;
  139. }
  140. }
  141. else
  142. {
  143. _state = RState.End;
  144. _currentStep = SchedulerStep.None;
  145. }
  146. }
  147. else
  148. {
  149. EnterReadyForPuf();
  150. }
  151. }
  152. else if (_loaderEntity.State == (int)LOADERSTATE.WaitForUnload)
  153. {
  154. ExecuteForSecondUnload();
  155. }
  156. else if (_loaderEntity.State == (int)LOADERSTATE.Unloading)
  157. {
  158. _currentStep = SchedulerStep.ReadyForPuf;
  159. _currentWaferIndex = 2;
  160. }
  161. }
  162. else if (_currentStep == SchedulerStep.ReadyForPuf)
  163. {
  164. if (_loaderEntity.State == (int)LOADERSTATE.WaitForLoad)
  165. {
  166. if (_puf1Entity.State == (int)PUFSTATE.AferSwapParkStation)
  167. {
  168. bool result = ExecuteLoadSide(true, loaderParameter.LoadCompleteToTransporterSide);
  169. if (result)
  170. {
  171. _currentStep = SchedulerStep.LoadingSecond;
  172. }
  173. }
  174. }
  175. }
  176. else if (_currentStep == SchedulerStep.LoadingSecond)
  177. {
  178. if (_loaderEntity.IsIdle)
  179. {
  180. _state = RState.End;
  181. _currentStep = SchedulerStep.None;
  182. }
  183. }
  184. return true;
  185. }
  186. /// <summary>
  187. /// 分析得到Wafer组
  188. /// </summary>
  189. /// <param name="waferInfo"></param>
  190. /// <returns></returns>
  191. private string AnalyseWaferGroup(WaferInfo waferInfo)
  192. {
  193. string matchWaferId = WaferTaskManager.Instance.GetMatchWaferIdByWaferId(waferInfo.WaferID);
  194. string cycleStr = "";
  195. if (waferInfo.WaferType == WaferType.Production)
  196. {
  197. int cycleCount = CycleManager.Instance.GetLoadportCycleCount($"LP{waferInfo.OriginStation}");
  198. int cycleSetPoint = CycleManager.Instance.GetLoadportCycleSetPoint($"LP{waferInfo.OriginStation}");
  199. cycleStr = cycleSetPoint > 1 ? $"_Cycle-{cycleCount + 1}" : "";
  200. }
  201. if (string.IsNullOrEmpty(matchWaferId))
  202. {
  203. return $"{waferInfo.LotId}_LP{waferInfo.OriginStation}-{waferInfo.OriginSlot}-0{cycleStr}";
  204. }
  205. else
  206. {
  207. WaferInfo matchedWafer = WaferManager.Instance.GetWaferByWaferId(matchWaferId);
  208. if (matchedWafer != null && !matchedWafer.IsEmpty)
  209. {
  210. if (matchedWafer.WaferType == WaferType.Assit)
  211. {
  212. return $"{waferInfo.LotId}_LP{waferInfo.OriginStation}-{waferInfo.OriginSlot+1}{cycleStr}";
  213. }
  214. else
  215. {
  216. int cycleCountM = CycleManager.Instance.GetLoadportCycleCount($"LP{matchedWafer.OriginStation}");
  217. int cycleSetPointM = CycleManager.Instance.GetLoadportCycleSetPoint($"LP{matchedWafer.OriginStation}");
  218. string cycleStrM = cycleSetPointM > 1 ? $"_Cycle-{cycleCountM + 1}" : "";
  219. if ((waferInfo.OriginStation > matchedWafer.OriginStation) || (waferInfo.OriginStation == matchedWafer.OriginStation && waferInfo.OriginSlot > matchedWafer.OriginSlot))
  220. {
  221. string lotStr = waferInfo.LotId == matchedWafer.LotId ? "" : $"_{waferInfo.LotId}";
  222. return $"{matchedWafer.LotId}_LP{matchedWafer.OriginStation}-{matchedWafer.OriginSlot + 1}{cycleStrM}{lotStr}_LP{waferInfo.OriginStation}-{waferInfo.OriginSlot + 1}{cycleStr}";
  223. }
  224. else
  225. {
  226. string lotStr = waferInfo.LotId == matchedWafer.LotId ? "" : $"_{matchedWafer.LotId}";
  227. return $"{waferInfo.LotId}_LP{waferInfo.OriginStation}-{waferInfo.OriginSlot + 1}{cycleStr}{lotStr}_LP{matchedWafer.OriginStation}-{matchedWafer.OriginSlot + 1}{cycleStrM}";
  228. }
  229. }
  230. }
  231. else
  232. {
  233. return $"{waferInfo.LotId}_LP{waferInfo.SourceStation}-{waferInfo.OriginSlot+1}{cycleStr}";
  234. }
  235. }
  236. }
  237. /// <summary>
  238. /// 执行Loader Load动作
  239. /// </summary>
  240. /// <param name="loadComplete"></param>
  241. /// <param name="completeSide"></param>
  242. /// <returns></returns>
  243. private bool ExecuteLoadSide(bool loadComplete,string completeSide)
  244. {
  245. if (_puf1Entity.State == (int)PUFSTATE.AferSwapParkStation || (_puf1Entity.IsIdle && _puf1Entity.IsBackToParkStation))
  246. {
  247. JetAxisBase tiltAAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.TiltA");
  248. JetAxisBase tiltBAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.TiltB");
  249. double tiltAPosition = tiltAAxis.MotionData.MotorPosition;
  250. double tiltBPosition = tiltBAxis.MotionData.MotorPosition;
  251. bool tiltAHori = tiltAAxis.CheckPositionIsInStation(tiltAPosition, "HORI");
  252. bool tiltBHori = tiltBAxis.CheckPositionIsInStation(tiltBPosition, "HORI");
  253. string side = tiltAHori ? "SideA" : (tiltBHori ? "SideB" : "");
  254. if (string.IsNullOrEmpty(side))
  255. {
  256. return false;
  257. }
  258. return _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, Module.ToString(),
  259. (int)LoaderMSG.LoadSide, side, loadComplete,completeSide,_waferGroup);
  260. }
  261. return false;
  262. }
  263. /// <summary>
  264. /// 第二次进入WaitForUnload
  265. /// </summary>
  266. /// <returns></returns>
  267. private void EnterReadyForPuf()
  268. {
  269. _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, ModuleName.Loader1.ToString(),
  270. (int)LoaderMSG.ReadyForPuf);
  271. }
  272. /// <summary>
  273. /// 执行第二次unload
  274. /// </summary>
  275. /// <returns></returns>
  276. private void ExecuteForSecondUnload()
  277. {
  278. if (_loaderEntity.State == (int)LOADERSTATE.WaitForUnload)
  279. {
  280. if (!WaferHolderManager.Instance.HasWaferHolder("Loader"))
  281. {
  282. return;
  283. }
  284. JetAxisBase _loadTransporterGantryAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Transporter2}.Gantry");
  285. if (_loadTransporterGantryAxis != null && _loadTransporterGantryAxis.JudgeCompareTargetStation("Loader", "Right"))
  286. {
  287. WaferInfo preLoaderWaferInfo = WaferHolderTaskManager.Instance.GetPreLoaderHasWafer();
  288. //触发loaderEntity UnloadAll
  289. if (preLoaderWaferInfo != null && !string.IsNullOrEmpty(preLoaderWaferInfo.LoaderSide))
  290. {
  291. bool result = _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, ModuleName.Loader1.ToString(),
  292. (int)LoaderMSG.UnloadSide, preLoaderWaferInfo.LoaderSide, _waferGroup);
  293. }
  294. }
  295. }
  296. }
  297. /// <summary>
  298. /// 检验前置条件
  299. /// </summary>
  300. /// <param name="sequenceIndex"></param>
  301. /// <param name="parameter"></param>
  302. /// <returns></returns>
  303. public override bool CheckPrecondition(List<SchedulerSequence> schedulerSequences, int sequenceIndex, object parameter, string materialId,ref string reason)
  304. {
  305. if (_state == RState.Running)
  306. {
  307. reason = "scheduler module is already running";
  308. return false;
  309. }
  310. if (_loaderEntity.IsIdle)
  311. {
  312. reason = "loader is idle";
  313. return false;
  314. }
  315. if (_loaderEntity.WaferHolderInfo == null)
  316. {
  317. reason = "loader has no wafer shuttle";
  318. return false;
  319. }
  320. if (_loaderEntity.WaferHolderInfo.Id != materialId)
  321. {
  322. reason = $"{_loaderEntity.Module} wafer shuttle {_loaderEntity.WaferHolderInfo.Id} is not matched with {materialId}";
  323. return false;
  324. }
  325. return true;
  326. }
  327. }
  328. }