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