TMPickAndPlaceRoutine.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. using System;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Sorter.Common;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.Schedulers;
  8. using MECF.Framework.Common.SubstrateTrackings;
  9. using MECF.Framework.RT.EquipmentLibrary.LogicUnits;
  10. using MECF.Framework.RT.ModuleLibrary.PMModules;
  11. using MECF.Framework.RT.ModuleLibrary.SystemModules;
  12. namespace JetMainframe.TMs
  13. {
  14. public class TMPickAndPlaceRoutine : ModuleRoutine, IRoutine
  15. {
  16. enum RoutineStep
  17. {
  18. CheckBeforePick,
  19. PickWafer,
  20. UpdateWaferInfoToHand,
  21. CheckBeforePlace,
  22. PlaceWafer,
  23. UpdateWaferInfoToTarget,
  24. PostTransfer,
  25. }
  26. private TMModule _robotModule;
  27. private ITransferTarget _target;
  28. private Hand _pickBlade;
  29. private Hand _placeBlade;
  30. private ModuleName _targetModule;
  31. private int _pickSlot;
  32. private int _placeSlot;
  33. private int _pickTimeout;
  34. private int _placeTimeout;
  35. private int _postTransferTimeout;
  36. public TMPickAndPlaceRoutine(TMModule robotModule)
  37. {
  38. Module = "TM";
  39. Name = "PickAndPlace";
  40. _robotModule = robotModule;
  41. }
  42. public Result Start(params object[] objs)
  43. {
  44. _pickTimeout = SC.GetValue<int>("TM.TMRobot.PickTimeout");
  45. _placeTimeout = SC.GetValue<int>("TM.TMRobot.PlaceTimeout");
  46. if (ModuleHelper.IsPm(_targetModule))
  47. {
  48. _postTransferTimeout = SC.GetValue<int>($"PM.PostTransferTimeout");
  49. }
  50. Reset();
  51. if (!WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_pickBlade))
  52. {
  53. EV.PostWarningLog(Module, $"Can not pick by {_pickBlade}, found wafer on");
  54. return Result.FAIL;
  55. }
  56. if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_placeBlade))
  57. {
  58. EV.PostWarningLog(Module, $"Can not place by {_placeBlade}, no wafer on");
  59. return Result.FAIL;
  60. }
  61. if (_pickSlot != _placeSlot)
  62. {
  63. if (!WaferManager.Instance.CheckHasWafer(_targetModule, _pickSlot))
  64. {
  65. EV.PostWarningLog(Module, $"Can not pick from {_targetModule} slot {_pickSlot + 1}, no wafer on");
  66. return Result.FAIL;
  67. }
  68. if (!WaferManager.Instance.CheckNoWafer(_targetModule, _placeSlot))
  69. {
  70. EV.PostWarningLog(Module, $"Can not place to {_targetModule} slot {_placeSlot + 1}, found wafer on");
  71. return Result.FAIL;
  72. }
  73. }
  74. else
  75. {
  76. if (!WaferManager.Instance.CheckHasWafer(_targetModule, _placeSlot))
  77. {
  78. {
  79. EV.PostWarningLog(Module, $"Can not pick&place from {_targetModule} slot {_placeSlot + 1}, no wafer on");
  80. return Result.FAIL;
  81. }
  82. }
  83. }
  84. Notify($"Start, swap wafer,pick: {_pickBlade} slot {_pickSlot + 1}, place: {_placeBlade} slot {_placeSlot + 1}");
  85. return Result.RUN;
  86. }
  87. public void Init(ModuleName targetModule, Hand pickBlade, int pickSlot, Hand placeBlade, int placeSlot)
  88. {
  89. _pickBlade = pickBlade;
  90. _placeBlade = placeBlade;
  91. _targetModule = targetModule;
  92. _pickSlot = pickSlot;
  93. _placeSlot = placeSlot;
  94. _target = EquipmentManager.Modules[targetModule] as ITransferTarget;
  95. }
  96. public void Abort()
  97. {
  98. if (_target != null)
  99. {
  100. _target.NoteTransferStop(ModuleName.TMRobot, Hand.Blade1, 0, EnumTransferType.Pick);
  101. }
  102. _target = null;
  103. Notify("Abort");
  104. }
  105. public Result Monitor()
  106. {
  107. try
  108. {
  109. CheckBeforePick((int)RoutineStep.CheckBeforePick, _targetModule, _pickSlot, _pickBlade);
  110. PickWafer((int)RoutineStep.PickWafer, _targetModule, _pickSlot, _pickBlade, _pickTimeout);
  111. UpdateWaferInfoToHand((int)RoutineStep.UpdateWaferInfoToHand, _targetModule, _pickSlot, _pickBlade);
  112. CheckBeforePlace((int)RoutineStep.CheckBeforePlace, _targetModule, _placeSlot, _placeBlade);
  113. PlaceWafer((int)RoutineStep.PlaceWafer, _targetModule, _placeSlot, _placeBlade, _pickTimeout);
  114. UpdateWaferInfoToTarget((int)RoutineStep.UpdateWaferInfoToTarget, _targetModule, _placeSlot, _placeBlade);
  115. if (ModuleHelper.IsPm(_targetModule))
  116. {
  117. PostTransfer((int)RoutineStep.PostTransfer, _target as PMModuleBase, EnumTransferType.Place, _postTransferTimeout);
  118. }
  119. }
  120. catch (RoutineBreakException)
  121. {
  122. return Result.RUN;
  123. }
  124. catch (RoutineFaildException)
  125. {
  126. return Result.FAIL;
  127. }
  128. _target.NoteTransferStop(ModuleName.TMRobot, Hand.Blade1, 0, EnumTransferType.Pick);
  129. Notify($"complete, swap wafer,pick: {_pickBlade} slot {_pickSlot + 1}, place: {_placeBlade} slot {_placeSlot + 1}");
  130. return Result.DONE;
  131. }
  132. public void CheckBeforePick(int id, ModuleName source, int slot, Hand blade)
  133. {
  134. Tuple<bool, Result> ret = Execute(id, () =>
  135. {
  136. Notify("Check pick is enabled");
  137. string reason = string.Empty;
  138. if (!_target.CheckReadyForTransfer(ModuleName.TMRobot, blade, slot, EnumTransferType.Pick, out reason))
  139. {
  140. Stop(reason);
  141. return false;
  142. }
  143. if (blade == Hand.Blade1)
  144. {
  145. if (!WaferManager.Instance.CheckHasWafer(source, slot))
  146. {
  147. Stop("Source no wafer");
  148. return false;
  149. }
  150. if (!WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0))
  151. {
  152. Stop("Blade has wafer");
  153. return false;
  154. }
  155. }
  156. else if (blade == Hand.Blade2)
  157. {
  158. if (!WaferManager.Instance.CheckHasWafer(source, slot))
  159. {
  160. Stop("Source no wafer");
  161. return false;
  162. }
  163. if (!WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  164. {
  165. Stop("Blade has wafer");
  166. return false;
  167. }
  168. }
  169. else
  170. {
  171. for (int i = 0; i < 2; i++)
  172. {
  173. if (!WaferManager.Instance.CheckHasWafer(source, slot + i))
  174. {
  175. Stop("Source no wafer");
  176. return false;
  177. }
  178. if (!WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, i))
  179. {
  180. Stop("Blade has wafer");
  181. return false;
  182. }
  183. }
  184. }
  185. return true;
  186. });
  187. if (ret.Item1)
  188. {
  189. if (ret.Item2 == Result.FAIL)
  190. {
  191. throw new RoutineFaildException();
  192. }
  193. }
  194. }
  195. public void PickWafer(int id, ModuleName chamber, int slot, Hand hand, int timeout)
  196. {
  197. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  198. {
  199. Notify("robot execute pick command");
  200. _target.NoteTransferStart(ModuleName.TMRobot, hand, slot, EnumTransferType.Pick);
  201. //string reason;
  202. //if (!_robotModule.RobotDevice.Pick(chamber, hand, slot, out reason))
  203. //{
  204. // Stop(reason);
  205. // return false;
  206. //}
  207. return true;
  208. }, () =>
  209. {
  210. if (_robotModule.RobotDevice.IsError)
  211. return null;
  212. if (_robotModule.RobotDevice.IsIdle)
  213. return true;
  214. return false;
  215. }, timeout * 1000);
  216. if (ret.Item1)
  217. {
  218. if (ret.Item2 == Result.FAIL)
  219. {
  220. Stop(string.Format("failed."));
  221. throw new RoutineFaildException();
  222. }
  223. else if (ret.Item2 == Result.TIMEOUT) //timeout
  224. {
  225. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  226. throw new RoutineFaildException();
  227. }
  228. else
  229. throw new RoutineBreakException();
  230. }
  231. }
  232. public void UpdateWaferInfoToHand(int id, ModuleName chamber, int slot, Hand hand)
  233. {
  234. Tuple<bool, Result> ret = Execute(id, () =>
  235. {
  236. WaferManager.Instance.WaferMoved(chamber,slot, ModuleName.TMRobot, (int)hand);
  237. return true;
  238. });
  239. if (ret.Item1)
  240. {
  241. if (ret.Item2 == Result.FAIL)
  242. {
  243. Stop(string.Format("failed."));
  244. throw new RoutineFaildException();
  245. }
  246. else
  247. throw new RoutineBreakException();
  248. }
  249. }
  250. public void CheckBeforePlace(int id, ModuleName source, int slot, Hand blade)
  251. {
  252. Tuple<bool, Result> ret = Execute(id, () =>
  253. {
  254. Notify("Check place condition");
  255. string reason = string.Empty;
  256. if (!_target.CheckReadyForTransfer(ModuleName.TMRobot, blade, slot, EnumTransferType.Place, out reason))
  257. {
  258. Stop(reason);
  259. return false;
  260. }
  261. if (blade == Hand.Blade1)
  262. {
  263. if (!WaferManager.Instance.CheckNoWafer(source, slot))
  264. {
  265. Stop("Source has wafer");
  266. return false;
  267. }
  268. if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0))
  269. {
  270. Stop("Blade 1 no wafer");
  271. return false;
  272. }
  273. }
  274. else if (blade == Hand.Blade2)
  275. {
  276. if (!WaferManager.Instance.CheckNoWafer(source, slot))
  277. {
  278. Stop("Source has wafer");
  279. return false;
  280. }
  281. if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1))
  282. {
  283. Stop("Blade no wafer");
  284. return false;
  285. }
  286. }
  287. else
  288. {
  289. for (int i = 0; i < 2; i++)
  290. {
  291. if (!WaferManager.Instance.CheckNoWafer(source, slot + i))
  292. {
  293. Stop("Source has wafer");
  294. return false;
  295. }
  296. if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, i))
  297. {
  298. Stop("Blade no wafer");
  299. return false;
  300. }
  301. }
  302. }
  303. return true;
  304. });
  305. if (ret.Item1)
  306. {
  307. if (ret.Item2 == Result.FAIL)
  308. {
  309. throw new RoutineFaildException();
  310. }
  311. }
  312. }
  313. public void PlaceWafer(int id, ModuleName chamber, int slot, Hand hand, int timeout)
  314. {
  315. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  316. {
  317. Notify("robot start execute place command");
  318. //string reason;
  319. _target.NoteTransferStart(ModuleName.TMRobot, hand, slot, EnumTransferType.Place);
  320. //if (!_robotModule.RobotDevice.Place(chamber, hand, slot, out reason))
  321. //{
  322. // Stop(reason);
  323. // return false;
  324. //}
  325. return true;
  326. }, () =>
  327. {
  328. if (_robotModule.RobotDevice.IsError)
  329. return null;
  330. if (_robotModule.RobotDevice.IsIdle)
  331. return true;
  332. return false;
  333. }, timeout * 1000);
  334. if (ret.Item1)
  335. {
  336. if (ret.Item2 == Result.FAIL)
  337. {
  338. throw new RoutineFaildException();
  339. }
  340. else if (ret.Item2 == Result.TIMEOUT) //timeout
  341. {
  342. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  343. throw new RoutineFaildException();
  344. }
  345. else
  346. throw new RoutineBreakException();
  347. }
  348. }
  349. public void UpdateWaferInfoToTarget(int id, ModuleName chamber, int slot, Hand hand)
  350. {
  351. Tuple<bool, Result> ret = Execute(id, () =>
  352. {
  353. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)hand,chamber, slot);
  354. return true;
  355. });
  356. if (ret.Item1)
  357. {
  358. if (ret.Item2 == Result.FAIL)
  359. {
  360. Stop(string.Format("failed."));
  361. throw new RoutineFaildException();
  362. }
  363. else
  364. throw new RoutineBreakException();
  365. }
  366. }
  367. public void PostTransfer(int id, PMModuleBase pm, EnumTransferType type, int timeout)
  368. {
  369. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  370. {
  371. Notify($"{pm.Name} post transfer ");
  372. if (!pm.PostTransfer(ModuleName.TMRobot, Hand.Blade1, 0, type, out string reason))
  373. {
  374. Stop(reason);
  375. return false;
  376. }
  377. return true;
  378. }, () =>
  379. {
  380. if (pm.IsError)
  381. {
  382. return null;
  383. }
  384. return pm.IsReady;
  385. }, timeout * 1000);
  386. if (ret.Item1)
  387. {
  388. if (ret.Item2 == Result.FAIL)
  389. {
  390. Stop($"{pm.Name} error");
  391. throw new RoutineFaildException();
  392. }
  393. else if (ret.Item2 == Result.TIMEOUT) //timeout
  394. {
  395. Stop($"{pm.Name} post transfer timeout, over {timeout} seconds");
  396. throw new RoutineFaildException();
  397. }
  398. else
  399. throw new RoutineBreakException();
  400. }
  401. }
  402. }
  403. }