LoaderUnloadRoutine.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.Util;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.Common.Routine;
  7. using MECF.Framework.Common.Utilities;
  8. using CyberX8_Core;
  9. using CyberX8_RT.Devices.AXIS;
  10. using CyberX8_RT.Devices.AXIS.CANOpen;
  11. using CyberX8_RT.Modules.PUF;
  12. using CyberX8_RT.Modules;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using MECF.Framework.Common.CommonData.Loader;
  19. using CyberX8_RT.Modules.Transporter;
  20. using Aitex.Core.RT.SCCore;
  21. namespace CyberX8_RT.Devices.Loader
  22. {
  23. public class LoaderUnloadRoutine : RoutineBase, IRoutine
  24. {
  25. private enum UnloadStep
  26. {
  27. CheckPreCondition,
  28. WSClampOn,
  29. LSGotoLock,
  30. LSGotoLockWait,
  31. ShuttleGotoIN,
  32. ShuttleGotoINWait,
  33. BernoulliBladderOn,
  34. BernoulliBladderOnCheck,
  35. BernoulliN2On,
  36. WSBladderOn,
  37. WSBladderOnCheck,
  38. LSVacuumOn,
  39. LSVacuumOnCheck,
  40. LSVacuumLevelCheck,
  41. LSVacuumLevelCheckWait,
  42. ShuttleGotoLS,
  43. ShuttleGotoLSWait,
  44. LSGotoSetup,
  45. LSGotoSetupWait,
  46. LSGotoUnlock,
  47. LSGotoUnlockWait,
  48. ReLSVacuumLevelCheck,
  49. ReLSVacuumLevelCheckWait,
  50. ShuttleGotoOUT,
  51. ShuttleGotoOUTWait,
  52. TiltGotoHori,
  53. TiltGotoHoriCheck,
  54. BernoulliN2Off,
  55. WSBladderOff,
  56. WSBladderOffCheck,
  57. End
  58. }
  59. #region 内部变量
  60. private string _side = "";
  61. private JetAxisBase _lsAxis;
  62. private LoaderSideBernoulliBladderRoutine _bernoulliBladderRoutine;
  63. private LoaderSideVacuumRoutine _vacuumRoutine;
  64. private LoaderSideVacuumLevelCheckRoutine _vacuumLevelCheckRoutine;
  65. private LoaderSideWhBladderRoutine _whBladderRoutine;
  66. private JetAxisBase _shuttleAxis;
  67. private JetAxisBase _tiltAxis;
  68. private JetAxisBase _rotationAxis;
  69. private LoaderSideDevice _sideDevice;
  70. private LoaderCommonDevice _loaderCommonDevice;
  71. /// <summary>
  72. /// WaferSize
  73. /// </summary>
  74. private int _waferSize;
  75. #endregion
  76. /// <summary>
  77. /// 构造函数
  78. /// </summary>
  79. /// <param name="module"></param>
  80. public LoaderUnloadRoutine(string module, string side) : base(module)
  81. {
  82. _side = side;
  83. }
  84. /// <summary>
  85. /// 中止
  86. /// </summary>
  87. public void Abort()
  88. {
  89. Runner.Stop("Manual Abort");
  90. }
  91. /// <summary>
  92. /// 监控
  93. /// </summary>
  94. /// <returns></returns>
  95. public RState Monitor()
  96. {
  97. Runner.Run(UnloadStep.CheckPreCondition,CheckPreCondition,_delay_1ms)
  98. //1. WS Clamp on
  99. .Run(UnloadStep.WSClampOn, WSClampOnAction, () => { return _loaderCommonDevice.CommonData.WaferHolderClamp; }, _delay_5s)
  100. //2. LS Goto Lock位
  101. .Run(UnloadStep.LSGotoLock, () => { return AxisPosition(_lsAxis,$"Lock{_waferSize}"); }, NullFun, _delay_1ms)
  102. .WaitWithStopCondition(UnloadStep.LSGotoLockWait, () => { return _lsAxis.Status == RState.End; },
  103. ()=>CheckAxisMotionStopStatus(_lsAxis))
  104. //3. Shuttle Goto OPEN
  105. .Run(UnloadStep.ShuttleGotoIN, () => { return AxisPosition(_shuttleAxis, "IN"); }, NullFun, _delay_1ms)
  106. .WaitWithStopCondition(UnloadStep.ShuttleGotoINWait, () => { return _shuttleAxis.Status == RState.End; },
  107. () => CheckAxisMotionStopStatus(_shuttleAxis))
  108. //4. BernoulliBladderOn
  109. .Run(UnloadStep.BernoulliBladderOn, () => { return _bernoulliBladderRoutine.Start(true) == RState.Running; }, _delay_1ms)
  110. .WaitWithStopCondition(UnloadStep.BernoulliBladderOnCheck, () => { return CommonFunction.CheckRoutineEndState(_bernoulliBladderRoutine); },
  111. () => CheckRoutineStopStatus(_bernoulliBladderRoutine, "BernoulliBladder On failed"))
  112. //5. BernoulliN2 On
  113. .Run(UnloadStep.BernoulliN2On, BernoulliN2On, () => { return _sideDevice.SideData.BernoulliN2; }, _delay_5s)
  114. //6. WS Bladder On
  115. .Run(UnloadStep.WSBladderOn, () => { return _whBladderRoutine.Start(true) == RState.Running; }, _delay_1ms)
  116. .WaitWithStopCondition(UnloadStep.WSBladderOnCheck, () => { return CommonFunction.CheckRoutineEndState(_whBladderRoutine); },
  117. () => CheckRoutineStopStatus(_whBladderRoutine, "WSBladder On failed"))
  118. //7. LS Vacuum On
  119. .Run(UnloadStep.LSVacuumOn, () => { return _vacuumRoutine.Start(true) == RState.Running; }, _delay_1ms)
  120. .WaitWithStopCondition(UnloadStep.LSVacuumOnCheck, () => { return CommonFunction.CheckRoutineEndState(_vacuumRoutine); },
  121. () => CheckRoutineStopStatus(_vacuumRoutine, "LS Vaccum On failed"))
  122. //8. LS vacuum level check
  123. .Run(UnloadStep.LSVacuumLevelCheck, () => { return _vacuumLevelCheckRoutine.Start(true) == RState.Running; }, _delay_1ms)
  124. .WaitWithStopCondition(UnloadStep.LSVacuumLevelCheckWait, () => { return CommonFunction.CheckRoutineEndState(_vacuumLevelCheckRoutine); },
  125. () => CheckRoutineStopStatus(_vacuumLevelCheckRoutine, "LS Vacuum Level Check failed"))
  126. //9. Shuttle Goto LS
  127. .Run(UnloadStep.ShuttleGotoLS, () => { return AxisPosition(_shuttleAxis, "LS"); }, NullFun, _delay_1ms)
  128. .WaitWithStopCondition(UnloadStep.ShuttleGotoLSWait, () => { return _shuttleAxis.Status == RState.End; },
  129. () => CheckAxisMotionStopStatus(_shuttleAxis))
  130. //10. LS Goto Setup
  131. .Run(UnloadStep.LSGotoSetup, () => { return AxisPosition(_lsAxis, $"Setup{_waferSize}"); }, NullFun, _delay_1ms)
  132. .WaitWithStopCondition(UnloadStep.LSGotoSetupWait, () => { return _lsAxis.Status == RState.End; },
  133. () => CheckAxisMotionStopStatus(_lsAxis))
  134. //11. LS Goto Unlock
  135. .Run(UnloadStep.LSGotoUnlock, () => { return AxisPosition(_lsAxis, $"Unlock{_waferSize}"); }, NullFun, _delay_1ms)
  136. .WaitWithStopCondition(UnloadStep.LSGotoUnlockWait, () => { return _lsAxis.Status == RState.End; },
  137. () => CheckAxisMotionStopStatus(_lsAxis))
  138. //12. Re LS Vacuum level Check
  139. .Run(UnloadStep.ReLSVacuumLevelCheck, () => { return _vacuumLevelCheckRoutine.Start(true) == RState.Running; }, _delay_1ms)
  140. .WaitWithStopCondition(UnloadStep.ReLSVacuumLevelCheckWait, () => { return CommonFunction.CheckRoutineEndState(_vacuumLevelCheckRoutine); },
  141. () => CheckRoutineStopStatus(_vacuumLevelCheckRoutine,"LS Vacuum Level check failed"))
  142. //13. Shuttle Goto OUT
  143. .Run(UnloadStep.ShuttleGotoOUT, () => { return AxisPosition(_shuttleAxis, $"OUT{_waferSize}"); }, NullFun, _delay_1ms)
  144. .WaitWithStopCondition(UnloadStep.ShuttleGotoOUTWait, () => { return _shuttleAxis.Status == RState.End; },
  145. () => CheckAxisMotionStopStatus(_shuttleAxis))
  146. //14. Tilt Goto HORI
  147. .Run(UnloadStep.TiltGotoHori, () => { return AxisPosition(_tiltAxis,"HORI"); }, NullFun, _delay_1ms)
  148. .WaitWithStopCondition(UnloadStep.TiltGotoHoriCheck, () => { return _tiltAxis.Status == RState.End; },
  149. () => CheckAxisMotionStopStatus(_tiltAxis))
  150. //15. Bernoulli N2 Off
  151. .Run(UnloadStep.BernoulliN2Off, BernoulliN2Off, () => { return !_sideDevice.SideData.BernoulliN2; }, _delay_5s)
  152. //16. WS Bladder Off
  153. .Run(UnloadStep.WSBladderOff, () => { return _whBladderRoutine.Start(false) == RState.Running; }, _delay_1ms)
  154. .WaitWithStopCondition(UnloadStep.WSBladderOffCheck, () => { return CommonFunction.CheckRoutineEndState(_whBladderRoutine); },
  155. () => CheckRoutineStopStatus(_whBladderRoutine, "WSBladder Off failed"))
  156. .End(UnloadStep.End, NullFun, 10);
  157. return Runner.Status;
  158. }
  159. /// <summary>
  160. /// 检验Routine异常状态
  161. /// </summary>
  162. /// <returns></returns>
  163. private bool CheckRoutineStopStatus(IRoutine routine,string error)
  164. {
  165. bool result = CommonFunction.CheckRoutineStopState(routine);
  166. if (result)
  167. {
  168. NotifyError(eEvent.ERR_LOADER, $"{error}", 0);
  169. }
  170. return result;
  171. }
  172. /// <summary>
  173. /// Axis goto position
  174. /// </summary>
  175. /// <param name="axis"></param>
  176. /// <param name="station"></param>
  177. /// <returns></returns>
  178. private bool AxisPosition(JetAxisBase axis,string station)
  179. {
  180. bool result = axis.PositionStation(station);
  181. if (!result)
  182. {
  183. NotifyError(eEvent.ERR_LOADER, $"{axis.Module} goto {station} failed", 0);
  184. }
  185. return result;
  186. }
  187. /// <summary>
  188. /// 检验电机运动异常状态
  189. /// </summary>
  190. /// <param name="axis"></param>
  191. /// <returns></returns>
  192. private bool CheckAxisMotionStopStatus(JetAxisBase axis)
  193. {
  194. bool result = axis.Status == RState.Failed || axis.Status == RState.Timeout;
  195. if (result)
  196. {
  197. NotifyError(eEvent.ERR_LOADER, $"{axis.Module} motion failed", 0);
  198. }
  199. return result;
  200. }
  201. /// <summary>
  202. /// BerolliN2 On
  203. /// </summary>
  204. /// <returns></returns>
  205. private bool BernoulliN2On()
  206. {
  207. bool result= _sideDevice.BernoulliN2OnAction("", null);
  208. if (!result)
  209. {
  210. NotifyError(eEvent.ERR_LOADER, $"BernoulliN2 On failed", 0);
  211. }
  212. return result;
  213. }
  214. /// <summary>
  215. /// BernoulliN2Off
  216. /// </summary>
  217. /// <returns></returns>
  218. private bool BernoulliN2Off()
  219. {
  220. bool result = _sideDevice.BernoulliN2OffAction("", null);
  221. if (!result)
  222. {
  223. NotifyError(eEvent.ERR_LOADER, "BernoulliN2 Off failed", 0);
  224. }
  225. return result;
  226. }
  227. /// <summary>
  228. /// Wafer Holder Clamp Off
  229. /// </summary>
  230. /// <returns></returns>
  231. public bool WSClampOffAction()
  232. {
  233. bool result = _loaderCommonDevice.WaferHolderClampOffAction();
  234. if (!result)
  235. {
  236. NotifyError(eEvent.ERR_LOADER, "Wafer Shuttle Clamp Off failed", 2);
  237. }
  238. return result;
  239. }
  240. /// <summary>
  241. /// Wafer Holder Clamp On
  242. /// </summary>
  243. /// <returns></returns>
  244. public bool WSClampOnAction()
  245. {
  246. bool result = _loaderCommonDevice.WaferHolderClampOnAction();
  247. if (!result)
  248. {
  249. NotifyError(eEvent.ERR_LOADER, "Wafer Shuttle Clamp On failed", 2);
  250. }
  251. return result;
  252. }
  253. /// <summary>
  254. /// 启动
  255. /// </summary>
  256. /// <param name="objs"></param>
  257. /// <returns></returns>
  258. /// <exception cref="NotImplementedException"></exception>
  259. public RState Start(params object[] objs)
  260. {
  261. if (SC.ContainsItem($"Loader1.{_side}WaferSize"))
  262. {
  263. _waferSize = SC.GetValue<int>($"Loader1.{_side}WaferSize");
  264. }
  265. _shuttleAxis = GetShuttleAxis();
  266. _lsAxis = GetCrsAxis();
  267. _tiltAxis = GetTiltAxis();
  268. _loaderCommonDevice = DEVICE.GetDevice<LoaderCommonDevice>($"Loader1.Common");
  269. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.Rotation");
  270. _sideDevice = DEVICE.GetDevice<LoaderSideDevice>($"{Module}.{_side}");
  271. _vacuumRoutine = new LoaderSideVacuumRoutine($"{Module}.{_side}");
  272. _vacuumLevelCheckRoutine = new LoaderSideVacuumLevelCheckRoutine($"{Module}.{_side}");
  273. //_unloadVacuumLevelCheckRoutine = new LoaderSideUnloadVacuumLevelCheckRoutine($"{Module}.{_side}");
  274. _whBladderRoutine = new LoaderSideWhBladderRoutine($"{Module}.{_side}");
  275. _bernoulliBladderRoutine = new LoaderSideBernoulliBladderRoutine($"{Module}.{_side}");
  276. Runner.Start(Module, $"Unload {_side}");
  277. return RState.Running;
  278. }
  279. /// <summary>
  280. /// 获取Shuttle轴对象
  281. /// </summary>
  282. /// <returns></returns>
  283. private JetAxisBase GetShuttleAxis()
  284. {
  285. switch (_side)
  286. {
  287. case "SideA":
  288. return DEVICE.GetDevice<JetAxisBase>($"{Module}.ShuttleA");
  289. default:
  290. return DEVICE.GetDevice<JetAxisBase>($"{Module}.ShuttleB");
  291. }
  292. }
  293. /// <summary>
  294. /// 获取CRS轴对象
  295. /// </summary>
  296. /// <returns></returns>
  297. private JetAxisBase GetCrsAxis()
  298. {
  299. switch (_side)
  300. {
  301. case "SideA":
  302. return DEVICE.GetDevice<JetAxisBase>($"{Module}.LSA");
  303. default:
  304. return DEVICE.GetDevice<JetAxisBase>($"{Module}.LSB");
  305. }
  306. }
  307. /// <summary>
  308. /// 获取Tilt轴对象
  309. /// </summary>
  310. /// <returns></returns>
  311. private JetAxisBase GetTiltAxis()
  312. {
  313. switch (_side)
  314. {
  315. case "SideA":
  316. return DEVICE.GetDevice<JetAxisBase>($"{Module}.TiltA");
  317. default:
  318. return DEVICE.GetDevice<JetAxisBase>($"{Module}.TiltB");
  319. }
  320. }
  321. /// <summary>
  322. /// 检验前置条件
  323. /// </summary>
  324. /// <returns></returns>
  325. private bool CheckPreCondition()
  326. {
  327. if (!CheckHomeCondition())
  328. {
  329. return false;
  330. }
  331. if (!CheckUnloadAxisCondition())
  332. {
  333. return false;
  334. }
  335. if (!UnloadStatusCheck())
  336. {
  337. return false;
  338. }
  339. return true;
  340. }
  341. /// <summary>
  342. /// 检验Home条件
  343. /// </summary>
  344. /// <returns></returns>
  345. private bool CheckHomeCondition()
  346. {
  347. //检验PUF、Loader Transporter,Robot均Homed
  348. //Efem Home
  349. if (ModuleHelper.IsInstalled(ModuleName.EFEM))
  350. {
  351. EfemEntity efemEntity = Singleton<RouteManager>.Instance.GetModule<EfemEntity>(ModuleName.EFEM.ToString());
  352. if (!efemEntity.IsHomed)
  353. {
  354. LOG.WriteLog(eEvent.ERR_EFEM_ROBOT, Module, $"{ModuleName.EFEM.ToString()} is not home, Cannot execute GotoSavedPosition");
  355. return false;
  356. }
  357. }
  358. if (ModuleHelper.IsInstalled(ModuleName.PUF1))
  359. {
  360. PUFEntity puf1Entity = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(ModuleName.PUF1.ToString());
  361. if (!puf1Entity.IsHomed)
  362. {
  363. NotifyError(eEvent.ERR_LOADER, "PUF1 is not homed",-1);
  364. return false;
  365. }
  366. }
  367. if (ModuleHelper.IsInstalled(ModuleName.Transporter2))
  368. {
  369. TransporterEntity loaderTransportEntity = Singleton<RouteManager>.Instance.GetModule<TransporterEntity>(ModuleName.Transporter2.ToString());
  370. if (!loaderTransportEntity.IsHomed)
  371. {
  372. NotifyError(eEvent.ERR_LOADER, "Loader Transporter is not homed",-1);
  373. return false;
  374. }
  375. }
  376. return true;
  377. }
  378. /// <summary>
  379. /// 检验Axis条件
  380. /// </summary>
  381. /// <param name="side"></param>
  382. /// <returns></returns>
  383. private bool CheckUnloadAxisCondition()
  384. {
  385. if (!_rotationAxis.IsHomed)
  386. {
  387. NotifyError(eEvent.ERR_LOADER, $"Rotation is not homed",-1);
  388. return false;
  389. }
  390. if (!_shuttleAxis.IsHomed)
  391. {
  392. NotifyError(eEvent.ERR_LOADER, $"{_shuttleAxis.Name} is not homed", -1);
  393. return false;
  394. }
  395. if (!_tiltAxis.IsHomed)
  396. {
  397. NotifyError(eEvent.ERR_LOADER, $"{_tiltAxis.Name} is not homed",-1);
  398. return false;
  399. }
  400. if (!_lsAxis.IsHomed)
  401. {
  402. NotifyError(eEvent.ERR_LOADER, $"{_lsAxis.Name} is not homed", -1);
  403. return false;
  404. }
  405. //LS已经运动到 Setup 位
  406. double crsPosition = _lsAxis.MotionData.MotorPosition;
  407. if (!_lsAxis.CheckPositionIsInStation(crsPosition, $"Setup{_waferSize}"))
  408. {
  409. NotifyError(eEvent.ERR_LOADER, $"LS {crsPosition} not in Setup{_waferSize}", -1);
  410. return false;
  411. }
  412. //Rotation已经运动到 loaderA 位(sideA 下片时)或 loaderB 位(sideB 下片时)
  413. double rotationPosition = _rotationAxis.MotionData.MotorPosition;
  414. if(_side == "SideA")
  415. {
  416. if (!_rotationAxis.CheckPositionIsInStation(rotationPosition, $"LOADA{_waferSize}"))
  417. {
  418. NotifyError(eEvent.ERR_LOADER, $"Rotation {rotationPosition} not in LOADA{_waferSize}", -1);
  419. return false;
  420. }
  421. }
  422. else
  423. {
  424. if (!_rotationAxis.CheckPositionIsInStation(rotationPosition, $"LOADB{_waferSize}"))
  425. {
  426. NotifyError(eEvent.ERR_LOADER, $"Rotation {rotationPosition} not in LOADB{_waferSize}", -1);
  427. return false;
  428. }
  429. }
  430. //Shuttle已经运动到 MID 位
  431. double shuttlePosition =_shuttleAxis.MotionData.MotorPosition;
  432. if (!_shuttleAxis.CheckPositionIsInStation(shuttlePosition, "MID"))
  433. {
  434. NotifyError(eEvent.ERR_LOADER, $"Shuttle {shuttlePosition} not in MID", -1);
  435. return false;
  436. }
  437. //Tilt已经运动到 VERT 位
  438. double tiltPosition = _tiltAxis.MotionData.MotorPosition;
  439. if (!_tiltAxis.CheckPositionIsInStation(tiltPosition, "VERT"))
  440. {
  441. NotifyError(eEvent.ERR_LOADER, $"Tilt {tiltPosition} not in VERT", -1);
  442. return false;
  443. }
  444. return true;
  445. }
  446. /// <summary>
  447. /// 检验状态条件
  448. /// </summary>
  449. /// <param name="side"></param>
  450. /// <returns></returns>
  451. private bool UnloadStatusCheck()
  452. {
  453. LoaderSideData sideData = _sideDevice.SideData;
  454. LoaderCommonData commonData = _loaderCommonDevice.CommonData;
  455. //Bernoulli Bladder(WS Bladder on)
  456. if (!sideData.BernoulliBladder)
  457. {
  458. NotifyError(eEvent.ERR_LOADER, "Bernoulli Bladder is off", -1);
  459. return false;
  460. }
  461. //Bernoulli N2(BernoulliN2 off)
  462. if (sideData.BernoulliN2)
  463. {
  464. NotifyError(eEvent.ERR_LOADER, "Bernoulli N2 is on",-1);
  465. return false;
  466. }
  467. //LS Vacuum检验(LS Vaccum off)
  468. if (sideData.CRSVacuum)
  469. {
  470. NotifyError(eEvent.ERR_LOADER, "LS Vacuum is on", -1);
  471. return false;
  472. }
  473. //Wafer Shuttle Present(WS present)
  474. if (!commonData.WaferHolderPresent)
  475. {
  476. NotifyError(eEvent.ERR_LOADER, "Wafer Shuttle is absent", -1);
  477. return false;
  478. }
  479. //Wafer Shuttle Clamp(Clamp on/off均可)
  480. //Wafer Shuttle Bladder(Bladder off)
  481. if (sideData.WHBladder)
  482. {
  483. NotifyError(eEvent.ERR_LOADER, "Wafer Shuttle Bladder is on", -1);
  484. return false;
  485. }
  486. //Drip Tray Fluid(Drip Tray Fluid正常)
  487. if (commonData.DripTrayFluid)
  488. {
  489. NotifyError(eEvent.ERR_LOADER, "Drip Tray Fluid is on", -1);
  490. return false;
  491. }
  492. return true;
  493. }
  494. }
  495. }