SchedulerLoader.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. namespace CyberX8_RT.Schedulers.Loader
  20. {
  21. public class SchedulerLoader : SchedulerModule
  22. {
  23. private enum SchedulerStep
  24. {
  25. WaitLoad,
  26. LoadingFirst,
  27. LoadingSecond
  28. }
  29. #region 内部变量
  30. private LoaderEntity _loaderEntity;
  31. private PUFEntity _puf1Entity;
  32. private SchedulerStep _currentStep;
  33. private int _currentWaferIndex = 0;
  34. #endregion
  35. #region 属性
  36. public override bool IsIdle
  37. {
  38. get { return _state == RState.End; }
  39. }
  40. public override bool IsError
  41. {
  42. get { return _state == RState.Failed || _state == RState.Timeout; }
  43. }
  44. #endregion
  45. /// <summary>
  46. /// 构造函数
  47. /// </summary>
  48. /// <param name="module"></param>
  49. public SchedulerLoader(ModuleName module) : base(module.ToString())
  50. {
  51. _loaderEntity = Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(module.ToString());
  52. _puf1Entity = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(ModuleName.PUF1.ToString());
  53. }
  54. /// <summary>
  55. /// 执行
  56. /// </summary>
  57. /// <param name="parameter"></param>
  58. /// <returns></returns>
  59. public override bool RunProcess(object recipe, object parameter, List<SchedulerSyncModuleMessage> syncModuleMessages)
  60. {
  61. _state = RState.Running;
  62. _currentStep = SchedulerStep.WaitLoad;
  63. _currentWaferIndex = 0;
  64. return true;
  65. }
  66. /// <summary>
  67. /// 监控执行
  68. /// </summary>
  69. /// <returns></returns>
  70. public override bool MonitorProcess(SchedulerSequence schedulerSequence, bool hasMatchWafer)
  71. {
  72. int waferTaskCount =(int)schedulerSequence.Parameters;
  73. bool loadComplete = waferTaskCount == _currentWaferIndex;
  74. if (_currentStep == SchedulerStep.WaitLoad)
  75. {
  76. if (_loaderEntity.State != (int)LOADERSTATE.WaitForLoad)
  77. {
  78. return false;
  79. }
  80. bool result = ExecuteLoadSide(loadComplete);
  81. if (result)
  82. {
  83. _currentStep = SchedulerStep.LoadingFirst;
  84. }
  85. }
  86. else if (_currentStep == SchedulerStep.LoadingFirst)
  87. {
  88. if (_loaderEntity.IsIdle)
  89. {
  90. if (waferTaskCount == 1)
  91. {
  92. _state = RState.End;
  93. }
  94. else
  95. {
  96. bool result = ExecuteLoadSide(true);
  97. if (result)
  98. {
  99. _currentStep = SchedulerStep.LoadingSecond;
  100. }
  101. }
  102. }
  103. }
  104. else if (_currentStep == SchedulerStep.LoadingSecond)
  105. {
  106. if (_loaderEntity.IsIdle)
  107. {
  108. _state = RState.End;
  109. }
  110. }
  111. return true;
  112. }
  113. private bool ExecuteLoadSide(bool loadComplete)
  114. {
  115. if (_puf1Entity.State == (int)PUFSTATE.AferSwapParkStation || (_puf1Entity.IsIdle && _puf1Entity.IsBackToParkStation))
  116. {
  117. JetAxisBase tiltAAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.TiltA");
  118. JetAxisBase tiltBAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.TiltB");
  119. double tiltAPosition = tiltAAxis.MotionData.MotorPosition;
  120. double tiltBPosition = tiltBAxis.MotionData.MotorPosition;
  121. bool tiltAHori = tiltAAxis.CheckPositionIsInStation(tiltAPosition, "HORI");
  122. bool tiltBHori = tiltBAxis.CheckPositionIsInStation(tiltBPosition, "HORI");
  123. string side = tiltAHori ? "SideA" : (tiltBHori ? "SideB" : "");
  124. if (string.IsNullOrEmpty(side))
  125. {
  126. return false;
  127. }
  128. bool result = _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, Module.ToString(),
  129. (int)LoaderMSG.LoadSide, side, loadComplete);
  130. return result;
  131. }
  132. return false;
  133. }
  134. /// <summary>
  135. /// 检验前置条件
  136. /// </summary>
  137. /// <param name="sequenceIndex"></param>
  138. /// <param name="parameter"></param>
  139. /// <returns></returns>
  140. public override bool CheckPrecondition(List<SchedulerSequence> schedulerSequences, int sequenceIndex, object parameter, string materialId,ref string reason)
  141. {
  142. if (_state == RState.Running)
  143. {
  144. reason = "scheduler module is already running";
  145. return false;
  146. }
  147. if (_loaderEntity.IsIdle)
  148. {
  149. reason = "loader is idle";
  150. return false;
  151. }
  152. if (_loaderEntity.WaferHolderInfo == null)
  153. {
  154. reason = "loader has no wafer shuttle";
  155. return false;
  156. }
  157. if (_loaderEntity.WaferHolderInfo.Id != materialId)
  158. {
  159. reason = $"{_loaderEntity.Module} wafer shuttle {_loaderEntity.WaferHolderInfo.Id} is not matched with {materialId}";
  160. return false;
  161. }
  162. return true;
  163. }
  164. }
  165. }