SchedulerLoader.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. if (string.IsNullOrEmpty(matchWaferId))
  195. {
  196. return $"{waferInfo.OriginStation}_{waferInfo.OriginSlot}_0";
  197. }
  198. else
  199. {
  200. WaferInfo matchedWafer = WaferManager.Instance.GetWaferByWaferId(matchWaferId);
  201. if (matchedWafer != null && !matchedWafer.IsEmpty)
  202. {
  203. if (matchedWafer.WaferType == WaferType.Assit)
  204. {
  205. return $"LP{waferInfo.OriginStation}_{waferInfo.OriginSlot+1}_0";
  206. }
  207. else
  208. {
  209. return $"LP{waferInfo.OriginStation}_{waferInfo.OriginSlot+1}_LP{matchedWafer.OriginStation}_{matchedWafer.OriginSlot+1}";
  210. }
  211. }
  212. else
  213. {
  214. return $"LP{waferInfo.SourceStation}_{waferInfo.OriginSlot+1}_0";
  215. }
  216. }
  217. }
  218. /// <summary>
  219. /// 执行Loader Load动作
  220. /// </summary>
  221. /// <param name="loadComplete"></param>
  222. /// <param name="completeSide"></param>
  223. /// <returns></returns>
  224. private bool ExecuteLoadSide(bool loadComplete,string completeSide)
  225. {
  226. if (_puf1Entity.State == (int)PUFSTATE.AferSwapParkStation || (_puf1Entity.IsIdle && _puf1Entity.IsBackToParkStation))
  227. {
  228. JetAxisBase tiltAAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.TiltA");
  229. JetAxisBase tiltBAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.TiltB");
  230. double tiltAPosition = tiltAAxis.MotionData.MotorPosition;
  231. double tiltBPosition = tiltBAxis.MotionData.MotorPosition;
  232. bool tiltAHori = tiltAAxis.CheckPositionIsInStation(tiltAPosition, "HORI");
  233. bool tiltBHori = tiltBAxis.CheckPositionIsInStation(tiltBPosition, "HORI");
  234. string side = tiltAHori ? "SideA" : (tiltBHori ? "SideB" : "");
  235. if (string.IsNullOrEmpty(side))
  236. {
  237. return false;
  238. }
  239. return _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, Module.ToString(),
  240. (int)LoaderMSG.LoadSide, side, loadComplete,completeSide,_waferGroup);
  241. }
  242. return false;
  243. }
  244. /// <summary>
  245. /// 第二次进入WaitForUnload
  246. /// </summary>
  247. /// <returns></returns>
  248. private void EnterReadyForPuf()
  249. {
  250. _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, ModuleName.Loader1.ToString(),
  251. (int)LoaderMSG.ReadyForPuf);
  252. }
  253. /// <summary>
  254. /// 执行第二次unload
  255. /// </summary>
  256. /// <returns></returns>
  257. private void ExecuteForSecondUnload()
  258. {
  259. if (_loaderEntity.State == (int)LOADERSTATE.WaitForUnload)
  260. {
  261. if (!WaferHolderManager.Instance.HasWaferHolder("Loader"))
  262. {
  263. return;
  264. }
  265. JetAxisBase _loadTransporterGantryAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Transporter2}.Gantry");
  266. if (_loadTransporterGantryAxis != null && _loadTransporterGantryAxis.JudgeCompareTargetStation("Loader", "Right"))
  267. {
  268. WaferInfo preLoaderWaferInfo = WaferHolderTaskManager.Instance.GetPreLoaderHasWafer();
  269. //触发loaderEntity UnloadAll
  270. if (preLoaderWaferInfo != null && !string.IsNullOrEmpty(preLoaderWaferInfo.LoaderSide))
  271. {
  272. bool result = _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, ModuleName.Loader1.ToString(),
  273. (int)LoaderMSG.UnloadSide, preLoaderWaferInfo.LoaderSide, _waferGroup);
  274. }
  275. }
  276. }
  277. }
  278. /// <summary>
  279. /// 检验前置条件
  280. /// </summary>
  281. /// <param name="sequenceIndex"></param>
  282. /// <param name="parameter"></param>
  283. /// <returns></returns>
  284. public override bool CheckPrecondition(List<SchedulerSequence> schedulerSequences, int sequenceIndex, object parameter, string materialId,ref string reason)
  285. {
  286. if (_state == RState.Running)
  287. {
  288. reason = "scheduler module is already running";
  289. return false;
  290. }
  291. if (_loaderEntity.IsIdle)
  292. {
  293. reason = "loader is idle";
  294. return false;
  295. }
  296. if (_loaderEntity.WaferHolderInfo == null)
  297. {
  298. reason = "loader has no wafer shuttle";
  299. return false;
  300. }
  301. if (_loaderEntity.WaferHolderInfo.Id != materialId)
  302. {
  303. reason = $"{_loaderEntity.Module} wafer shuttle {_loaderEntity.WaferHolderInfo.Id} is not matched with {materialId}";
  304. return false;
  305. }
  306. return true;
  307. }
  308. }
  309. }