LoaderLoadSideRoutine.cs 16 KB

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