LoaderLoadSideRoutine.cs 17 KB

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