LoaderLoadSideRoutine.cs 18 KB

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