SwapRoutine.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. using System;
  2. using Aitex.Core.Common;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.Routine;
  6. using Aitex.Core.RT.SCCore;
  7. using EFEM.RT.Modules;
  8. using Aitex.Sorter.Common;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  12. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  13. using System.Security.Cryptography;
  14. namespace EFEM.RT.Routines
  15. {
  16. public class SwapRoutine : CommonRoutine, IRoutine
  17. {
  18. enum Swap
  19. {
  20. QueryState,
  21. CheckBeforeSwap,
  22. SwapWafer,
  23. WaitSwap,
  24. PickWafer,
  25. WaitPick,
  26. PlaceWafer,
  27. WaitPlace,
  28. CheckAfterSwap,
  29. CoolBufferMoveUP,
  30. WaitCoolBufferMoveUP,
  31. CoolBufferMoveDown,
  32. PostMessage,
  33. RobotBusytoSimifOn,
  34. RobotBusytoSimifOff,
  35. CheckBlade1WaferPrecense,
  36. CheckBlade2WaferPrecense,
  37. CheckBlade1WaferPrecenseAfterSwap,
  38. CheckBlade2WaferPrecenseAfterSwap,
  39. QuerySignalStatus,
  40. WaitCoolBufferMoveDown,
  41. PinDown,
  42. NotifyFlipperPrepare,
  43. NotifyFlipperOver
  44. }
  45. private SCConfigItem _scSwapTimeout = null;
  46. private int _timeout = 0;
  47. public SwapRoutine(string module, string name)
  48. {
  49. Module = module;
  50. Name = name;
  51. _scSwapTimeout = SC.GetConfigItem(SorterCommon.ScPathName.Robot_TimeLimitForPlaceWafer);
  52. }
  53. public bool Initalize()
  54. {
  55. IsStopped = true;
  56. return true;
  57. }
  58. public ModuleName Source { get; set; }
  59. public int Slot { get; set; }
  60. public Hand PlaceBlade { get; set; }
  61. public LoadPort _lpDevice;
  62. private int _offsetXPick;
  63. private int _offsetYPick;
  64. private int _offsetZPick;
  65. private int _offsetXPlace;
  66. private int _offsetYPlace;
  67. private int _offsetZPLace;
  68. private Hand _pickHand;
  69. private int _alignerdelay = 0;
  70. private int _coolingdelay = 0;
  71. private int delaytime = 0;
  72. public Result Start(params object[] objs)
  73. {
  74. IsStopped = false;
  75. Reset();
  76. _timeout = robot.RobotCommandTimeout; ;
  77. Reset();
  78. EV.PostMessage(ModuleName.System.ToString(), EventEnum.GeneralInfo, string.Format("swap wafer {0}{1:D2} place blade {2} start", Source.ToString(), Slot + 1, PlaceBlade.ToString()));
  79. if (ModuleHelper.IsCoolingBuffer(Source))
  80. delaytime = _coolingdelay * 1000;
  81. else delaytime = _alignerdelay * 1000;
  82. _pickHand = Hand.Blade1;
  83. if (PlaceBlade == Hand.Blade1)
  84. _pickHand = Hand.Blade2;
  85. return Result.RUN;
  86. }
  87. public Result Monitor()
  88. {
  89. try
  90. {
  91. if (IsStopped) return Result.DONE;
  92. if (ModuleHelper.IsCoolingBuffer(Source) || ModuleHelper.IsAligner(Source))
  93. {
  94. var dev = GetCoolBuffer(Source);
  95. if (dev != null)
  96. {
  97. //QueryCoolBufferState((int)Pick.QueryState, GetCoolBuffer(Source));
  98. CoolBufferMoveUP((int)Swap.CoolBufferMoveUP, GetCoolBuffer(Source), WaferManager.Instance.GetWaferSize(Source, Slot), _timeout, Notify, Stop);
  99. WaitCoolBufferMoveUp((int)Swap.WaitCoolBufferMoveUP, GetCoolBuffer(Source), "Wait CoolingBuffer Move Up...", _timeout, Notify, Stop);
  100. }
  101. }
  102. else if (ModuleHelper.IsFlipper(Source))
  103. {
  104. FlipperPrepare((int)Swap.NotifyFlipperPrepare, GetFlipper(), "Flipper Prepare Transfer...", _timeout, Notify, Stop);
  105. }
  106. //if (ModuleHelper.IsLoadLock(Source))
  107. //{
  108. // if (Source.Equals("LL1")) ll1.SafeytoPm(true);
  109. // else if (Source.Equals("LL2")) ll2.SafeytoPm(true);
  110. //}
  111. //RobotSignalStatus((int)Swap.QuerySignalStatus, robot, _timeout);
  112. CheckBladeWaferIsExist((int)Swap.CheckBlade1WaferPrecense, robot, Hand.Blade1, _timeout);
  113. CheckBladeWaferIsExist((int)Swap.CheckBlade2WaferPrecense, robot, Hand.Blade2, _timeout);
  114. CheckBeforeSwap((int)Swap.CheckBeforeSwap, "Check wafer information", Source, Slot, _pickHand, Notify, Stop);
  115. //if (ModuleHelper.IsLoadPort(Source))
  116. //{
  117. // RobotBusytoSimif((int)Swap.RobotBusytoSimifOn, Source, true, _timeout, Notify, Stop);
  118. //}
  119. //if (OffsetX == 0 && OffsetY == 0 && OffsetZ == 0)
  120. //{
  121. // PickWafer((int)Swap.PickWafer, "Pick wafer", Source, Slot, _pickHand, _offsetXPick, _offsetYPick, _offsetZPick, Notify, Stop);
  122. // this.WaitRobotMotion((int)Swap.WaitPick, robot, "Wait picked", _timeout, Notify, Stop);
  123. // PlaceWafer((int)Swap.PlaceWafer, "Place wafer", Source, Slot, PlaceBlade, _offsetXPlace, _offsetYPlace, _offsetZPLace, Notify, Stop);
  124. // this.WaitRobotMotion((int)Swap.WaitPlace, robot, "Wait Placed", _timeout, Notify, Stop);
  125. //}
  126. //else
  127. //{
  128. if (!ModuleHelper.IsLoadLock(Source))
  129. {
  130. if (ModuleHelper.IsCoolingBuffer(Source) || ModuleHelper.IsAligner(Source))
  131. {
  132. SwapWafer((int)Swap.SwapWafer, "Swap wafer", Source, Slot, _pickHand, OffsetX, OffsetY, OffsetZ, Notify, Stop);
  133. }
  134. else
  135. {
  136. PickWafer((int)Swap.PickWafer, "Pick wafer", Source, Slot, _pickHand, _offsetXPick, _offsetYPick, _offsetZPick, Notify, Stop);
  137. this.WaitRobotMotion((int)Swap.WaitPick, robot, "Wait picked", _timeout, Notify, Stop);
  138. PlaceWafer((int)Swap.PlaceWafer, "Place wafer", Source, Slot, PlaceBlade, _offsetXPlace, _offsetYPlace, _offsetZPLace, Notify, Stop);
  139. this.WaitRobotMotion((int)Swap.WaitPlace, robot, "Wait Placed", _timeout, Notify, Stop);
  140. }
  141. }
  142. //}
  143. this.WaitRobotMotion((int)Swap.WaitSwap, robot, "Wait swap finish", _timeout, Notify, Stop);
  144. //if (ModuleHelper.IsLoadPort(Source))
  145. //{
  146. // RobotBusytoSimif((int)Swap.RobotBusytoSimifOn, Source, true, _timeout, Notify, Stop);
  147. //}
  148. if (ModuleHelper.IsCoolingBuffer(Source) || ModuleHelper.IsAligner(Source))
  149. {
  150. var dev = GetCoolBuffer(Source);
  151. if (dev != null)
  152. {
  153. TimeDelay((int)Swap.PinDown, delaytime);
  154. CoolBufferMoveDown((int)Swap.CoolBufferMoveDown, GetCoolBuffer(Source), WaferManager.Instance.GetWaferSize(Source, Slot), _timeout, Notify, Stop);
  155. WaitCoolBufferMoveDown((int)Swap.WaitCoolBufferMoveDown, GetCoolBuffer(Source), "Wait CoolingBuffer Move Down...", _timeout, Notify, Stop);
  156. }
  157. }
  158. else if(ModuleHelper.IsFlipper(Source))
  159. {
  160. FlipperComplete((int)Swap.NotifyFlipperOver, GetFlipper(), "Flipper Complete Transfer...", _timeout, Notify, Stop);
  161. }
  162. PostMessage((int)Swap.PostMessage, string.Format("Swap wafer {0}{1:D2} place blade {2}", Source.ToString(), Slot + 1, PlaceBlade.ToString()));
  163. CheckBladeWaferIsExist((int)Swap.CheckBlade1WaferPrecenseAfterSwap, robot, Hand.Blade1, _timeout);
  164. CheckBladeWaferIsExist((int)Swap.CheckBlade2WaferPrecenseAfterSwap, robot, Hand.Blade2, _timeout);
  165. CheckAfterSwap((int)Swap.CheckAfterSwap, "Check wafer information after swap", Source, Slot, PlaceBlade, Notify, Stop);
  166. }
  167. catch (RoutineBreakException)
  168. {
  169. return Result.RUN;
  170. }
  171. catch (RoutineFaildException)
  172. {
  173. IsStopped = true;
  174. return Result.FAIL;
  175. }
  176. IsStopped = true;
  177. return Result.DONE;
  178. }
  179. protected override void Notify(string message)
  180. {
  181. EV.PostMessage(Module, EventEnum.GeneralInfo, String.Format("Swap wafer:{0}", message));
  182. }
  183. /// <summary>
  184. /// prepare process failed
  185. /// </summary>
  186. /// <param name="failReason"></param>
  187. /// <param name="reactor"></param>
  188. protected override void Stop(string failReason)
  189. {
  190. string reason = String.Empty;
  191. EV.PostMessage(ModuleName.System.ToString(), EventEnum.GeneralInfo, string.Format("Swap wafer {0}{1:D2} with arm {2} failed, {3}", Source.ToString(), Slot + 1, PlaceBlade.ToString(), failReason));
  192. }
  193. private void SwapWafer(int id, string name, ModuleName chamber, int slot, Hand blade, int x, int y, int z,
  194. Action<string> notify, Action<string> error)
  195. {
  196. Tuple<bool, Result> ret = Execute(id, () =>
  197. {
  198. notify(String.Format("Swap wafer {0}{1:D2}", chamber.ToString(), slot));
  199. string reason = string.Empty;
  200. if (x == 0 && y == 0 && z == 0)
  201. return robot.Swap((RobotArmEnum)blade,chamber.ToString(), slot);
  202. return robot.SwapEx((RobotArmEnum)blade, chamber.ToString(), slot, x, y, z,0);
  203. });
  204. if (ret.Item1)
  205. {
  206. if (ret.Item2 == Result.FAIL)
  207. {
  208. throw (new RoutineFaildException());
  209. }
  210. }
  211. }
  212. public void CheckBeforeSwap(int id, string name, ModuleName chamber, int slot, Hand blade, Action<string> notify, Action<string> error)
  213. {
  214. Tuple<bool, Result> ret = Execute(id, () =>
  215. {
  216. notify(String.Format("Check target {0}{1:D2} wafer information", chamber.ToString(), slot));
  217. string reason = string.Empty;
  218. if (!CheckRobotMotionInterlock(chamber, slot, out reason))
  219. {
  220. EV.PostMessage(ModuleName.System.ToString(), EventEnum.TransferPrepareFailed, String.Format("target {0}{1:D2},{2}", chamber.ToString(), slot + 1, reason));
  221. return false;
  222. }
  223. if (blade == Hand.Blade1)
  224. {
  225. bool bHasWafer = WaferManager.Instance.CheckWafer(chamber, slot, WaferStatus.Normal);
  226. if (!bHasWafer)
  227. {
  228. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferAbsentWithoutRecord, String.Format("target {0}{1:D2}", chamber.ToString(), slot + 1));
  229. return false;
  230. }
  231. bHasWafer = WaferManager.Instance.CheckWafer(ModuleName.Robot, (int)Hand.Blade1, WaferStatus.Normal);
  232. if (bHasWafer)
  233. {
  234. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  235. return false;
  236. }
  237. bHasWafer = CheckSeneorHasWafer(ModuleName.Robot, (int)Hand.Blade1); //check sensor
  238. if (bHasWafer)
  239. {
  240. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  241. return false;
  242. }
  243. bool bNoWafer = WaferManager.Instance.CheckWafer(ModuleName.Robot, (int)Hand.Blade2, WaferStatus.Normal);
  244. if (!bNoWafer)
  245. {
  246. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDetectedBeforePick);
  247. return false;
  248. }
  249. bNoWafer = CheckSensorNoWafer(ModuleName.Robot, (int)Hand.Blade2); //check sensor
  250. if (bNoWafer)
  251. {
  252. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDetectedBeforePick);
  253. return false;
  254. }
  255. }
  256. else
  257. {
  258. bool bHasWafer = WaferManager.Instance.CheckWafer(chamber, slot, WaferStatus.Normal);
  259. if (!bHasWafer)
  260. {
  261. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferAbsentWithoutRecord, String.Format("target {0}{1:D2}", chamber.ToString(), slot + 1));
  262. return false;
  263. }
  264. bHasWafer = WaferManager.Instance.CheckWafer(ModuleName.Robot, (int)Hand.Blade2, WaferStatus.Normal);
  265. if (bHasWafer)
  266. {
  267. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  268. return false;
  269. }
  270. bHasWafer = CheckSeneorHasWafer(ModuleName.Robot, (int)Hand.Blade2); //check sensor
  271. if (bHasWafer)
  272. {
  273. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  274. return false;
  275. }
  276. bool bNoWafer = WaferManager.Instance.CheckWafer(ModuleName.Robot, (int)Hand.Blade1, WaferStatus.Normal);
  277. if (!bNoWafer)
  278. {
  279. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDetectedBeforePick);
  280. return false;
  281. }
  282. bNoWafer = CheckSensorNoWafer(ModuleName.Robot, (int)Hand.Blade1); //check sensor
  283. if (bNoWafer)
  284. {
  285. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDetectedBeforePick);
  286. return false;
  287. }
  288. }
  289. return true;
  290. });
  291. if (ret.Item1)
  292. {
  293. if (ret.Item2 == Result.FAIL)
  294. {
  295. error(String.Format("Failed to swap, wafer information not correct."));
  296. throw (new RoutineFaildException());
  297. }
  298. }
  299. }
  300. public void CheckAfterSwap(int id, string name, ModuleName chamber, int slot, Hand blade, Action<string> notify, Action<string> error)
  301. {
  302. Tuple<bool, Result> ret = Execute(id, () =>
  303. {
  304. notify(name);
  305. if (blade == Hand.Blade1)
  306. {
  307. bool bNoWafer = CheckSensorNoWafer(ModuleName.Robot, (int)Hand.Blade1);
  308. if (!bNoWafer)
  309. {
  310. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDetectedAfterSend);
  311. return false;
  312. }
  313. bool bHasWafer = CheckSeneorHasWafer(ModuleName.Robot, (int)Hand.Blade2);
  314. if (!bHasWafer)
  315. {
  316. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedAfterPick);
  317. return false;
  318. }
  319. }
  320. else
  321. {
  322. bool bNoWafer = CheckSensorNoWafer(ModuleName.Robot, (int)Hand.Blade2);
  323. if (!bNoWafer)
  324. {
  325. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDetectedAfterSend);
  326. return false;
  327. }
  328. bool bHasWafer = CheckSeneorHasWafer(ModuleName.Robot, (int)Hand.Blade1);
  329. if (!bHasWafer)
  330. {
  331. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedAfterPick);
  332. return false;
  333. }
  334. }
  335. return true;
  336. });
  337. if (ret.Item1)
  338. {
  339. if (ret.Item2 == Result.FAIL)
  340. {
  341. error(String.Format("Failed to check information after swap."));
  342. throw (new RoutineFaildException());
  343. }
  344. }
  345. }
  346. }
  347. }