LoaderUnloadSideRoutine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Routine;
  3. using MECF.Framework.Common.Equipment;
  4. using MECF.Framework.Common.Routine;
  5. using CyberX8_Core;
  6. using CyberX8_RT.Devices.AXIS;
  7. using CyberX8_RT.Devices.Loader;
  8. using System;
  9. using System.Collections.Generic;
  10. using Aitex.Core.RT.Log;
  11. using MECF.Framework.Common.Utilities;
  12. using MECF.Framework.Common.CommonData.Loader;
  13. using MECF.Framework.Common.CommonData;
  14. using Aitex.Core.RT.DataCenter;
  15. using Aitex.Core.RT.SCCore;
  16. using Aitex.Core.Util;
  17. namespace CyberX8_RT.Modules.Loader
  18. {
  19. public class LoaderUnloadSideRoutine : RoutineBase, IRoutine
  20. {
  21. private enum UnloadStep
  22. {
  23. RotationGoToLOADA,
  24. RotationGoToLOADAWait,
  25. SideUnload,
  26. UnloadAllWait,
  27. End
  28. }
  29. #region 常量
  30. private const string SIDE_A = "SideA";
  31. private const string SIDE_B = "SideB";
  32. private const int LOTTRACK_TIME = 1000;
  33. #endregion
  34. #region 内部变量
  35. private JetAxisBase _rotationAxis;
  36. private string _side;
  37. private LoaderUnloadRoutine _sideUnloadRoutine;
  38. private bool _isSideUnloaded = false;
  39. private bool _isSideStop = false;
  40. /// <summary>
  41. /// lotTrack time
  42. /// </summary>
  43. private DateTime _lotTackTime = DateTime.Now;
  44. /// <summary>
  45. /// Loader Common
  46. /// </summary>
  47. private LoaderCommonDevice _loaderCommon;
  48. /// <summary>
  49. /// LoaderSide
  50. /// </summary>
  51. private LoaderSideDevice _loaderSide;
  52. /// <summary>
  53. /// Loader LotTrackData
  54. /// </summary>
  55. private List<LoaderLotTrackData> _datas = new List<LoaderLotTrackData>();
  56. /// <summary>
  57. /// Wafer组
  58. /// </summary>
  59. private string _waferGroup;
  60. /// <summary>
  61. /// Wafer尺寸
  62. /// </summary>
  63. private int _waferSize;
  64. #endregion
  65. #region 属性
  66. /// <summary>
  67. /// UnLoad LotTrackData
  68. /// </summary>
  69. public List<LoaderLotTrackData> UnloadLotTrackDatas { get { return _datas; } }
  70. /// <summary>
  71. /// Wafer组
  72. /// </summary>
  73. public string waferGroup { get { return _waferGroup; } }
  74. #endregion
  75. /// <summary>
  76. /// 构造函数
  77. /// </summary>
  78. /// <param name="module"></param>
  79. public LoaderUnloadSideRoutine(string module) : base(module)
  80. {
  81. }
  82. /// <summary>
  83. /// 中止
  84. /// </summary>
  85. public void Abort()
  86. {
  87. }
  88. /// <summary>
  89. /// 监控
  90. /// </summary>
  91. /// <returns></returns>
  92. public RState Monitor()
  93. {
  94. LottrackRecord();
  95. Runner.Run(UnloadStep.RotationGoToLOADA,RotationGotoLOAD,_delay_1ms)
  96. .WaitWithStopCondition(UnloadStep.RotationGoToLOADAWait,CheckRotationPositionStatus,CheckRotationPositionRunStop)
  97. .Run(UnloadStep.SideUnload, () => StartUnloadRoutine(_sideUnloadRoutine,_isSideUnloaded), _delay_1ms)
  98. .WaitWithStopCondition(UnloadStep.UnloadAllWait, CheckUnloadAllRoutineEndStatus,CheckUnloadAllRoutineStopStatus)
  99. .End(UnloadStep.End, NullFun, _delay_1ms);
  100. return Runner.Status;
  101. }
  102. /// <summary>
  103. /// Rotation Goto LOADA
  104. /// </summary>
  105. /// <returns></returns>
  106. private bool RotationGotoLOAD()
  107. {
  108. string side = _side == SIDE_A ? "A" : "B";
  109. bool result = _rotationAxis.PositionStation($"LOAD{side}{_waferSize}", false);
  110. if (!result)
  111. {
  112. NotifyError(eEvent.ERR_LOADER, "rotation start goto LOAD failed", 0);
  113. }
  114. return result;
  115. }
  116. /// <summary>
  117. /// 检验Rotation移动状态
  118. /// </summary>
  119. /// <returns></returns>
  120. private bool CheckRotationPositionStatus()
  121. {
  122. return _rotationAxis.Status == RState.End;
  123. }
  124. /// <summary>
  125. /// 检验Rotation是否还在运动
  126. /// </summary>
  127. /// <returns></returns>
  128. private bool CheckRotationPositionRunStop()
  129. {
  130. bool result = _rotationAxis.Status == RState.Failed || _rotationAxis.Status == RState.Timeout ;
  131. if (result)
  132. {
  133. NotifyError(eEvent.ERR_LOADER, "rotation goto position failed",0);
  134. }
  135. return result;
  136. }
  137. /// <summary>
  138. /// 启动Unload routine
  139. /// </summary>
  140. /// <param name="unloadRoutine"></param>
  141. /// <returns></returns>
  142. private bool StartUnloadRoutine(LoaderUnloadRoutine unloadRoutine,bool isSideUnloaded)
  143. {
  144. if (isSideUnloaded)
  145. {
  146. return true;
  147. }
  148. bool result= unloadRoutine.Start()==RState.Running;
  149. if(!result)
  150. {
  151. NotifyError(eEvent.ERR_LOADER, unloadRoutine.ErrorMsg, 0);
  152. }
  153. return result;
  154. }
  155. /// <summary>
  156. /// 检验UnloadAll完成状态
  157. /// </summary>
  158. /// <returns></returns>
  159. private bool CheckUnloadAllRoutineEndStatus()
  160. {
  161. bool sideResult = true;
  162. if (!_isSideUnloaded)
  163. {
  164. sideResult = CheckUnloadRoutineEndStatus(_sideUnloadRoutine);
  165. }
  166. return sideResult;
  167. }
  168. /// <summary>
  169. /// 检查UnloadAll停止状态
  170. /// </summary>
  171. /// <returns></returns>
  172. private bool CheckUnloadAllRoutineStopStatus()
  173. {
  174. bool sideComplete = false;
  175. if (!_isSideUnloaded&&!_isSideStop)
  176. {
  177. RState ret = _sideUnloadRoutine.Monitor();
  178. _isSideStop = ret == RState.Failed || ret == RState.Timeout;
  179. sideComplete = (ret != RState.Running);
  180. if (_isSideStop)
  181. {
  182. NotifyError(eEvent.ERR_LOADER, $"unload A failed\r\n{_sideUnloadRoutine.ErrorMsg}", 1);
  183. }
  184. }
  185. return _isSideStop;
  186. }
  187. /// <summary>
  188. /// 检验routine完成状态
  189. /// </summary>
  190. /// <param name="unloadRoutine"></param>
  191. /// <returns></returns>
  192. private bool CheckUnloadRoutineEndStatus(LoaderUnloadRoutine unloadRoutine)
  193. {
  194. return unloadRoutine.Monitor() == RState.End;
  195. }
  196. /// <summary>
  197. /// 检验Routine结束状态
  198. /// </summary>
  199. /// <param name="unloadRoutine"></param>
  200. /// <returns></returns>
  201. private bool CheckUnloadRoutineStopStatus(LoaderUnloadRoutine unloadRoutine,string side)
  202. {
  203. RState state=unloadRoutine.Monitor();
  204. if (state == RState.Failed || state == RState.Timeout)
  205. {
  206. NotifyError(eEvent.ERR_LOADER, $"{side} Unload failed", 0);
  207. return true;
  208. }
  209. return false;
  210. }
  211. /// <summary>
  212. /// 启动
  213. /// </summary>
  214. /// <param name="objs"></param>
  215. /// <returns></returns>
  216. public RState Start(params object[] objs)
  217. {
  218. _side = objs[0].ToString();
  219. if (objs.Length > 1)
  220. {
  221. _waferGroup = objs[1].ToString();
  222. }
  223. LoaderEntity loaderEntity=Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(ModuleName.Loader1.ToString());
  224. if (_side == SIDE_A)
  225. {
  226. _waferSize = loaderEntity.SideAWaferSize;
  227. }
  228. else
  229. {
  230. _waferSize = loaderEntity.SideBWaferSize;
  231. }
  232. InitializeParameters();
  233. _loaderCommon = DEVICE.GetDevice<LoaderCommonDevice>($"{Module}.Common");
  234. _loaderSide = DEVICE.GetDevice<LoaderSideDevice>($"{Module}.{_side}");
  235. return Runner.Start(Module, "Start Unload side");
  236. }
  237. /// <summary>
  238. /// 初始化参数
  239. /// </summary>
  240. private void InitializeParameters()
  241. {
  242. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  243. _sideUnloadRoutine = new LoaderUnloadRoutine(ModuleName.Loader1.ToString(), _side);
  244. _isSideUnloaded = false;
  245. _isSideStop = false;
  246. }
  247. /// <summary>
  248. /// 重试
  249. /// </summary>
  250. /// <param name="step"></param>
  251. public RState Retry(int step)
  252. {
  253. InitializeParameters();
  254. List<Enum> preStepIds = new List<Enum>();
  255. return Runner.Retry(UnloadStep.RotationGoToLOADA,preStepIds,Module,"UnloadAll Retry");
  256. }
  257. /// <summary>
  258. /// 检验前面Unload完成状态
  259. /// </summary>
  260. /// <returns></returns>
  261. public bool CheckCompleteCondition(int index)
  262. {
  263. string side = _side == SIDE_A ? "A" : "B";
  264. if (!CheckSideUnloadCondition(side, index,true))
  265. {
  266. return false;
  267. }
  268. return true;
  269. }
  270. /// <summary>
  271. /// 检验Side Unload情况
  272. /// </summary>
  273. /// <param name="side"></param>
  274. /// <param name="index"></param>
  275. /// <returns></returns>
  276. private bool CheckSideUnloadCondition(string side, int index,bool showError)
  277. {
  278. JetAxisBase shuttleAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.Shuttle{side}");
  279. double shuttlePosition = shuttleAxis.MotionData.MotorPosition;
  280. if (!shuttleAxis.CheckPositionInStationIgnoreWaferSize(shuttlePosition, "OUT"))
  281. {
  282. if (showError)
  283. {
  284. NotifyError(eEvent.ERR_LOADER, $"shuttle{side} {shuttlePosition} is not in Out", index);
  285. }
  286. return false;
  287. }
  288. JetAxisBase tiltAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.Tilt{side}");
  289. double tiltPosition = tiltAxis.MotionData.MotorPosition;
  290. if (!tiltAxis.CheckPositionInStationIgnoreWaferSize(tiltPosition, "HORI"))
  291. {
  292. if (showError)
  293. {
  294. NotifyError(eEvent.ERR_LOADER, $"tilt{side} {tiltPosition} is not in HORI", index);
  295. return false;
  296. }
  297. }
  298. JetAxisBase crsAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.LS{side}");
  299. double crsPosition = crsAxis.MotionData.MotorPosition;
  300. if (!crsAxis.CheckPositionInStationIgnoreWaferSize(crsPosition, "Unlock"))
  301. {
  302. if (showError)
  303. {
  304. NotifyError(eEvent.ERR_LOADER, $"LS{side} {crsPosition} is not in Unlock", index);
  305. }
  306. return false;
  307. }
  308. return true;
  309. }
  310. /// <summary>
  311. /// 记录Lottrack
  312. /// </summary>
  313. private void LottrackRecord()
  314. {
  315. //记录Lottrack
  316. if (DateTime.Now.Subtract(_lotTackTime).TotalMilliseconds >= LOTTRACK_TIME)
  317. {
  318. AddLotTrackData();
  319. _lotTackTime = DateTime.Now;
  320. }
  321. }
  322. /// <summary>
  323. /// 获取Lot Track数据
  324. /// </summary>
  325. /// <returns></returns>
  326. private void AddLotTrackData()
  327. {
  328. LoaderLotTrackData data = new LoaderLotTrackData();
  329. data.TimeStamp = DateTime.Now;
  330. data.LoaderABernoulliBladderEnable = _loaderSide.SideData.BernoulliBladder;
  331. data.LoaderABernoulliExtended = _loaderSide.SideData.BernoulliExtended;
  332. data.LoaderABernoulliBladderPressure = _loaderSide.SideData.BernoulliBladderPressure;
  333. data.LoaderABernoulliN2Pressure = _loaderSide.SideData.BernoulliPressure;
  334. data.LoaderACRSVacuum = _loaderSide.SideData.CRSVacuum;
  335. data.LoaderACRSVacuumAnlg = _loaderSide.SideData.CRSVacuumValue;
  336. data.LoaderAWHPressure = _loaderSide.SideData.WHBladderPressure;
  337. data.LoaderATranslatePressure = _loaderSide.SideData.TransPressure;
  338. data.LoaderWHClamped = _loaderCommon.CommonData.WaferHolderClamp;
  339. _datas.Add(data);
  340. }
  341. }
  342. }