EfemPickAndPlaceRoutine.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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 JetEfemLib.Efems
  15. {
  16. public class EfemPickAndPlaceRoutine : ModuleRoutineBase, IStepRoutine
  17. {
  18. enum RoutineStep
  19. {
  20. CheckBeforePick,
  21. PickWafer,
  22. CheckBeforePlace,
  23. PlaceWafer,
  24. PostTransfer,
  25. PickExtend,
  26. PickRetract,
  27. PlaceExtend,
  28. PlaceRetract,
  29. PickLiftUp,
  30. PickLiftDown,
  31. PlaceLiftUp,
  32. PlaceLiftDown,
  33. End,
  34. }
  35. private EfemModule _robotModule;
  36. private ITransferTarget _target;
  37. private Hand _pickBlade;
  38. private Hand _placeBlade;
  39. private ModuleName _targetModule;
  40. private int _pickSlot;
  41. private int _placeSlot;
  42. private int _pickTimeout;
  43. private int _placeTimeout;
  44. private int _postTransferTimeout;
  45. public EfemPickAndPlaceRoutine(EfemModule robotModule) : base(ModuleName.EfemRobot.ToString())
  46. {
  47. Name = "Pick";
  48. _robotModule = robotModule;
  49. }
  50. public RState Start(params object[] objs)
  51. {
  52. _pickTimeout = SC.GetValue<int>("EFEM.EfemRobot.PickTimeout") * 1000;
  53. _placeTimeout = SC.GetValue<int>("EFEM.EfemRobot.PlaceTimeout");
  54. if (ModuleHelper.IsPm(_targetModule))
  55. {
  56. _postTransferTimeout = SC.GetValue<int>($"PM.PostTransferTimeout");
  57. }
  58. Reset();
  59. if (!WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_pickBlade))
  60. {
  61. EV.PostWarningLog(Module, $"Can not pick by {_pickBlade}, found wafer on");
  62. return RState.Failed;
  63. }
  64. if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_placeBlade))
  65. {
  66. EV.PostWarningLog(Module, $"Can not place by {_placeBlade}, no wafer on");
  67. return RState.Failed;
  68. }
  69. if (_pickSlot != _placeSlot)
  70. {
  71. if (!WaferManager.Instance.CheckHasWafer(_targetModule, _pickSlot))
  72. {
  73. EV.PostWarningLog(Module, $"Can not pick from {_targetModule} slot {_pickSlot + 1}, no wafer on");
  74. return RState.Failed;
  75. }
  76. if (!WaferManager.Instance.CheckNoWafer(_targetModule, _placeSlot))
  77. {
  78. EV.PostWarningLog(Module, $"Can not place to {_targetModule} slot {_placeSlot + 1}, found wafer on");
  79. return RState.Failed;
  80. }
  81. }
  82. else
  83. {
  84. if (!WaferManager.Instance.CheckHasWafer(_targetModule, _placeSlot))
  85. {
  86. {
  87. EV.PostWarningLog(Module, $"Can not pick&place from {_targetModule} slot {_placeSlot + 1}, no wafer on");
  88. return RState.Failed;
  89. }
  90. }
  91. }
  92. Notify($"Start, swap wafer,pick: {_pickBlade} slot {_pickSlot + 1}, place: {_placeBlade} slot {_placeSlot+1}");
  93. return Runner.Start(ModuleName.EfemRobot.ToString(), Name);
  94. }
  95. public void Init(ModuleName targetModule, Hand pickBlade, int pickSlot, Hand placeBlade, int placeSlot)
  96. {
  97. _pickBlade = pickBlade;
  98. _placeBlade = placeBlade;
  99. _targetModule = targetModule;
  100. _pickSlot = pickSlot;
  101. _placeSlot = placeSlot;
  102. //_target = Singleton<EquipmentManager>.Instance.Modules[targetModule] as ITransferTarget;
  103. }
  104. public void Abort()
  105. {
  106. if (_target != null)
  107. {
  108. _target.NoteTransferStop(ModuleName.EfemRobot, Hand.Blade1, 0, EnumTransferType.Pick);
  109. }
  110. _target = null;
  111. Notify("Abort");
  112. }
  113. public RState Monitor()
  114. {
  115. if (ModuleHelper.IsPm(_targetModule))
  116. {
  117. Runner.Wait(RoutineStep.CheckBeforePick, CheckBeforePick)
  118. .Run(RoutineStep.PickExtend, RobotExtendForPick, CheckRobotExtend, _pickTimeout)
  119. .Run(RoutineStep.PickLiftDown, MovePinDown, CheckMovePinDown, _pickTimeout)
  120. .Run(RoutineStep.PickRetract, RobotRetractForPick, CheckRobotRetract, _pickTimeout)
  121. .Run(RoutineStep.PlaceExtend, RobotExtendForPlace, CheckRobotExtend, _pickTimeout)
  122. .Run(RoutineStep.PlaceLiftUp, MovePinUp, CheckMovePinUp, _pickTimeout)
  123. .Run(RoutineStep.PlaceRetract, RobotRetractForPlace, CheckRobotRetract, _pickTimeout)
  124. .Run(RoutineStep.PostTransfer, PostTransfer, CheckPostTransfer, _postTransferTimeout)
  125. .End(RoutineStep.End, NullFun, _delay_50ms);
  126. }
  127. else
  128. {
  129. Runner.Wait(RoutineStep.CheckBeforePick, CheckBeforePick)
  130. .Run(RoutineStep.PickWafer, PickWafer, CheckPickWafer, _pickTimeout)
  131. .Wait(RoutineStep.CheckBeforePlace, CheckBeforePlace)
  132. .Run(RoutineStep.PlaceWafer, PlaceWafer, CheckPlaceWafer, _pickTimeout)
  133. .End(RoutineStep.End, NullFun, _delay_50ms);
  134. }
  135. if (Runner.Status == RState.End)
  136. {
  137. _target.NoteTransferStop(ModuleName.EfemRobot, Hand.Blade1, 0, EnumTransferType.Pick);
  138. Notify($"complete, swap wafer,pick: {_pickBlade} slot {_pickSlot + 1}, place: {_placeBlade} slot {_placeSlot + 1}");
  139. }
  140. return Runner.Status;
  141. }
  142. bool CheckBeforePick()
  143. {
  144. var blade = _pickBlade;
  145. var slot = _pickSlot;
  146. var source = _targetModule;
  147. Notify("Check pick is enabled");
  148. string reason = string.Empty;
  149. if (!_target.CheckReadyForTransfer(ModuleName.EfemRobot, blade, slot, EnumTransferType.Pick, out reason))
  150. {
  151. Stop(reason);
  152. return false;
  153. }
  154. if (blade == Hand.Blade1)
  155. {
  156. if (!WaferManager.Instance.CheckHasWafer(source, slot))
  157. {
  158. Stop("Source no wafer");
  159. return false;
  160. }
  161. if (!WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0))
  162. {
  163. Stop("Blade has wafer");
  164. return false;
  165. }
  166. }
  167. else if (blade == Hand.Blade2)
  168. {
  169. if (!WaferManager.Instance.CheckHasWafer(source, slot))
  170. {
  171. Stop("Source no wafer");
  172. return false;
  173. }
  174. if (!WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1))
  175. {
  176. Stop("Blade has wafer");
  177. return false;
  178. }
  179. }
  180. else
  181. {
  182. for (int i = 0; i < 2; i++)
  183. {
  184. if (!WaferManager.Instance.CheckHasWafer(source, slot + i))
  185. {
  186. Stop("Source no wafer");
  187. return false;
  188. }
  189. if (!WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, i))
  190. {
  191. Stop("Blade has wafer");
  192. return false;
  193. }
  194. }
  195. }
  196. return true;
  197. }
  198. bool RobotExtendForPick()
  199. {
  200. Notify("robot execute goto command");
  201. var chamber = _targetModule;
  202. var slot = _pickSlot;
  203. var hand = _pickBlade;
  204. var robotPostion = RobotPostionEnum.PickExtendLow;
  205. //string reason;
  206. //if (!_robotModule.RobotDevice.GotoRE(chamber, hand, slot, robotPostion, out reason))
  207. //{
  208. // Stop(reason);
  209. // return false;
  210. //}
  211. return true;
  212. }
  213. bool CheckRobotExtend()
  214. {
  215. return !_robotModule.RobotDevice.IsError && _robotModule.RobotDevice.IsIdle;
  216. }
  217. bool MovePinDown()
  218. {
  219. var pm = _target as PMModuleBase;
  220. Notify($"{pm.Name} lift pin down");
  221. //if (!pm.ChamberLiftPin.MoveDown(out string reason))
  222. //{
  223. // Stop(reason);
  224. // return false;
  225. //}
  226. return true;
  227. }
  228. bool CheckMovePinDown()
  229. {
  230. var pm = _target as PMModuleBase;
  231. //if (pm.ChamberLiftPin.IsDown)
  232. // return true;
  233. return false;
  234. }
  235. bool RobotRetractForPick()
  236. {
  237. Notify("robot execute goto command");
  238. var chamber = _targetModule;
  239. var slot = _pickSlot;
  240. var hand = _pickBlade;
  241. var robotPostion = RobotPostionEnum.PickRetracted;
  242. //string reason;
  243. //if (!_robotModule.RobotDevice.GotoRE(chamber, hand, slot, robotPostion, out reason))
  244. //{
  245. // Stop(reason);
  246. // return false;
  247. //}
  248. return true;
  249. }
  250. bool CheckRobotRetract()
  251. {
  252. return !_robotModule.RobotDevice.IsError && _robotModule.RobotDevice.IsIdle;
  253. }
  254. public bool RobotExtendForPlace()
  255. {
  256. Notify("robot execute goto command");
  257. var chamber = _targetModule;
  258. var slot = _placeSlot;
  259. var hand = _placeBlade;
  260. var robotPostion = RobotPostionEnum.PlaceExtendUp;
  261. //string reason;
  262. //if (!_robotModule.RobotDevice.GotoRE(chamber, hand, slot, robotPostion, out reason))
  263. //{
  264. // Stop(reason);
  265. // return false;
  266. //}
  267. return true;
  268. }
  269. bool MovePinUp()
  270. {
  271. var pm = _target as PMModuleBase;
  272. Notify($"{pm.Name} lift pin up ");
  273. //if (!pm.ChamberLiftPin.MoveUp(out string reason))
  274. //{
  275. // Stop(reason);
  276. // return false;
  277. //}
  278. return true;
  279. }
  280. bool CheckMovePinUp()
  281. {
  282. //if (pm.ChamberLiftPin.IsUp)
  283. // return true;
  284. return false;
  285. }
  286. bool RobotRetractForPlace()
  287. {
  288. Notify("robot execute goto command");
  289. var chamber = _targetModule;
  290. var slot = _placeSlot;
  291. var hand = _placeBlade;
  292. var robotPostion = RobotPostionEnum.PlaceRetract;
  293. //string reason;
  294. //if (!_robotModule.RobotDevice.GotoRE(chamber, hand, slot, robotPostion, out reason))
  295. //{
  296. // Stop(reason);
  297. // return false;
  298. //}
  299. return true;
  300. }
  301. bool PostTransfer()
  302. {
  303. var pm = _target as PMModuleBase;
  304. var type = EnumTransferType.Place;
  305. Notify($"{pm.Name} post transfer ");
  306. if (!pm.PostTransfer(ModuleName.EfemRobot, _placeBlade, new int[] { _placeSlot }, type, out string reason))
  307. {
  308. Stop(reason);
  309. return false;
  310. }
  311. return true;
  312. }
  313. bool CheckPostTransfer()
  314. {
  315. var pm = _target as PMModuleBase;
  316. return !pm.IsError && pm.IsReady;
  317. }
  318. bool PickWafer()
  319. {
  320. Notify("robot execute pick command");
  321. var chamber = _targetModule;
  322. var slot = _pickSlot;
  323. var hand = _pickBlade;
  324. _target.NoteTransferStart(ModuleName.EfemRobot, hand, slot, EnumTransferType.Pick);
  325. string reason;
  326. if (!_robotModule.RobotDevice.Pick(chamber, hand, slot, out reason))
  327. {
  328. Stop(reason);
  329. return false;
  330. }
  331. return true;
  332. }
  333. bool CheckPickWafer()
  334. {
  335. return !_robotModule.RobotDevice.IsError && _robotModule.RobotDevice.IsIdle;
  336. }
  337. bool CheckBeforePlace()
  338. {
  339. var source = _targetModule;
  340. var slot = _placeSlot;
  341. var blade = _placeBlade;
  342. Notify("Check place condition");
  343. string reason = string.Empty;
  344. if (!_target.CheckReadyForTransfer(ModuleName.EfemRobot, blade, slot, EnumTransferType.Place, out reason))
  345. {
  346. Stop(reason);
  347. return false;
  348. }
  349. if (blade == Hand.Blade1)
  350. {
  351. if (!WaferManager.Instance.CheckNoWafer(source, slot))
  352. {
  353. Stop("Source has wafer");
  354. return false;
  355. }
  356. if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  357. {
  358. Stop("Blade 1 no wafer");
  359. return false;
  360. }
  361. }
  362. else if (blade == Hand.Blade2)
  363. {
  364. if (!WaferManager.Instance.CheckNoWafer(source, slot))
  365. {
  366. Stop("Source has wafer");
  367. return false;
  368. }
  369. if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1))
  370. {
  371. Stop("Blade no wafer");
  372. return false;
  373. }
  374. }
  375. else
  376. {
  377. for (int i = 0; i < 2; i++)
  378. {
  379. if (!WaferManager.Instance.CheckNoWafer(source, slot + i))
  380. {
  381. Stop("Source has wafer");
  382. return false;
  383. }
  384. if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, i))
  385. {
  386. Stop("Blade no wafer");
  387. return false;
  388. }
  389. }
  390. }
  391. return true;
  392. }
  393. bool PlaceWafer()
  394. {
  395. Notify("robot start execute place command");
  396. string reason;
  397. var chamber = _targetModule;
  398. var slot = _placeSlot;
  399. var hand = _placeBlade;
  400. _target.NoteTransferStart(ModuleName.EfemRobot, hand, slot, EnumTransferType.Place);
  401. if (!_robotModule.RobotDevice.Place(chamber, hand, slot, out reason))
  402. {
  403. Stop(reason);
  404. return false;
  405. }
  406. return true;
  407. }
  408. bool CheckPlaceWafer()
  409. {
  410. return !_robotModule.RobotDevice.IsError && _robotModule.RobotDevice.IsIdle;
  411. }
  412. }
  413. }