EfemPickRoutine.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. using System;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using Aitex.Sorter.Common;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.Schedulers;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  11. using MECF.Framework.RT.EquipmentLibrary.LogicUnits;
  12. using MECF.Framework.RT.ModuleLibrary.PMModules;
  13. using MECF.Framework.RT.ModuleLibrary.SystemModules;
  14. namespace FutureEfemLib.Efems
  15. {
  16. public class EfemPickRoutine : ModuleRoutine, IRoutine
  17. {
  18. enum RoutineStep
  19. {
  20. CheckBeforePick,
  21. PickWafer,
  22. CheckBeforePick2,
  23. PickWafer2,
  24. PostTransfer,
  25. PrepareTransfer,
  26. PickExtend,
  27. PickRetract,
  28. LiftDown,
  29. }
  30. private int _pickTimeout;
  31. private ModuleName _source;
  32. private int _sourceSlot;
  33. private Hand _hand;
  34. private bool _autoHand;
  35. private EfemModule _robotModule;
  36. private ITransferTarget _target;
  37. private int _postTransferTimeout;
  38. public EfemPickRoutine(EfemModule robotModule)
  39. {
  40. Module = "EfemRobot";
  41. Name = "Pick";
  42. _robotModule = robotModule;
  43. }
  44. public Result Start(params object[] objs)
  45. {
  46. _pickTimeout = SC.GetValue<int>("EFEM.EfemRobot.PickTimeout");
  47. Reset();
  48. if (_autoHand)
  49. {
  50. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0))
  51. {
  52. _hand = Hand.Blade1;
  53. }
  54. else if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1))
  55. {
  56. _hand = Hand.Blade2;
  57. }
  58. else
  59. {
  60. EV.PostWarningLog(Module, $"Can not pick, Robot both arm has wafer");
  61. return Result.FAIL;
  62. }
  63. }
  64. if (_hand == Hand.Both)
  65. {
  66. if (!SC.GetValueOrDefault<bool>("EFEM.EfemRobot.LowerBladeEnable"))
  67. {
  68. EV.PostAlarmLog(Module, $"Can not pick, Lower Blade is Disabled");
  69. return Result.FAIL;
  70. }
  71. if (!SC.GetValueOrDefault<bool>("EFEM.EfemRobot.UpperBladeEnable"))
  72. {
  73. EV.PostAlarmLog(Module, $"Can not pick, Upper Blade is Disabled");
  74. return Result.FAIL;
  75. }
  76. if (WaferManager.Instance.GetWafers(_source).Length < 2)
  77. {
  78. EV.PostWarningLog(Module, $"Can not pick use both arm, Only one slot at {_source}");
  79. return Result.FAIL;
  80. }
  81. if (!WaferManager.Instance.CheckHasWafer(_source, _sourceSlot))
  82. {
  83. EV.PostWarningLog(Module, $"Can not pick, No wafer at {_source}, {_sourceSlot + 1}");
  84. return Result.FAIL;
  85. }
  86. if (!WaferManager.Instance.CheckHasWafer(_source, _sourceSlot + 1))
  87. {
  88. EV.PostWarningLog(Module, $"Can not pick, No wafer at {_source}, {_sourceSlot + 1 + 1}");
  89. return Result.FAIL;
  90. }
  91. if (!WaferManager.Instance.CheckNoWafer(Module, (int)Hand.Blade1))
  92. {
  93. EV.PostWarningLog(Module, $"Can not pick, Robot arm 1 has wafer");
  94. return Result.FAIL;
  95. }
  96. if (!WaferManager.Instance.CheckNoWafer(Module, (int)Hand.Blade2))
  97. {
  98. EV.PostWarningLog(Module, $"Can not pick, Robot arm 2 has wafer");
  99. return Result.FAIL;
  100. }
  101. }
  102. else
  103. {
  104. if (_hand == Hand.Blade1 && !SC.GetValueOrDefault<bool>("EFEM.EfemRobot.LowerBladeEnable"))
  105. {
  106. EV.PostAlarmLog(Module, $"Can not pick, Lower Blade is Disabled");
  107. return Result.FAIL;
  108. }
  109. if (_hand == Hand.Blade2 && !SC.GetValueOrDefault<bool>("EFEM.EfemRobot.UpperBladeEnable"))
  110. {
  111. EV.PostAlarmLog(Module, $"Can not pick, Upper Blade is Disabled");
  112. return Result.FAIL;
  113. }
  114. if (!WaferManager.Instance.CheckHasWafer(_source, _sourceSlot))
  115. {
  116. EV.PostWarningLog(Module, $"Can not pick, No wafer at {_source}, {_sourceSlot + 1}");
  117. return Result.FAIL;
  118. }
  119. if (!WaferManager.Instance.CheckNoWafer(Module, (int)_hand))
  120. {
  121. EV.PostWarningLog(Module, $"Can not pick, Robot arm {(int)_hand + 1} has wafer");
  122. return Result.FAIL;
  123. }
  124. }
  125. Notify($"Start, Pick from {_source} slot {_sourceSlot + 1}, by {_hand}");
  126. return Result.RUN;
  127. }
  128. public void Init(ModuleName source, int slot, Hand hand)
  129. {
  130. _autoHand = false;
  131. _source = source;
  132. _sourceSlot = slot;
  133. _hand = hand;
  134. if (ModuleHelper.IsPm(source))
  135. _postTransferTimeout = SC.GetValue<int>($"PM.PostTransferTimeout");
  136. _target = EquipmentManager.Modules[source] as ITransferTarget;
  137. }
  138. public void Init(ModuleName source, int slot)
  139. {
  140. _autoHand = true;
  141. _source = source;
  142. _sourceSlot = slot;
  143. if (ModuleHelper.IsPm(source))
  144. _postTransferTimeout = SC.GetValue<int>($"PM.PostTransferTimeout");
  145. _target = EquipmentManager.Modules[source] as ITransferTarget;
  146. }
  147. public void Abort()
  148. {
  149. if (_target != null)
  150. {
  151. _target.NoteTransferStop(ModuleName.EfemRobot, Hand.Blade1, 0, EnumTransferType.Pick);
  152. }
  153. _target = null;
  154. Notify("Abort");
  155. }
  156. public Result Monitor()
  157. {
  158. try
  159. {
  160. if (ModuleHelper.IsPm(_source))
  161. {
  162. if (!_target.CheckReadyForTransfer(ModuleName.EfemRobot, _hand, _sourceSlot, EnumTransferType.Pick, out _))
  163. {
  164. PrepareTransfer((int)RoutineStep.PrepareTransfer, _target as PMModuleBase, EnumTransferType.Pick, _postTransferTimeout);
  165. }
  166. }
  167. if (_hand == Hand.Both)
  168. {
  169. CheckBeforePick((int)RoutineStep.CheckBeforePick, _source, _sourceSlot, Hand.Blade1);
  170. PickWafer((int)RoutineStep.PickWafer, _source, _sourceSlot, Hand.Blade1, _pickTimeout);
  171. CheckBeforePick((int)RoutineStep.CheckBeforePick2, _source, _sourceSlot + 1, Hand.Blade2);
  172. PickWafer((int)RoutineStep.PickWafer2, _source, _sourceSlot + 1, Hand.Blade2, _pickTimeout);
  173. }
  174. else
  175. {
  176. CheckBeforePick((int)RoutineStep.CheckBeforePick, _source, _sourceSlot, _hand);
  177. if (ModuleHelper.IsPm(_source))
  178. {
  179. RobotExtend((int)RoutineStep.PickExtend, _source, _sourceSlot, _hand, RobotPostionEnum.PickExtendLow, _pickTimeout);
  180. MovePinDown((int)RoutineStep.LiftDown, _target as PMModuleBase, EnumTransferType.Extend, _pickTimeout);
  181. RobotRetract((int)RoutineStep.PickRetract, _source, _sourceSlot, _hand, RobotPostionEnum.PickRetracted, _pickTimeout);
  182. //放到process过程中,提高产能
  183. //LiftPinDown((int)RoutineStep.LiftDown, _target as PMModuleBase, EnumTransferType.Retract, _pickTimeout);
  184. }
  185. else
  186. {
  187. PickWafer((int)RoutineStep.PickWafer, _source, _sourceSlot, _hand, _pickTimeout);
  188. }
  189. }
  190. if (ModuleHelper.IsPm(_source))
  191. {
  192. PostTransfer((int)RoutineStep.PostTransfer, _target as PMModuleBase, EnumTransferType.Pick, _postTransferTimeout);
  193. }
  194. }
  195. catch (RoutineBreakException)
  196. {
  197. return Result.RUN;
  198. }
  199. catch (RoutineFaildException)
  200. {
  201. return Result.FAIL;
  202. }
  203. _target.NoteTransferStop(ModuleName.EfemRobot, Hand.Blade1, 0, EnumTransferType.Pick);
  204. Notify($"Finish, Pick from {_source} slot {_sourceSlot + 1}, by {_hand}");
  205. return Result.DONE;
  206. }
  207. public void CheckBeforePick(int id, ModuleName source, int slot, Hand blade)
  208. {
  209. Tuple<bool, Result> ret = Execute(id, () =>
  210. {
  211. Notify("Check pick is enabled");
  212. string reason = string.Empty;
  213. if (!_target.CheckReadyForTransfer(ModuleName.EfemRobot, _hand, _sourceSlot, EnumTransferType.Pick, out reason))
  214. {
  215. Stop(reason);
  216. return false;
  217. }
  218. if (blade == Hand.Blade1)
  219. {
  220. if (!WaferManager.Instance.CheckHasWafer(source, slot))
  221. {
  222. Stop("Source no wafer");
  223. return false;
  224. }
  225. if (!WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0))
  226. {
  227. Stop("Blade has wafer");
  228. return false;
  229. }
  230. }
  231. else if (blade == Hand.Blade2)
  232. {
  233. if (!WaferManager.Instance.CheckHasWafer(source, slot))
  234. {
  235. Stop("Source no wafer");
  236. return false;
  237. }
  238. if (!WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1))
  239. {
  240. Stop("Blade has wafer");
  241. return false;
  242. }
  243. }
  244. else
  245. {
  246. for (int i = 0; i < 2; i++)
  247. {
  248. if (!WaferManager.Instance.CheckHasWafer(source, slot + i))
  249. {
  250. Stop("Source no wafer");
  251. return false;
  252. }
  253. if (!WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, i))
  254. {
  255. Stop("Blade has wafer");
  256. return false;
  257. }
  258. }
  259. }
  260. return true;
  261. });
  262. if (ret.Item1)
  263. {
  264. if (ret.Item2 == Result.FAIL)
  265. {
  266. throw (new RoutineFaildException());
  267. }
  268. }
  269. }
  270. public void PickWafer(int id, ModuleName chamber, int slot, Hand hand, int timeout)
  271. {
  272. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  273. {
  274. Notify("robot execute pick command");
  275. _target.NoteTransferStart(ModuleName.EfemRobot, Hand.Blade1, 0, EnumTransferType.Pick);
  276. string reason;
  277. if (!_robotModule.RobotDevice.Pick(chamber, hand, slot, out reason))
  278. {
  279. Stop(reason);
  280. return false;
  281. }
  282. return true;
  283. }, () =>
  284. {
  285. if (_robotModule.RobotDevice.IsError)
  286. return null;
  287. if (_robotModule.RobotDevice.IsIdle)
  288. return true;
  289. return false;
  290. }, timeout * 1000);
  291. if (ret.Item1)
  292. {
  293. if (ret.Item2 == Result.FAIL)
  294. {
  295. Stop(string.Format("failed."));
  296. throw (new RoutineFaildException());
  297. }
  298. else if (ret.Item2 == Result.TIMEOUT) //timeout
  299. {
  300. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  301. throw (new RoutineFaildException());
  302. }
  303. else
  304. throw (new RoutineBreakException());
  305. }
  306. }
  307. public void PostTransfer(int id, PMModuleBase pm, EnumTransferType type, int timeout)
  308. {
  309. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  310. {
  311. Notify($"{pm.Name} post transfer ");
  312. if (!pm.PostTransfer(ModuleName.EfemRobot, Hand.Blade1, 0, type, out string reason))
  313. {
  314. Stop(reason);
  315. return false;
  316. }
  317. return true;
  318. }, () =>
  319. {
  320. if (pm.IsError)
  321. {
  322. return null;
  323. }
  324. return pm.IsReady;
  325. }, timeout * 1000);
  326. if (ret.Item1)
  327. {
  328. if (ret.Item2 == Result.FAIL)
  329. {
  330. Stop($"{pm.Name} error");
  331. throw (new RoutineFaildException());
  332. }
  333. else if (ret.Item2 == Result.TIMEOUT) //timeout
  334. {
  335. Stop($"{pm.Name} post transfer timeout, over {timeout} seconds");
  336. throw (new RoutineFaildException());
  337. }
  338. else
  339. throw (new RoutineBreakException());
  340. }
  341. }
  342. public void PrepareTransfer(int id, PMModuleBase pm, EnumTransferType type, int timeout)
  343. {
  344. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  345. {
  346. Notify($"{pm.Name} Prepare transfer ");
  347. if (!pm.PrepareTransfer(ModuleName.EfemRobot, Hand.Blade1, 0, type, 0, 0, false, out string reason))
  348. {
  349. Stop(reason);
  350. return false;
  351. }
  352. return true;
  353. }, () =>
  354. {
  355. if (pm.IsError)
  356. {
  357. return null;
  358. }
  359. return pm.IsReady;
  360. }, timeout * 1000);
  361. if (ret.Item1)
  362. {
  363. if (ret.Item2 == Result.FAIL)
  364. {
  365. Stop($"{pm.Name} error");
  366. throw (new RoutineFaildException());
  367. }
  368. else if (ret.Item2 == Result.TIMEOUT) //timeout
  369. {
  370. Stop($"{pm.Name} Prepare transfer timeout, over {timeout} seconds");
  371. throw (new RoutineFaildException());
  372. }
  373. else
  374. throw (new RoutineBreakException());
  375. }
  376. }
  377. public void RobotExtend(int id, ModuleName chamber, int slot, Hand hand, RobotPostionEnum robotPostion, int timeout)
  378. {
  379. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  380. {
  381. Notify("robot execute goto command");
  382. //string reason;
  383. //if (!_robotModule.RobotDevice.GotoRE(chamber, hand, slot, robotPostion, out reason))
  384. //{
  385. // Stop(reason);
  386. // return false;
  387. //}
  388. return true;
  389. }, () =>
  390. {
  391. if (_robotModule.RobotDevice.IsError)
  392. return null;
  393. if (_robotModule.RobotDevice.IsIdle)
  394. return true;
  395. return false;
  396. }, timeout * 1000);
  397. if (ret.Item1)
  398. {
  399. if (ret.Item2 == Result.FAIL)
  400. {
  401. Stop(string.Format("failed."));
  402. throw (new RoutineFaildException());
  403. }
  404. else if (ret.Item2 == Result.TIMEOUT) //timeout
  405. {
  406. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  407. throw (new RoutineFaildException());
  408. }
  409. else
  410. throw (new RoutineBreakException());
  411. }
  412. }
  413. public void RobotRetract(int id, ModuleName chamber, int slot, Hand hand, RobotPostionEnum robotPostion, int timeout)
  414. {
  415. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  416. {
  417. Notify("robot execute goto command");
  418. //string reason;
  419. //if (!_robotModule.RobotDevice.GotoRE(chamber, hand, slot, robotPostion, out reason))
  420. //{
  421. // Stop(reason);
  422. // return false;
  423. //}
  424. return true;
  425. }, () =>
  426. {
  427. if (_robotModule.RobotDevice.IsError)
  428. return null;
  429. if (_robotModule.RobotDevice.IsIdle)
  430. return true;
  431. return false;
  432. }, timeout * 1000);
  433. if (ret.Item1)
  434. {
  435. if (ret.Item2 == Result.FAIL)
  436. {
  437. Stop(string.Format("failed."));
  438. throw (new RoutineFaildException());
  439. }
  440. else if (ret.Item2 == Result.TIMEOUT) //timeout
  441. {
  442. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  443. throw (new RoutineFaildException());
  444. }
  445. else
  446. throw (new RoutineBreakException());
  447. }
  448. }
  449. public void MovePinUp(int id, PMModuleBase pm, EnumTransferType type, int timeout)
  450. {
  451. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  452. {
  453. Notify($"{pm.Name} lift pin up ");
  454. //if (!pm.ChamberLiftPin.MoveUp(out string reason))
  455. //{
  456. // Stop(reason);
  457. // return false;
  458. //}
  459. return true;
  460. }, () =>
  461. {
  462. //if(pm.ChamberLiftPin.IsUp)
  463. // return true;
  464. return false;
  465. }, timeout * 1000);
  466. if (ret.Item1)
  467. {
  468. if (ret.Item2 == Result.FAIL)
  469. {
  470. throw (new RoutineFaildException());
  471. }
  472. else if (ret.Item2 == Result.TIMEOUT) //timeout
  473. {
  474. Stop($"{pm.Name} move lift pin up timeout, over {timeout} seconds");
  475. throw (new RoutineFaildException());
  476. }
  477. else
  478. throw (new RoutineBreakException());
  479. }
  480. }
  481. public void MovePinDown(int id, PMModuleBase pm, EnumTransferType type, int timeout)
  482. {
  483. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  484. {
  485. Notify($"{pm.Name} lift pin down");
  486. //if (!pm.ChamberLiftPin.MoveDown(out string reason))
  487. //{
  488. // Stop(reason);
  489. // return false;
  490. //}
  491. return true;
  492. }, () =>
  493. {
  494. //if (pm.ChamberLiftPin.IsDown)
  495. // return true;
  496. return false;
  497. }, timeout * 1000);
  498. if (ret.Item1)
  499. {
  500. if (ret.Item2 == Result.FAIL)
  501. {
  502. throw (new RoutineFaildException());
  503. }
  504. else if (ret.Item2 == Result.TIMEOUT) //timeout
  505. {
  506. Stop($"{pm.Name} move down lift pin timeout, over {timeout} seconds");
  507. throw (new RoutineFaildException());
  508. }
  509. else
  510. throw (new RoutineBreakException());
  511. }
  512. }
  513. }
  514. }