SchedulerLoader.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. #endregion
  41. #region 属性
  42. public override bool IsIdle
  43. {
  44. get { return _state == RState.End; }
  45. }
  46. public override bool IsError
  47. {
  48. get { return _state == RState.Failed || _state == RState.Timeout; }
  49. }
  50. #endregion
  51. /// <summary>
  52. /// 构造函数
  53. /// </summary>
  54. /// <param name="module"></param>
  55. public SchedulerLoader(ModuleName module) : base(module.ToString())
  56. {
  57. _loaderEntity = Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(module.ToString());
  58. _puf1Entity = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(ModuleName.PUF1.ToString());
  59. }
  60. /// <summary>
  61. /// 执行
  62. /// </summary>
  63. /// <param name="parameter"></param>
  64. /// <returns></returns>
  65. public override bool RunProcess(object recipe, object parameter, List<SchedulerSyncModuleMessage> syncModuleMessages)
  66. {
  67. _state = RState.Running;
  68. _currentStep = SchedulerStep.WaitUnload;
  69. _currentWaferIndex = 1;
  70. return true;
  71. }
  72. /// <summary>
  73. /// 监控执行
  74. /// </summary>
  75. /// <returns></returns>
  76. public override bool MonitorProcess(SchedulerSequence schedulerSequence, bool hasMatchWafer)
  77. {
  78. if (_currentStep == SchedulerStep.WaitUnload)
  79. {
  80. if (_loaderEntity.State == (int)LOADERSTATE.WaitForUnload && WaferHolderManager.Instance.HasWaferHolder("Loader"))
  81. {
  82. JetAxisBase _loadTransporterGantryAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Transporter2}.Gantry");
  83. if (_loadTransporterGantryAxis != null && _loadTransporterGantryAxis.JudgeCompareTargetStation("Loader", "Right"))
  84. {
  85. WaferInfo preLoaderWaferInfo = WaferHolderTaskManager.Instance.GetPreLoaderHasWafer();
  86. //触发loaderEntity UnloadAll
  87. if (preLoaderWaferInfo != null && !string.IsNullOrEmpty(preLoaderWaferInfo.LoaderSide))
  88. {
  89. _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, ModuleName.Loader1.ToString(),
  90. (int)LoaderMSG.UnloadSide, preLoaderWaferInfo.LoaderSide);
  91. }
  92. }
  93. }
  94. else if(_loaderEntity.State==(int)LOADERSTATE.Unloading)
  95. {
  96. _currentStep = SchedulerStep.WaitLoad;
  97. }
  98. else if (_loaderEntity.State == (int)LOADERSTATE.WaitForLoad)
  99. {
  100. _currentStep = SchedulerStep.WaitLoad;
  101. }
  102. return true;
  103. }
  104. LoaderParameter loaderParameter =(LoaderParameter)schedulerSequence.Parameters;
  105. bool loadComplete = loaderParameter.WaferCount == _currentWaferIndex;
  106. bool needFlip = loaderParameter.NeedWaitFlip;
  107. if (_currentStep == SchedulerStep.WaitLoad)
  108. {
  109. if (_loaderEntity.State != (int)LOADERSTATE.WaitForLoad)
  110. {
  111. return false;
  112. }
  113. if (_puf1Entity.State == (int)PUFSTATE.AferSwapParkStation)
  114. {
  115. bool result = ExecuteLoadSide(loadComplete, loaderParameter.LoadCompleteToTransporterSide);
  116. if (result)
  117. {
  118. _currentStep = SchedulerStep.LoadingFirst;
  119. }
  120. }
  121. }
  122. else if (_currentStep == SchedulerStep.LoadingFirst)
  123. {
  124. if (_loaderEntity.IsIdle)
  125. {
  126. if (loaderParameter.WaferCount == 1)
  127. {
  128. if (needFlip)
  129. {
  130. bool loaderResult= _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, Module.ToString(),
  131. (int)LoaderMSG.WaitFlip);
  132. if (loaderResult)
  133. {
  134. _state = RState.End;
  135. _currentStep = SchedulerStep.None;
  136. }
  137. }
  138. else
  139. {
  140. _state = RState.End;
  141. _currentStep = SchedulerStep.None;
  142. }
  143. }
  144. else
  145. {
  146. EnterReadyForPuf();
  147. }
  148. }
  149. else if (_loaderEntity.State == (int)LOADERSTATE.WaitForUnload)
  150. {
  151. ExecuteForSecondUnload();
  152. }
  153. else if (_loaderEntity.State == (int)LOADERSTATE.Unloading)
  154. {
  155. _currentStep = SchedulerStep.ReadyForPuf;
  156. _currentWaferIndex = 2;
  157. }
  158. }
  159. else if (_currentStep == SchedulerStep.ReadyForPuf)
  160. {
  161. if (_loaderEntity.State == (int)LOADERSTATE.WaitForLoad)
  162. {
  163. if (_puf1Entity.State == (int)PUFSTATE.AferSwapParkStation)
  164. {
  165. bool result = ExecuteLoadSide(true, loaderParameter.LoadCompleteToTransporterSide);
  166. if (result)
  167. {
  168. _currentStep = SchedulerStep.LoadingSecond;
  169. }
  170. }
  171. }
  172. }
  173. else if (_currentStep == SchedulerStep.LoadingSecond)
  174. {
  175. if (_loaderEntity.IsIdle)
  176. {
  177. _state = RState.End;
  178. _currentStep = SchedulerStep.None;
  179. }
  180. }
  181. return true;
  182. }
  183. /// <summary>
  184. /// 执行Loader Load动作
  185. /// </summary>
  186. /// <param name="loadComplete"></param>
  187. /// <param name="completeSide"></param>
  188. /// <returns></returns>
  189. private bool ExecuteLoadSide(bool loadComplete,string completeSide)
  190. {
  191. if (_puf1Entity.State == (int)PUFSTATE.AferSwapParkStation || (_puf1Entity.IsIdle && _puf1Entity.IsBackToParkStation))
  192. {
  193. JetAxisBase tiltAAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.TiltA");
  194. JetAxisBase tiltBAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.TiltB");
  195. double tiltAPosition = tiltAAxis.MotionData.MotorPosition;
  196. double tiltBPosition = tiltBAxis.MotionData.MotorPosition;
  197. bool tiltAHori = tiltAAxis.CheckPositionIsInStation(tiltAPosition, "HORI");
  198. bool tiltBHori = tiltBAxis.CheckPositionIsInStation(tiltBPosition, "HORI");
  199. string side = tiltAHori ? "SideA" : (tiltBHori ? "SideB" : "");
  200. if (string.IsNullOrEmpty(side))
  201. {
  202. return false;
  203. }
  204. return _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, Module.ToString(),
  205. (int)LoaderMSG.LoadSide, side, loadComplete,completeSide);
  206. }
  207. return false;
  208. }
  209. /// <summary>
  210. /// 第二次进入WaitForUnload
  211. /// </summary>
  212. /// <returns></returns>
  213. private void EnterReadyForPuf()
  214. {
  215. _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, ModuleName.Loader1.ToString(),
  216. (int)LoaderMSG.ReadyForPuf);
  217. }
  218. /// <summary>
  219. /// 执行第二次unload
  220. /// </summary>
  221. /// <returns></returns>
  222. private void ExecuteForSecondUnload()
  223. {
  224. if (_loaderEntity.State == (int)LOADERSTATE.WaitForUnload)
  225. {
  226. if (!WaferHolderManager.Instance.HasWaferHolder("Loader"))
  227. {
  228. return;
  229. }
  230. JetAxisBase _loadTransporterGantryAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Transporter2}.Gantry");
  231. if (_loadTransporterGantryAxis != null && _loadTransporterGantryAxis.JudgeCompareTargetStation("Loader", "Right"))
  232. {
  233. WaferInfo preLoaderWaferInfo = WaferHolderTaskManager.Instance.GetPreLoaderHasWafer();
  234. //触发loaderEntity UnloadAll
  235. if (preLoaderWaferInfo != null && !string.IsNullOrEmpty(preLoaderWaferInfo.LoaderSide))
  236. {
  237. bool result = _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, ModuleName.Loader1.ToString(),
  238. (int)LoaderMSG.UnloadSide, preLoaderWaferInfo.LoaderSide);
  239. }
  240. }
  241. }
  242. }
  243. /// <summary>
  244. /// 检验前置条件
  245. /// </summary>
  246. /// <param name="sequenceIndex"></param>
  247. /// <param name="parameter"></param>
  248. /// <returns></returns>
  249. public override bool CheckPrecondition(List<SchedulerSequence> schedulerSequences, int sequenceIndex, object parameter, string materialId,ref string reason)
  250. {
  251. if (_state == RState.Running)
  252. {
  253. reason = "scheduler module is already running";
  254. return false;
  255. }
  256. if (_loaderEntity.IsIdle)
  257. {
  258. reason = "loader is idle";
  259. return false;
  260. }
  261. if (_loaderEntity.WaferHolderInfo == null)
  262. {
  263. reason = "loader has no wafer shuttle";
  264. return false;
  265. }
  266. if (_loaderEntity.WaferHolderInfo.Id != materialId)
  267. {
  268. reason = $"{_loaderEntity.Module} wafer shuttle {_loaderEntity.WaferHolderInfo.Id} is not matched with {materialId}";
  269. return false;
  270. }
  271. return true;
  272. }
  273. }
  274. }