SwapRoutine.cs 16 KB

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