EfemPlaceRoutine.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. using System;
  2. using Aitex.Core.Common;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Routine;
  5. using Aitex.Core.RT.SCCore;
  6. using Aitex.Core.Util;
  7. using Aitex.Sorter.Common;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.Routine;
  10. using MECF.Framework.Common.Schedulers;
  11. using MECF.Framework.Common.SubstrateTrackings;
  12. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.PMs;
  13. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  14. using MECF.Framework.RT.EquipmentLibrary.LogicUnits;
  15. using MECF.Framework.RT.ModuleLibrary.AlignerModules;
  16. using MECF.Framework.RT.ModuleLibrary.PMModules;
  17. using MECF.Framework.RT.ModuleLibrary.SystemModules;
  18. namespace JetEfemLib.Efems
  19. {
  20. public class EfemPlaceRoutine : ModuleRoutineBase, IStepRoutine
  21. {
  22. enum RoutineStep
  23. {
  24. QuerySourceState,
  25. CheckBeforePlace,
  26. PlaceWafer,
  27. CheckBeforePlace2,
  28. PlaceWafer2,
  29. PlaceDelay,
  30. PostTransfer,
  31. PrepareTransfer,
  32. PlaceRetract,
  33. PlaceExtend,
  34. LiftUp,
  35. DelayBeforeLiftDown,
  36. LiftDown,
  37. DelayAfterLiftDown,
  38. End,
  39. }
  40. private int _delayTimeBeforeAlignerLiftDown;
  41. private int _delayTimeBeforeCoolingLiftDown;
  42. private int _timeout;
  43. private ModuleName _source;
  44. private int _sourceSlot;
  45. private Hand _hand;
  46. private bool _autoHand;
  47. private EfemModule _robotModule;
  48. private ITransferTarget _target;
  49. private int _postTransferTimeout;
  50. private WaferSize _waferSize = WaferSize.WS0;
  51. public EfemPlaceRoutine(EfemModule robotModule) : base(ModuleName.EFEM.ToString())
  52. {
  53. Name = "Place";
  54. _robotModule = robotModule;
  55. }
  56. public RState Start(params object[] objs)
  57. {
  58. if (!_robotModule.EfemDevice.IsInitialized)
  59. {
  60. EV.PostAlarmLog(Module, $"EFEM robot is not homed, please home it first");
  61. return RState.Failed;
  62. }
  63. _timeout = SC.GetValue<int>("EFEM.EfemRobot.PlaceTimeout");
  64. _delayTimeBeforeAlignerLiftDown= SC.GetValue<int>("EFEM.DelayTimeBeforeAlignerLiftDown");
  65. _delayTimeBeforeCoolingLiftDown= SC.GetValue<int>("EFEM.DelayTimeBeforeCoolingLiftDown");
  66. Reset();
  67. if (_autoHand)
  68. {
  69. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  70. {
  71. _hand = Hand.Blade1;
  72. }
  73. else if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1))
  74. {
  75. _hand = Hand.Blade2;
  76. }
  77. else
  78. {
  79. EV.PostWarningLog(Module, $"Can not place, Robot both arm no wafer");
  80. return RState.Failed;
  81. }
  82. }
  83. if (_hand == Hand.Both)
  84. {
  85. if (!SC.GetValueOrDefault<bool>("EFEM.EfemRobot.LowerBladeEnable"))
  86. {
  87. EV.PostAlarmLog(Module, $"Can not pick, Lower Blade is Disabled");
  88. return RState.Failed;
  89. }
  90. if (!SC.GetValueOrDefault<bool>("EFEM.EfemRobot.UpperBladeEnable"))
  91. {
  92. EV.PostAlarmLog(Module, $"Can not pick, Upper Blade is Disabled");
  93. return RState.Failed;
  94. }
  95. if (WaferManager.Instance.GetWafers(_source).Length < 2)
  96. {
  97. EV.PostWarningLog(Module, $"Can not place use both arm, Only one slot at {_source}");
  98. return RState.Failed;
  99. }
  100. if (!WaferManager.Instance.CheckNoWafer(_source, _sourceSlot))
  101. {
  102. EV.PostWarningLog(Module, $"Can not place, should no wafer at {_source}, {_sourceSlot + 1}");
  103. return RState.Failed;
  104. }
  105. if (!WaferManager.Instance.CheckNoWafer(_source, _sourceSlot + 1))
  106. {
  107. EV.PostWarningLog(Module, $"Can not place, should no wafer at {_source}, {_sourceSlot + 1 + 1}");
  108. return RState.Failed;
  109. }
  110. if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)Hand.Blade1))
  111. {
  112. EV.PostWarningLog(Module, $"Can not place, Robot arm 1 no wafer");
  113. return RState.Failed;
  114. }
  115. if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)Hand.Blade2))
  116. {
  117. EV.PostWarningLog(Module, $"Can not place, Robot arm 2 no wafer");
  118. return RState.Failed;
  119. }
  120. }
  121. else
  122. {
  123. if (_hand == Hand.Blade1 && !SC.GetValueOrDefault<bool>("EFEM.EfemRobot.LowerBladeEnable"))
  124. {
  125. EV.PostAlarmLog(Module, $"Can not pick, Lower Blade is Disabled");
  126. return RState.Failed;
  127. }
  128. if (_hand == Hand.Blade2 && !SC.GetValueOrDefault<bool>("EFEM.EfemRobot.UpperBladeEnable"))
  129. {
  130. EV.PostAlarmLog(Module, $"Can not pick, Upper Blade is Disabled");
  131. return RState.Failed;
  132. }
  133. if (!WaferManager.Instance.CheckNoWafer(_source, _sourceSlot))
  134. {
  135. EV.PostWarningLog(Module, $"Can not place, should no wafer at {_source}, {_sourceSlot + 1}");
  136. return RState.Failed;
  137. }
  138. if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand))
  139. {
  140. EV.PostWarningLog(Module, $"Can not place, Robot arm {(int)_hand + 1} no wafer");
  141. return RState.Failed;
  142. }
  143. }
  144. if (ModuleHelper.IsLoadPort(_source))
  145. {
  146. if (WaferManager.Instance.GetWafer(ModuleName.EfemRobot, (int)_hand).Size != CarrierManager.Instance.GetCarrier(_source).CarrierWaferSize)
  147. {
  148. EV.PostWarningLog(Module, $"Can not place, Carrier Size and Wafer Size not matched");
  149. return RState.Failed;
  150. }
  151. }
  152. _waferSize = WaferManager.Instance.GetWafer(_source, _sourceSlot).Size;
  153. Notify($"Start, Place to {_source} slot {_sourceSlot + 1}, by {_hand}");
  154. return Runner.Start(ModuleName.EFEM.ToString(), Name);
  155. }
  156. //public Result Start(params object[] objs)
  157. //{
  158. // return Start((ModuleName)objs[0], (int)objs[1], (Hand)objs[2]);
  159. //}
  160. public void Init(ModuleName source, int slot, Hand hand)
  161. {
  162. _autoHand = false;
  163. _source = source;
  164. _sourceSlot = slot;
  165. _hand = hand;
  166. _target = EquipmentManager.Modules[source] as ITransferTarget;
  167. if (ModuleHelper.IsPm(source))
  168. _postTransferTimeout = SC.GetValue<int>($"PM.PostTransferTimeout");
  169. }
  170. public void Init(ModuleName source, int slot)
  171. {
  172. _autoHand = true;
  173. _source = source;
  174. _sourceSlot = slot;
  175. _target = EquipmentManager.Modules[source] as ITransferTarget;
  176. if (ModuleHelper.IsPm(source))
  177. _postTransferTimeout = SC.GetValue<int>($"PM.PostTransferTimeout");
  178. }
  179. public void Abort()
  180. {
  181. if (_target != null)
  182. {
  183. _target.NoteTransferStop(ModuleName.EfemRobot, Hand.Blade1, 0, EnumTransferType.Place);
  184. }
  185. _target = null;
  186. Notify("Abort");
  187. }
  188. public RState Monitor()
  189. {
  190. var delayBeforeLiftDownTime = ModuleHelper.IsAligner(_source) ? _delayTimeBeforeAlignerLiftDown : ModuleHelper.IsCooling(_source) ? _delayTimeBeforeCoolingLiftDown : 0;
  191. var delayAfterLiftDownTime = (ModuleHelper.IsCooling(_source) || ModuleHelper.IsAligner(_source)) ? _delay_1s : 0;
  192. if (_hand == Hand.Both)
  193. {
  194. Runner.Run(RoutineStep.PrepareTransfer, PrepareTransfer, CheckPrepareTransfer, _postTransferTimeout * 1000)
  195. .Wait(RoutineStep.CheckBeforePlace, HOFs.Apply(CheckBeforePlace, _source, _sourceSlot, Hand.Blade1))
  196. .Run(RoutineStep.PlaceWafer, HOFs.Apply(PlaceWafer, _source, _sourceSlot, Hand.Blade1), CheckPlaceWafer, _timeout * 1000)
  197. .Wait(RoutineStep.CheckBeforePlace2, HOFs.Apply(CheckBeforePlace, _source, _sourceSlot + 1, Hand.Blade2))
  198. .Run(RoutineStep.PlaceWafer2, HOFs.Apply(PlaceWafer, _source, _sourceSlot + 1, Hand.Blade2), CheckPlaceWafer, _timeout * 1000)
  199. .Run(RoutineStep.PostTransfer, PostTransfer, CheckPostTransfer, _postTransferTimeout * 1000)
  200. .Run(RoutineStep.DelayBeforeLiftDown, NullFun, delayBeforeLiftDownTime * 1000)
  201. .Run(RoutineStep.LiftDown, MovePinDown, CheckMovePinDown, _timeout * 1000)
  202. .Run(RoutineStep.DelayAfterLiftDown, NullFun, delayAfterLiftDownTime)
  203. .End(RoutineStep.End, NullFun, _delay_0s);
  204. }
  205. else
  206. {
  207. Runner.Run(RoutineStep.PrepareTransfer, PrepareTransfer, CheckPrepareTransfer, _postTransferTimeout * 1000)
  208. .Wait(RoutineStep.CheckBeforePlace, HOFs.Apply(CheckBeforePlace, _source, _sourceSlot, _hand))
  209. .Run(RoutineStep.PlaceWafer, HOFs.Apply(PlaceWafer, _source, _sourceSlot, _hand), CheckPlaceWafer, _timeout * 1000)
  210. .Run(RoutineStep.PostTransfer, PostTransfer, CheckPostTransfer, _postTransferTimeout * 1000)
  211. .Run(RoutineStep.DelayBeforeLiftDown, NullFun, delayBeforeLiftDownTime * 1000)
  212. .Run(RoutineStep.LiftDown, MovePinDown, CheckMovePinDown, _timeout * 1000)
  213. .Run(RoutineStep.DelayAfterLiftDown, NullFun, delayAfterLiftDownTime)
  214. .End(RoutineStep.End, NullFun, _delay_0s);
  215. }
  216. if (Runner.Status == RState.End)
  217. {
  218. _target.NoteTransferStop(ModuleName.EfemRobot, Hand.Blade1, 0, EnumTransferType.Place);
  219. Notify($"Finish, Place to {_source} slot {_sourceSlot + 1}, by {_hand}");
  220. }
  221. return Runner.Status;
  222. }
  223. bool PrepareTransfer()
  224. {
  225. if(ModuleHelper.IsPm(_source) && !_target.CheckReadyForTransfer(ModuleName.EfemRobot, _hand, _sourceSlot, EnumTransferType.Place, out _))
  226. {
  227. var pm = _target as PMModuleBase;
  228. var type = EnumTransferType.Place;
  229. Notify($"{pm.Name} Prepare transfer ");
  230. if (!pm.PrepareTransfer(ModuleName.EfemRobot, _hand, new int[] { _sourceSlot }, type, 0, 0, false, out string reason))
  231. {
  232. Stop(reason);
  233. return false;
  234. }
  235. return true;
  236. }
  237. return true;
  238. }
  239. bool CheckPrepareTransfer()
  240. {
  241. if (ModuleHelper.IsPm(_source) && !_target.CheckReadyForTransfer(ModuleName.EfemRobot, _hand, _sourceSlot, EnumTransferType.Place, out _))
  242. {
  243. var pm = _target as PMModuleBase;
  244. return !pm.IsError && pm.IsReady && pm.IsPrepareTransferReady(EnumTransferType.Place, (EnumDualPM)(_sourceSlot + 1), _waferSize);
  245. }
  246. return true;
  247. }
  248. bool CheckBeforePlace(ModuleName source, int slot, Hand blade)
  249. {
  250. Notify("Check place condition");
  251. string reason = string.Empty;
  252. if (!_target.CheckReadyForTransfer(ModuleName.EfemRobot, _hand, _sourceSlot, EnumTransferType.Place, out reason))
  253. {
  254. Stop(reason);
  255. return false;
  256. }
  257. if (blade == Hand.Blade1)
  258. {
  259. if (!WaferManager.Instance.CheckNoWafer(source, slot))
  260. {
  261. Stop("Source has wafer");
  262. return false;
  263. }
  264. if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  265. {
  266. Stop("Blade 1 no wafer");
  267. return false;
  268. }
  269. }
  270. else if (blade == Hand.Blade2)
  271. {
  272. if (!WaferManager.Instance.CheckNoWafer(source, slot))
  273. {
  274. Stop("Source has wafer");
  275. return false;
  276. }
  277. if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1))
  278. {
  279. Stop("Blade no wafer");
  280. return false;
  281. }
  282. }
  283. else
  284. {
  285. for (int i = 0; i < 2; i++)
  286. {
  287. if (!WaferManager.Instance.CheckNoWafer(source, slot + i))
  288. {
  289. Stop("Source has wafer");
  290. return false;
  291. }
  292. if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, i))
  293. {
  294. Stop("Blade no wafer");
  295. return false;
  296. }
  297. }
  298. }
  299. return true;
  300. }
  301. bool PlaceWafer(ModuleName chamber, int slot, Hand hand)
  302. {
  303. Notify("robot start execute place command");
  304. string reason;
  305. _target.NoteTransferStart(ModuleName.EfemRobot, Hand.Blade1, 0, EnumTransferType.Place);
  306. if (!_robotModule.RobotDevice.Place(chamber, hand, slot, out reason))
  307. {
  308. Stop(reason);
  309. return false;
  310. }
  311. return true;
  312. }
  313. bool CheckPlaceWafer()
  314. {
  315. return !_robotModule.RobotDevice.IsError && _robotModule.RobotDevice.IsIdle;
  316. }
  317. bool PostTransfer()
  318. {
  319. if(ModuleHelper.IsPm(_source))
  320. {
  321. var pm = _target as PMModuleBase;
  322. var type = EnumTransferType.Place;
  323. Notify($"{pm.Name} post transfer ");
  324. if (!pm.PostTransfer(ModuleName.EfemRobot, Hand.Blade1, new int[] { 0 }, type, out string reason))
  325. {
  326. Stop(reason);
  327. return false;
  328. }
  329. return true;
  330. }
  331. return true;
  332. }
  333. bool CheckPostTransfer()
  334. {
  335. if (ModuleHelper.IsPm(_source))
  336. {
  337. var pm = _target as PMModuleBase;
  338. return !pm.IsError && pm.IsReady;
  339. }
  340. return true;
  341. }
  342. bool MovePinDown()
  343. {
  344. if(ModuleHelper.IsCooling(_source) || ModuleHelper.IsAligner(_source))
  345. {
  346. AlignerModuleBase aligner = _target as AlignerModuleBase;
  347. Notify($"{aligner.Name} lift pin down");
  348. return aligner.Lift(false);
  349. }
  350. return true;
  351. }
  352. bool CheckMovePinDown()
  353. {
  354. if (ModuleHelper.IsCooling(_source) || ModuleHelper.IsAligner(_source))
  355. {
  356. var aligner = _target as AlignerModuleBase;
  357. return aligner.IsReady;
  358. }
  359. return true;
  360. }
  361. }
  362. }