SchedulerLoader.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. bool result = ExecuteLoadSide(loadComplete,loaderParameter.LoadCompleteToTransporterSide);
  114. if (result)
  115. {
  116. _currentStep = SchedulerStep.LoadingFirst;
  117. }
  118. }
  119. else if (_currentStep == SchedulerStep.LoadingFirst)
  120. {
  121. if (_loaderEntity.IsIdle)
  122. {
  123. if (loaderParameter.WaferCount == 1)
  124. {
  125. if (needFlip)
  126. {
  127. bool loaderResult= _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, Module.ToString(),
  128. (int)LoaderMSG.WaitFlip);
  129. if (loaderResult)
  130. {
  131. _state = RState.End;
  132. _currentStep = SchedulerStep.None;
  133. }
  134. }
  135. else
  136. {
  137. _state = RState.End;
  138. _currentStep = SchedulerStep.None;
  139. }
  140. }
  141. else
  142. {
  143. bool result = EnterReadyForPuf();
  144. if (result)
  145. {
  146. _currentStep = SchedulerStep.ReadyForPuf;
  147. _currentWaferIndex=2;
  148. }
  149. }
  150. }
  151. }
  152. else if (_currentStep == SchedulerStep.ReadyForPuf)
  153. {
  154. if (_loaderEntity.State == (int)LOADERSTATE.WaitForLoad)
  155. {
  156. bool result = ExecuteLoadSide(true,loaderParameter.LoadCompleteToTransporterSide);
  157. if (result)
  158. {
  159. _currentStep = SchedulerStep.LoadingSecond;
  160. }
  161. }
  162. }
  163. else if (_currentStep == SchedulerStep.LoadingSecond)
  164. {
  165. if (_loaderEntity.IsIdle)
  166. {
  167. _state = RState.End;
  168. _currentStep = SchedulerStep.None;
  169. }
  170. }
  171. return true;
  172. }
  173. /// <summary>
  174. /// 执行Loader Load动作
  175. /// </summary>
  176. /// <param name="loadComplete"></param>
  177. /// <param name="completeSide"></param>
  178. /// <returns></returns>
  179. private bool ExecuteLoadSide(bool loadComplete,string completeSide)
  180. {
  181. if (_puf1Entity.State == (int)PUFSTATE.AferSwapParkStation || (_puf1Entity.IsIdle && _puf1Entity.IsBackToParkStation))
  182. {
  183. JetAxisBase tiltAAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.TiltA");
  184. JetAxisBase tiltBAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.TiltB");
  185. double tiltAPosition = tiltAAxis.MotionData.MotorPosition;
  186. double tiltBPosition = tiltBAxis.MotionData.MotorPosition;
  187. bool tiltAHori = tiltAAxis.CheckPositionIsInStation(tiltAPosition, "HORI");
  188. bool tiltBHori = tiltBAxis.CheckPositionIsInStation(tiltBPosition, "HORI");
  189. string side = tiltAHori ? "SideA" : (tiltBHori ? "SideB" : "");
  190. if (string.IsNullOrEmpty(side))
  191. {
  192. return false;
  193. }
  194. return _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, Module.ToString(),
  195. (int)LoaderMSG.LoadSide, side, loadComplete,completeSide);
  196. }
  197. return false;
  198. }
  199. /// <summary>
  200. /// 第二次进入WaitForUnload
  201. /// </summary>
  202. /// <returns></returns>
  203. private bool EnterReadyForPuf()
  204. {
  205. return _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, Module.ToString(),
  206. (int)LoaderMSG.ReadyForPuf);
  207. }
  208. /// <summary>
  209. /// 检验前置条件
  210. /// </summary>
  211. /// <param name="sequenceIndex"></param>
  212. /// <param name="parameter"></param>
  213. /// <returns></returns>
  214. public override bool CheckPrecondition(List<SchedulerSequence> schedulerSequences, int sequenceIndex, object parameter, string materialId,ref string reason)
  215. {
  216. if (_state == RState.Running)
  217. {
  218. reason = "scheduler module is already running";
  219. return false;
  220. }
  221. if (_loaderEntity.IsIdle)
  222. {
  223. reason = "loader is idle";
  224. return false;
  225. }
  226. if (_loaderEntity.WaferHolderInfo == null)
  227. {
  228. reason = "loader has no wafer shuttle";
  229. return false;
  230. }
  231. if (_loaderEntity.WaferHolderInfo.Id != materialId)
  232. {
  233. reason = $"{_loaderEntity.Module} wafer shuttle {_loaderEntity.WaferHolderInfo.Id} is not matched with {materialId}";
  234. return false;
  235. }
  236. return true;
  237. }
  238. }
  239. }