LoaderLoadSideRoutine.cs 18 KB

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