PlaceRoutine.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Device.Unit;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.Routine;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using Aitex.Sorter.Common;
  9. using EFEM.RT.Devices;
  10. using MECF.Framework.Common.Equipment;
  11. using MECF.Framework.Common.SubstrateTrackings;
  12. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  13. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  14. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  15. using System;
  16. namespace EFEM.RT.Routines
  17. {
  18. public class PlaceRoutine : CommonRoutine, IRoutine, IEfemPlaceRoutine
  19. {
  20. private enum Place
  21. {
  22. QueryState,
  23. OpenLoadLockDoor,
  24. CoolBufferMoveUP,
  25. WaitCoolBufferMoveUP,
  26. CheckBeforePlace,
  27. QueryRobotParameter,
  28. RobotServoOff,
  29. WaitRobotServoOff,
  30. SetWaferSizeParameter0000,
  31. SetWaferSizeParameter0114,
  32. RobotServoOn,
  33. WaitRobotServoOn,
  34. PlaceWafer,
  35. WaitPlace,
  36. CloseLoadLockDoor,
  37. CoolBufferMoveDown,
  38. WaitCoolBufferMoveDown,
  39. CheckAfterPlace,
  40. XMove,
  41. PostMessage,
  42. RobotBusytoSimifOn,
  43. RobotBusytoSimifOff,
  44. PinDown,
  45. CheckWaferPrecense,
  46. WaitCheckWaferPrecense,
  47. CheckWaferPrecenseAfterPlace,
  48. QuerySignalStatus,
  49. RobotBladeGrip
  50. }
  51. protected bool MultiWaferSize = DeviceDefineManager.Instance.GetValue<bool>("MultiWaferSize") ?? false;
  52. protected bool EnableMoveInDiffSlotsNumLP
  53. {
  54. get
  55. {
  56. if (SC.ContainsItem("System.IsEnableMoveInDiffSlotsNumLP"))
  57. return SC.GetValue<bool>("System.IsEnableMoveInDiffSlotsNumLP");
  58. return false;
  59. }
  60. }
  61. private SCConfigItem _scPlaceTimeout = null;
  62. private int _timeout = 0;
  63. private int _axisTimeout = 0;
  64. private int _axisSpeed = 0;
  65. private int _alignerdelay = 0;
  66. private int _coolingdelay = 0;
  67. private int delaytime = 0;
  68. public PlaceRoutine(string module, string name)
  69. {
  70. Module = module; Name = name;
  71. _alignerdelay = SC.GetValue<int>("System.AlignerPinDownDelay");
  72. _coolingdelay = SC.GetValue<int>("System.CoolingPinDownDelay");
  73. _scPlaceTimeout = SC.GetConfigItem(SorterCommon.ScPathName.Robot_TimeLimitForPlaceWafer);
  74. if (HaveMotionAxis)
  75. {
  76. _axisTimeout = SC.GetValue<int>("MotionAxis.MoveTimeout");
  77. _axisSpeed = SC.GetValue<int>("MotionAxis.AutoSpeed");
  78. }
  79. }
  80. public bool Initalize()
  81. {
  82. IsStopped = true;
  83. return true;
  84. }
  85. public ModuleName Station { get; set; }
  86. public int Slot { get; set; }
  87. public Hand Blade { get; set; }
  88. public LoadPort _lpDevice;
  89. private bool _skipWait;
  90. public Result Start(params object[] objs)
  91. {
  92. IsStopped = false;
  93. Name = "Place";
  94. Reset();
  95. _timeout = robot.RobotCommandTimeout;
  96. if (ModuleHelper.IsCoolingBuffer(Station))
  97. delaytime = _coolingdelay * 1000;
  98. else delaytime = _alignerdelay * 1000;
  99. EV.PostMessage(ModuleName.System.ToString(), EventEnum.PuttingWaferToChamberBegins, string.Format("{0}{1:D2} by {2}", Station.ToString(), Slot + 1, Blade.ToString()));
  100. return Result.RUN;
  101. }
  102. public Result Monitor()
  103. {
  104. try
  105. {
  106. if (IsStopped) return Result.DONE;
  107. if (ModuleHelper.IsCoolingBuffer(Station) || ModuleHelper.IsAligner(Station))
  108. {
  109. var dev = GetCoolBuffer(Station);
  110. if (dev != null)
  111. {
  112. //QueryCoolBufferState((int)Place.QueryState, GetCoolBuffer(Station));
  113. CoolBufferMoveUP((int)Place.CoolBufferMoveUP, GetCoolBuffer(Station), WaferManager.Instance.GetWaferSize(ModuleName.Robot, 0), _timeout, Notify, Stop);
  114. WaitCoolBufferMoveUp((int)Place.WaitCoolBufferMoveUP, GetCoolBuffer(Station), "Wait CoolingBuffer Move Up...", _timeout, Notify, Stop);
  115. }
  116. }
  117. CheckBladeWaferIsExist((int)Place.CheckWaferPrecense, robot, Blade, _timeout);
  118. // RobotSignalStatus((int)Place.QuerySignalStatus, robot, _timeout);
  119. WaitRobotMotion((int)Place.WaitCheckWaferPrecense, robot, "Wait finish check wafer", _timeout, Notify, Stop);
  120. CheckBeforePlace((int)Place.CheckBeforePlace, "Check wafer before place", Station, Slot, Blade, Notify, Stop);
  121. //GripRobotBlade((int)Place.RobotBladeGrip, Blade, robot, _timeout);
  122. if (!ModuleHelper.IsLoadLock(Station))
  123. {
  124. PlaceWafer((int)Place.PlaceWafer, "Place wafer", Station, Slot, Blade, OffsetX, OffsetY, OffsetZ, Notify, Stop);
  125. this.WaitRobotMotion((int)Place.WaitPlace, robot, "Wait wafer placed", _timeout, Notify, Stop);
  126. }
  127. if (LoadLockDoorControlByStation && ModuleHelper.IsLoadLock(Station) && !Singleton<EfemEntity>.Instance.IsOnlineMode)
  128. {
  129. LoadLockCloseAtmDoor((int)Place.CloseLoadLockDoor, DEVICE.GetDevice<LoadLockDevice>(Station.ToString()), "Wait Atm Door Close", _timeout, Notify, Stop);
  130. }
  131. //为了提高上位机调度效率,机械手放片在上面就认为place指令完成。pin落下的时间和指令从上位机发送
  132. //为了保持兼容性,暂时判断了是否上位机控制,需要等cycle功能做好,这里都统一成外部控制lift pin
  133. if (!Singleton<EfemEntity>.Instance.IsOnlineMode)
  134. {
  135. if (ModuleHelper.IsCoolingBuffer(Station) || ModuleHelper.IsAligner(Station))
  136. {
  137. var dev = GetCoolBuffer(Station);
  138. if (dev != null)
  139. {
  140. TimeDelay((int)Place.PinDown, delaytime);
  141. CoolBufferMoveDown((int)Place.CoolBufferMoveDown, GetCoolBuffer(Station), WaferManager.Instance.GetWaferSize(Station, Slot), _timeout, Notify, Stop);
  142. WaitCoolBufferMoveDown((int)Place.WaitCoolBufferMoveDown, GetCoolBuffer(Station), "Wait CoolingBuffer Move Down...", _timeout, Notify, Stop);
  143. }
  144. }
  145. }
  146. PostMessage((int)Place.PostMessage, string.Format("{0}{1:D2} by {2}", Station.ToString(), Slot + 1, Blade.ToString()));
  147. //CheckBladeWaferIsExist((int)Place.CheckWaferPrecenseAfterPlace, robot, Blade, _timeout);
  148. CheckAfterPlace((int)Place.CheckAfterPlace, "Check wafer information after wafer placed", Station, Slot, Blade, Notify, Stop);
  149. }
  150. catch (RoutineBreakException)
  151. {
  152. if (!IsActived(TokenId) && !_skipWait)
  153. {
  154. _skipWait = true;
  155. return Monitor();
  156. }
  157. return Result.RUN;
  158. }
  159. catch (RoutineFaildException)
  160. {
  161. IsStopped = true;
  162. return Result.FAIL;
  163. }
  164. IsStopped = true;
  165. return Result.DONE;
  166. }
  167. protected override void Notify(string message)
  168. {
  169. EV.PostMessage(Module, EventEnum.GeneralInfo, String.Format("Place sequence:{0}", message));
  170. }
  171. /// <summary>
  172. /// prepare process failed
  173. /// </summary>
  174. /// <param name="failReason"></param>
  175. /// <param name="reactor"></param>
  176. protected override void Stop(string failReason)
  177. {
  178. string reason = String.Empty;
  179. EV.PostMessage(ModuleName.System.ToString(), EventEnum.PlaceWaferFailed, Station.ToString(), Slot + 1, Blade.ToString(), failReason);
  180. }
  181. public void PlaceWafer(int id, string name, ModuleName chamber, int slot, Hand blade, Action<string> notify, Action<string> error)
  182. {
  183. Tuple<bool, Result> ret = Execute(id, () =>
  184. {
  185. notify(String.Format("Place wafer to {0}", chamber.ToString()));
  186. string reason = string.Empty;
  187. return robot.Place((RobotArmEnum)(int)blade, chamber.ToString(), slot);
  188. });
  189. if (ret.Item1)
  190. {
  191. if (ret.Item2 == Result.FAIL)
  192. {
  193. throw (new RoutineFaildException());
  194. }
  195. }
  196. }
  197. public void CheckBeforePlace(int id, string name, ModuleName chamber, int slot, Hand blade, Action<string> notify, Action<string> error)
  198. {
  199. Tuple<bool, Result> ret = Execute(id, () =>
  200. {
  201. notify(String.Format("Check {0}{1:D2} wafer information before place wafer", chamber.ToString(), slot));
  202. string reason = string.Empty;
  203. if (!CheckRobotMotionInterlock(chamber, slot, out reason))
  204. {
  205. EV.PostMessage(ModuleName.System.ToString(), EventEnum.TransferPrepareFailed, String.Format("Target {0}{1:D2},{2}", chamber.ToString(), slot + 1, reason));
  206. return false;
  207. }
  208. if (blade == Hand.Blade1)
  209. {
  210. bool bNoWafer = WaferManager.Instance.CheckWafer(chamber, slot, WaferStatus.Empty);
  211. if (!bNoWafer)
  212. {
  213. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferPresentWithRecord, String.Format("Target {0}{1:D2}", chamber.ToString(), slot + 1));
  214. return false;
  215. }
  216. bool bHasWafer = WaferManager.Instance.CheckWafer(ModuleName.Robot, (int)blade, WaferStatus.Normal);
  217. if (!bHasWafer)
  218. {
  219. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  220. return false;
  221. }
  222. bHasWafer = CheckSeneorHasWafer(ModuleName.Robot, (int)blade); //check sensor
  223. if (!bHasWafer)
  224. {
  225. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  226. return false;
  227. }
  228. if (IsEnableIdentifyThickness)
  229. {
  230. if (ModuleHelper.IsLoadPort(chamber))
  231. {
  232. if (SC.GetStringValue($"CarrierInfo.LowerThicknessType") != SC.GetStringValue($"CarrierInfo.{chamber}ThicknessType"))
  233. {
  234. EV.PostAlarmLog(ModuleName.System.ToString(), $"The wafer thickness of the lower arm is different from {chamber}.");
  235. return false;
  236. }
  237. }
  238. }
  239. }
  240. else if (blade == Hand.Blade2)
  241. {
  242. bool bHasWafer = true;
  243. for (int i = 0; i < robot.Blade2Slots; i++)
  244. {
  245. bool bNoWafer = WaferManager.Instance.CheckWafer(chamber, slot + i, WaferStatus.Empty);
  246. if (!bNoWafer)
  247. {
  248. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferPresentWithRecord, String.Format("Target {0}{1:D2}", chamber.ToString(), slot + i + 1));
  249. return false;
  250. }
  251. bHasWafer &= WaferManager.Instance.CheckWafer(ModuleName.Robot, (int)blade + i, WaferStatus.Normal);
  252. bool bSensorWafer = CheckSeneorHasWafer(ModuleName.Robot, (int)blade + i); //check sensor
  253. if (!bSensorWafer)
  254. {
  255. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  256. return false;
  257. }
  258. }
  259. if (!bHasWafer)
  260. {
  261. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  262. return false;
  263. }
  264. if (IsEnableIdentifyThickness)
  265. {
  266. if (ModuleHelper.IsLoadPort(chamber))
  267. {
  268. if (SC.GetStringValue($"CarrierInfo.UpperThicknessType") != SC.GetStringValue($"CarrierInfo.{chamber}ThicknessType"))
  269. {
  270. EV.PostAlarmLog(ModuleName.System.ToString(), $"The wafer thickness of the lower arm is different from {chamber}.");
  271. return false;
  272. }
  273. }
  274. }
  275. }
  276. else
  277. {
  278. bool bHasWafer = true;
  279. for (int i = 0; i < robot.Blade2Slots + 1; i++)
  280. {
  281. bool bNoWafer = WaferManager.Instance.CheckWafer(chamber, slot + i, WaferStatus.Empty);
  282. if (!bNoWafer)
  283. {
  284. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferPresentWithRecord, String.Format("Target {0}{1:D2}", chamber.ToString(), slot + i + 1));
  285. return false;
  286. }
  287. bHasWafer &= WaferManager.Instance.CheckWafer(ModuleName.Robot, (int)Hand.Blade1 + i, WaferStatus.Normal);
  288. bool bSensorWafer = CheckSeneorHasWafer(ModuleName.Robot, (int)Hand.Blade1 + i); //check sensor
  289. if (!bSensorWafer)
  290. {
  291. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  292. return false;
  293. }
  294. if (ModuleHelper.IsLoadPort(chamber))
  295. {
  296. string arm = i == 0 ? "Lower" : "Upper";
  297. if (SC.GetStringValue($"CarrierInfo.{arm}ThicknessType") != SC.GetStringValue($"CarrierInfo.{chamber}ThicknessType"))
  298. {
  299. EV.PostAlarmLog(ModuleName.System.ToString(), $"The wafer thickness of the {arm} arm is different from {chamber}.");
  300. return false;
  301. }
  302. }
  303. }
  304. if (!bHasWafer)
  305. {
  306. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  307. return false;
  308. }
  309. }
  310. if (ModuleHelper.IsCoolingBuffer(chamber))
  311. {
  312. IoCoolingBuffer buffer = DEVICE.GetDevice<IoCoolingBuffer>(chamber.ToString());
  313. if (!buffer.CheckPinUp())
  314. {
  315. EV.PostWarningLog(chamber.ToString(), "Can not place wafer to buffer, buffer isn't pick position.");
  316. return false;
  317. }
  318. }
  319. if (ModuleHelper.IsLoadPort(chamber))
  320. {
  321. //WaferSize size = WaferManager.Instance.GetWaferSize(ModuleName.Robot, (blade == Hand.Both) ? 0 : (int)blade);
  322. WaferInfo wafer = WaferManager.Instance.GetWafer(ModuleName.Robot, (blade == Hand.Both) ? 0 : (int)blade);
  323. LoadPortBaseDevice lp = DEVICE.GetDevice<LoadPortBaseDevice>(chamber.ToString());
  324. LoadPortBaseDevice lp1 = DEVICE.GetDevice<LoadPortBaseDevice>(((ModuleName)wafer.OriginStation).ToString());
  325. if (!EnableMoveInDiffSlotsNumLP && lp1 != null && lp1.ValidSlotsNumber != lp.ValidSlotsNumber)
  326. {
  327. EV.PostWarningLog(chamber.ToString(), "Can not place wafer to loadport, SlotsNumber is unmatch.");
  328. return false;
  329. }
  330. if (IsEnableMultiWaferSize)
  331. {
  332. //因为此手臂只有一个手抓
  333. WaferSize size = WaferManager.Instance.GetWaferSize(ModuleName.Robot, (blade == Hand.Both) ? 0 : (int)blade);
  334. lp = DEVICE.GetDevice<LoadPortBaseDevice>(chamber.ToString());
  335. if (size != lp.GetCurrentWaferSize())
  336. {
  337. EV.PostWarningLog(chamber.ToString(), "Can not place wafer to loadport, size is unmatch.");
  338. return false;
  339. }
  340. }
  341. }
  342. return true;
  343. });
  344. if (ret.Item1)
  345. {
  346. if (ret.Item2 == Result.FAIL)
  347. {
  348. error(String.Format("Check wafer information failed, can not place."));
  349. throw (new RoutineFaildException());
  350. }
  351. }
  352. }
  353. public void CheckAfterPlace(int id, string name, ModuleName chamber, int slot, Hand blade, Action<string> notify, Action<string> error)
  354. {
  355. Tuple<bool, Result> ret = Execute(id, () =>
  356. {
  357. notify(name);
  358. //if (ModuleHelper.IsLoadLock(chamber) && Singleton<EfemEntity>.Instance.IsOnlineMode)
  359. //{
  360. // //online mode, DeleteWafer in LoadLock
  361. // WaferManager.Instance.DeleteWafer(chamber, slot);
  362. //}
  363. //if (ModuleHelper.IsBuffer(chamber) && Singleton<EfemEntity>.Instance.IsOnlineMode)
  364. //{
  365. // //online mode, DeleteWafer in LoadLock
  366. // WaferManager.Instance.DeleteWafer(chamber, slot);
  367. //}
  368. if (blade == Hand.Blade1)
  369. {
  370. bool bNoWafer = CheckSensorNoWafer(ModuleName.Robot, (int)blade);
  371. if (!bNoWafer)
  372. {
  373. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDetectedAfterSend);
  374. return false;
  375. }
  376. }
  377. else if (blade == Hand.Blade2)
  378. {
  379. for (int i = 0; i < robot.Blade2Slots; i++)
  380. {
  381. bool bNoWafer = CheckSensorNoWafer(ModuleName.Robot, (int)blade + i);
  382. if (!bNoWafer)
  383. {
  384. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDetectedAfterSend);
  385. return false;
  386. }
  387. }
  388. }
  389. else
  390. {
  391. for (int i = 0; i < robot.Blade2Slots + 1; i++)
  392. {
  393. bool bNoWafer = CheckSensorNoWafer(ModuleName.Robot, (int)Hand.Blade1 + i);
  394. if (!bNoWafer)
  395. {
  396. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDetectedAfterSend);
  397. return false;
  398. }
  399. }
  400. }
  401. return true;
  402. });
  403. if (ret.Item1)
  404. {
  405. if (ret.Item2 == Result.FAIL)
  406. {
  407. error(String.Format("Failed to check wafer information"));
  408. throw (new RoutineFaildException());
  409. }
  410. }
  411. }
  412. }
  413. }