EfemPlaceRoutine.cs 21 KB

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