LoaderLoadSideRoutine.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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 MECF.Framework.Common.WaferHolder;
  13. using Aitex.Core.RT.SCCore;
  14. using Aitex.Core.Util;
  15. namespace CyberX8_RT.Modules.Loader
  16. {
  17. public class LoaderLoadSideRoutine : RoutineBase, IRoutine
  18. {
  19. private enum LoadStep
  20. {
  21. SideLoad,
  22. SideAllLoadWait,
  23. LeakTest,
  24. LeakTestWait,
  25. RotationGoToTRNPA,
  26. RotationGoToTRNPAWait,
  27. UnclampWaferHolder,
  28. End
  29. }
  30. #region 常量
  31. private const string SIDE_A = "SideA";
  32. private const string SIDE_B = "SideB";
  33. private const int LOTTRACK_TIME = 1000;
  34. #endregion
  35. #region 内部变量
  36. private JetAxisBase _rotationAxis;
  37. private LoaderLoadRoutine _sideLoadRoutine;
  38. private LoaderCommonDevice _loaderCommonDevice;
  39. private bool _isSideLoaded = false;
  40. private bool _isSideStop = false;
  41. /// <summary>
  42. /// lotTrack time
  43. /// </summary>
  44. private DateTime _lotTackTime = DateTime.Now;
  45. /// <summary>
  46. /// Loader Common
  47. /// </summary>
  48. private LoaderCommonDevice _loaderCommon;
  49. /// <summary>
  50. /// LoaderSide
  51. /// </summary>
  52. private LoaderSideDevice _loaderSide;
  53. /// <summary>
  54. /// Loader LotTrackData
  55. /// </summary>
  56. private List<LoaderLotTrackData> _datas = new List<LoaderLotTrackData>();
  57. /// <summary>
  58. /// Flow LotTrackData
  59. /// </summary>
  60. private List<LoaderFlowLotTrackData> _flowDatas = new List<LoaderFlowLotTrackData>();
  61. /// <summary>
  62. /// Loader Start and Finish Time
  63. /// </summary>
  64. private List<DateTime> _loadTimeList = new List<DateTime>();
  65. /// <summary>
  66. ///
  67. /// </summary>
  68. private string _side = "";
  69. /// <summary>
  70. /// WaferSize
  71. /// </summary>
  72. private int _waferSize;
  73. /// <summary>
  74. /// load是否完成
  75. /// </summary>
  76. private bool _loadComplete = false;
  77. /// <summary>
  78. /// 完成后运行
  79. /// </summary>
  80. private string _completeSide = "TRNPA";
  81. /// <summary>
  82. /// Wafer组
  83. /// </summary>
  84. private string _waferGroup = "";
  85. #endregion
  86. #region 属性
  87. /// <summary>
  88. /// UnLoad LotTrackData
  89. /// </summary>
  90. public List<LoaderLotTrackData> LoadLotTrackDatas { get { return _datas; } }
  91. /// <summary>
  92. /// Flow LotTrackData
  93. /// </summary>
  94. public List<LoaderFlowLotTrackData> FlowLotTrackDatas { get { return _flowDatas; } }
  95. /// <summary>
  96. /// LoadTimeList
  97. /// </summary>
  98. public List<DateTime> LoadTimeList { get { return _loadTimeList; } }
  99. /// <summary>
  100. /// Wafer组
  101. /// </summary>
  102. public string WaferGroup { get { return _waferGroup; } }
  103. /// <summary>
  104. /// is SideA
  105. /// </summary>
  106. public bool IsSideA { get { return _side == "A" ? true : false; } }
  107. #endregion
  108. /// <summary>
  109. /// 构造函数
  110. /// </summary>
  111. /// <param name="module"></param>
  112. public LoaderLoadSideRoutine(string module) : base(module)
  113. {
  114. }
  115. /// <summary>
  116. /// 中止
  117. /// </summary>
  118. public void Abort()
  119. {
  120. }
  121. /// <summary>
  122. /// 监控
  123. /// </summary>
  124. /// <returns></returns>
  125. public RState Monitor()
  126. {
  127. //记录Lot track
  128. LottrackRecord();
  129. Runner.Run(LoadStep.SideLoad, () => StartLoadRoutine(_sideLoadRoutine,_isSideLoaded), _delay_1ms)
  130. .WaitWithStopCondition(LoadStep.SideAllLoadWait, CheckLoadAllRoutineEndStatus,CheckLoadAllRoutineStopStatus)
  131. .Run(LoadStep.LeakTest, StartFlowTest, _delay_1ms)
  132. .WaitWithStopCondition(LoadStep.LeakTestWait, CheckFlowTestEndStatus, CheckFlowTestStopStatus)
  133. .RunIf(LoadStep.RotationGoToTRNPA,_loadComplete,RotationGotoTransporterA,_delay_1s)
  134. .WaitWithStopConditionIf(LoadStep.RotationGoToTRNPAWait,_loadComplete, CheckRotationPositionStatus,CheckRotationPositionRunStop)
  135. .RunIf(LoadStep.UnclampWaferHolder,_loadComplete, WaferHolderClampOffAction,_delay_1ms)
  136. .End(LoadStep.End, UpdateWaferHolderUse, _delay_1ms);
  137. return Runner.Status;
  138. }
  139. /// <summary>
  140. /// 检验Rotation移动状态
  141. /// </summary>
  142. /// <returns></returns>
  143. private bool CheckRotationPositionStatus()
  144. {
  145. return _rotationAxis.Status == RState.End;
  146. }
  147. /// <summary>
  148. /// 检验Rotation是否还在运动
  149. /// </summary>
  150. /// <returns></returns>
  151. private bool CheckRotationPositionRunStop()
  152. {
  153. bool result= _rotationAxis.Status == RState.Failed||_rotationAxis.Status==RState.Timeout;
  154. if (result)
  155. {
  156. NotifyError(eEvent.ERR_LOADER, "rotation goto position failed", 2);
  157. }
  158. return result;
  159. }
  160. /// <summary>
  161. /// 启动load routine
  162. /// </summary>
  163. /// <param name="loadRoutine"></param>
  164. /// <returns></returns>
  165. private bool StartLoadRoutine(LoaderLoadRoutine loadRoutine,bool isSideLoaded)
  166. {
  167. if (isSideLoaded)
  168. {
  169. return true;
  170. }
  171. bool result= loadRoutine.Start()==RState.Running;
  172. if (!result)
  173. {
  174. NotifyError(eEvent.ERR_LOADER, loadRoutine.ErrorMsg, 0);
  175. }
  176. return result;
  177. }
  178. /// <summary>
  179. /// 检验LoadAll完成状态
  180. /// </summary>
  181. /// <returns></returns>
  182. private bool CheckLoadAllRoutineEndStatus()
  183. {
  184. bool sideResult = true;
  185. if (!_isSideLoaded)
  186. {
  187. sideResult = CheckLoadRoutineEndStatus(_sideLoadRoutine);
  188. }
  189. if (sideResult)
  190. {
  191. _loadTimeList.Add(DateTime.Now);
  192. }
  193. return sideResult;
  194. }
  195. /// <summary>
  196. /// 检验LoadAll停止状态
  197. /// </summary>
  198. /// <returns></returns>
  199. private bool CheckLoadAllRoutineStopStatus()
  200. {
  201. bool sideComplete = false;
  202. if(!_isSideLoaded&&!_isSideStop)
  203. {
  204. RState ret = _sideLoadRoutine.Monitor();
  205. _isSideStop = ret == RState.Failed || ret == RState.Timeout;
  206. sideComplete = (ret != RState.Running);
  207. if (_isSideStop)
  208. {
  209. NotifyError(eEvent.ERR_LOADER, $"load A failed\r\n{_sideLoadRoutine.ErrorMsg}", 0);
  210. }
  211. }
  212. return _isSideStop;
  213. }
  214. /// <summary>
  215. /// 检验routine完成状态
  216. /// </summary>
  217. /// <param name="loadRoutine"></param>
  218. /// <returns></returns>
  219. private bool CheckLoadRoutineEndStatus(LoaderLoadRoutine loadRoutine)
  220. {
  221. return loadRoutine.Monitor() == RState.End;
  222. }
  223. /// <summary>
  224. /// 启动Flowtest
  225. /// </summary>
  226. /// <returns></returns>
  227. private bool StartFlowTest()
  228. {
  229. bool result= _loaderCommonDevice.StartFlowTestAction();
  230. if (!result)
  231. {
  232. NotifyError(eEvent.ERR_LOADER, "Start Flow Test failed", 1);
  233. }
  234. return result;
  235. }
  236. /// <summary>
  237. /// 检验FlowTest停止状态
  238. /// </summary>
  239. /// <returns></returns>
  240. private bool CheckFlowTestStopStatus()
  241. {
  242. if (_loaderCommonDevice.Status == RState.Failed || _loaderCommonDevice.Status == RState.Timeout)
  243. {
  244. NotifyError(eEvent.ERR_LOADER, "Flow Test failed",1);
  245. return true;
  246. }
  247. return false;
  248. }
  249. /// <summary>
  250. /// 检验FlowTest完成状态
  251. /// </summary>
  252. /// <returns></returns>
  253. private bool CheckFlowTestEndStatus()
  254. {
  255. bool result = _loaderCommonDevice.Status == RState.End;
  256. if (result)
  257. {
  258. _flowDatas = _loaderCommonDevice.FlowLotTrackDatas;
  259. }
  260. return result;
  261. }
  262. /// <summary>
  263. /// Rotation 运动至TRNPA
  264. /// </summary>
  265. /// <returns></returns>
  266. private bool RotationGotoTransporterA()
  267. {
  268. bool result = _rotationAxis.PositionStation(_completeSide, false);
  269. if (!result)
  270. {
  271. NotifyError(eEvent.ERR_LOADER, $"rotation start goto {_completeSide} failed", 2);
  272. }
  273. return result;
  274. }
  275. /// <summary>
  276. /// Wafer Holder Clamp Off
  277. /// </summary>
  278. /// <returns></returns>
  279. public bool WaferHolderClampOffAction()
  280. {
  281. bool result = _loaderCommonDevice.WaferHolderClampOffAction();
  282. if (!result)
  283. {
  284. NotifyError(eEvent.ERR_LOADER, "Wafer Shuttle Clamp Off failed", 2);
  285. }
  286. return result;
  287. }
  288. /// <summary>
  289. /// 更新WaferHolder总用量
  290. /// </summary>
  291. /// <returns></returns>
  292. private bool UpdateWaferHolderUse()
  293. {
  294. WaferHolderInfo waferHolderInfo = WaferHolderManager.Instance.GetWaferHolder("Loader");
  295. if(waferHolderInfo != null)
  296. {
  297. waferHolderInfo.TotalUses += 1;
  298. WaferHolderManager.Instance.UpdateWaferHolderInfo(waferHolderInfo);
  299. }
  300. return true;
  301. }
  302. /// <summary>
  303. /// 启动
  304. /// </summary>
  305. /// <param name="objs"></param>
  306. /// <returns></returns>
  307. public RState Start(params object[] objs)
  308. {
  309. _side = objs[0].ToString();
  310. _loadComplete=(bool)objs[1];
  311. if (objs.Length > 2)
  312. {
  313. _completeSide= objs[2].ToString();
  314. }
  315. if (objs.Length > 3)
  316. {
  317. _waferGroup= objs[3].ToString();
  318. }
  319. LoaderEntity loaderEntity = Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(ModuleName.Loader1.ToString());
  320. if (_side == SIDE_A)
  321. {
  322. _waferSize = loaderEntity.SideAWaferSize;
  323. }
  324. else
  325. {
  326. _waferSize = loaderEntity.SideBWaferSize;
  327. }
  328. InitializeParameters();
  329. _loaderCommon = DEVICE.GetDevice<LoaderCommonDevice>($"{Module}.Common");
  330. _loaderSide = DEVICE.GetDevice<LoaderSideDevice>($"{Module}.{_side}");
  331. //清除lotTrack数据
  332. _datas.Clear();
  333. _flowDatas.Clear();
  334. _loadTimeList.Clear();
  335. _loadTimeList.Add(DateTime.Now);
  336. return Runner.Start(Module, "Start LoadAll");
  337. }
  338. /// <summary>
  339. /// 初始化参数
  340. /// </summary>
  341. private void InitializeParameters()
  342. {
  343. _isSideLoaded = false;
  344. _isSideStop = false;
  345. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  346. _sideLoadRoutine = new LoaderLoadRoutine(ModuleName.Loader1.ToString(), _side);
  347. _loaderCommonDevice = DEVICE.GetDevice<LoaderCommonDevice>($"{ModuleName.Loader1}.Common");
  348. }
  349. /// <summary>
  350. /// 重试
  351. /// </summary>
  352. /// <param name="step"></param>
  353. public RState Retry(int step)
  354. {
  355. InitializeParameters();
  356. List<Enum> preStepIds = new List<Enum>();
  357. _datas.Clear();
  358. if (step == 0 || step == -1)
  359. {
  360. string side = _side == SIDE_A ? "A" : "B";
  361. _isSideLoaded = CheckSideLoadCondition(side, step,false);
  362. return Runner.Retry(LoadStep.SideLoad, preStepIds, Module, "LoadAll Retry");
  363. }
  364. else if (step == 1)
  365. {
  366. AddPreSteps(LoadStep.LeakTest, preStepIds);
  367. return Runner.Retry(LoadStep.LeakTest, preStepIds, Module, $"LoadAll step {LoadStep.LeakTest} start Retry");
  368. }
  369. else
  370. {
  371. AddPreSteps(LoadStep.RotationGoToTRNPA, preStepIds);
  372. return Runner.Retry(LoadStep.RotationGoToTRNPA, preStepIds, Module, $"LoadAll step {LoadStep.RotationGoToTRNPA} start Retry");
  373. }
  374. }
  375. /// <summary>
  376. /// 忽略前
  377. /// </summary>
  378. /// <param name="step"></param>
  379. /// <param name="preStepIds"></param>
  380. private void AddPreSteps(LoadStep step, List<Enum> preStepIds)
  381. {
  382. for (int i = 0; i < (int)step; i++)
  383. {
  384. preStepIds.Add((LoadStep)i);
  385. }
  386. }
  387. /// <summary>
  388. /// 检验前面Unload完成状态
  389. /// </summary>
  390. /// <returns></returns>
  391. public bool CheckCompleteCondition(int index)
  392. {
  393. string side = _side == SIDE_A ? "A" : "B";
  394. if (!CheckSideLoadCondition(side, index,true))
  395. {
  396. return false;
  397. }
  398. JetAxisBase loaderRotationAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.Rotation");
  399. double loaderRotationPosition = loaderRotationAxis.MotionData.MotorPosition;
  400. if (!loaderRotationAxis.CheckPositionIsInStation(loaderRotationPosition, "TRNPA"))
  401. {
  402. NotifyError(eEvent.ERR_LOADER, $"loader rotation {loaderRotationPosition} not in TRNPA", index);
  403. }
  404. return true;
  405. }
  406. /// <summary>
  407. /// 检验Side Unload情况
  408. /// </summary>
  409. /// <param name="side"></param>
  410. /// <param name="index"></param>
  411. /// <returns></returns>
  412. private bool CheckSideLoadCondition(string side, int index,bool showError)
  413. {
  414. JetAxisBase shuttleAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.Shuttle{side}");
  415. double shuttlePosition = shuttleAxis.MotionData.MotorPosition;
  416. if (!shuttleAxis.CheckPositionInStationIgnoreWaferSize(shuttlePosition, "MID"))
  417. {
  418. if (showError)
  419. {
  420. NotifyError(eEvent.ERR_LOADER, $"shuttle{side} {shuttlePosition} is not in mid", index);
  421. }
  422. return false;
  423. }
  424. JetAxisBase tiltAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.Tilt{side}");
  425. double tiltPosition = tiltAxis.MotionData.MotorPosition;
  426. if (tiltAxis.CheckPositionIsInStation(tiltPosition, "VERT"))
  427. {
  428. if (showError)
  429. {
  430. NotifyError(eEvent.ERR_LOADER, $"tilt{side} {tiltPosition} is not in VERT", index);
  431. }
  432. return false;
  433. }
  434. JetAxisBase crsAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.LS{side}");
  435. double crsPosition = crsAxis.MotionData.MotorPosition;
  436. if (!crsAxis.CheckPositionIsInStation(crsPosition, "Setup"))
  437. {
  438. if (showError)
  439. {
  440. NotifyError(eEvent.ERR_LOADER, $"LS{side} {crsPosition} is not in Setup", index);
  441. }
  442. return false;
  443. }
  444. return true;
  445. }
  446. /// <summary>
  447. /// 记录Lottrack
  448. /// </summary>
  449. private void LottrackRecord()
  450. {
  451. //记录Lottrack
  452. if (DateTime.Now.Subtract(_lotTackTime).TotalMilliseconds >= LOTTRACK_TIME)
  453. {
  454. AddLotTrackData();
  455. _lotTackTime = DateTime.Now;
  456. }
  457. }
  458. /// <summary>
  459. /// 获取Lot Track数据
  460. /// </summary>
  461. /// <returns></returns>
  462. private void AddLotTrackData()
  463. {
  464. LoadStep step = (LoadStep)Runner.CurrentStep;
  465. if (step <= LoadStep.SideAllLoadWait)
  466. {
  467. LoaderLotTrackData data = new LoaderLotTrackData();
  468. data.TimeStamp = DateTime.Now;
  469. if (_side == SIDE_A)
  470. {
  471. data.LoaderABernoulliBladderEnable = _loaderSide.SideData.BernoulliBladder;
  472. data.LoaderABernoulliBladderPressure = _loaderSide.SideData.BernoulliBladderPressure;
  473. data.LoaderABernoulliN2Pressure = _loaderSide.SideData.BernoulliPressure;
  474. data.LoaderACRSVacuum = _loaderSide.SideData.CRSVacuum;
  475. data.LoaderACRSVacuumAnlg = _loaderSide.SideData.CRSVacuumValue;
  476. data.LoaderAWHPressure = _loaderSide.SideData.WHBladderPressure;
  477. }
  478. else
  479. {
  480. data.LoaderBBernoulliBladderEnable = _loaderSide.SideData.BernoulliBladder;
  481. data.LoaderBBernoulliBladderPressure = _loaderSide.SideData.BernoulliBladderPressure;
  482. data.LoaderBBernoulliN2Pressure = _loaderSide.SideData.BernoulliPressure;
  483. data.LoaderBCRSVacuum = _loaderSide.SideData.CRSVacuum;
  484. data.LoaderBCRSVacuumAnlg = _loaderSide.SideData.CRSVacuumValue;
  485. data.LoaderBWHPressure = _loaderSide.SideData.WHBladderPressure;
  486. }
  487. data.LoaderWHClamped = _loaderCommon.CommonData.WaferHolderClamp;
  488. _datas.Add(data);
  489. }
  490. }
  491. }
  492. }