SchedulerLoader.cs 8.7 KB

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