LoaderUnloadSideRoutine.cs 15 KB

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