TMPlaceRoutine.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. using System;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Device.Unit;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.IOCore;
  6. using Aitex.Core.RT.Routine;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Sorter.Common;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.Schedulers;
  11. using MECF.Framework.Common.SubstrateTrackings;
  12. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  13. using MECF.Framework.RT.EquipmentLibrary.LogicUnits;
  14. using MECF.Framework.RT.ModuleLibrary.PMModules;
  15. using MECF.Framework.RT.ModuleLibrary.SystemModules;
  16. namespace JetMainframe.TMs
  17. {
  18. public class TMPlaceRoutine : ModuleRoutine, IRoutine
  19. {
  20. enum RoutineStep
  21. {
  22. PrepareTransfer,
  23. QuerySourceState,
  24. CheckBeforePlace,
  25. PlaceWafer,
  26. CheckBeforePlace2,
  27. PlaceWafer2,
  28. PlaceDelay,
  29. TransferHandoff,
  30. PlaceRetract,
  31. PostTransfer,
  32. }
  33. private int _timeout;
  34. private ModuleName _source;
  35. private int _sourceSlot;
  36. private Hand _hand;
  37. private bool _autoHand;
  38. private double _TargetTemp1 = 0.0f;
  39. private double _TargetTemp2 = 0.0f;
  40. private bool _enableCheck = false;
  41. private TMModule _robotModule;
  42. private ITransferTarget _target;
  43. private int _postTransferTimeout;
  44. public TMPlaceRoutine(TMModule robotModule)
  45. {
  46. Module = "TM";
  47. Name = "Place";
  48. _robotModule = robotModule;
  49. }
  50. public Result Start(params object[] objs)
  51. {
  52. _timeout = SC.GetValue<int>("TM.TMRobot.PlaceTimeout");
  53. Reset();
  54. if (!DEVICE.GetDevice<IoSensor>($"System.SensorTMInSafety").Value)
  55. {
  56. EV.PostAlarmLog(Module, $"Can not place, Sensor TMInSafety is false");
  57. return Result.FAIL;
  58. }
  59. if (_source == ModuleName.LLA && DEVICE.GetDevice<IoSensor>($"System.SensorBufferABigWaferProtrusion").Value)
  60. {
  61. EV.PostAlarmLog(Module, $"Can not place, Sensor BufferABigWaferProtrusion is false");
  62. return Result.FAIL;
  63. }
  64. if (_source == ModuleName.LLB && DEVICE.GetDevice<IoSensor>($"System.SensorBufferBBigWaferProtrusion").Value)
  65. {
  66. EV.PostAlarmLog(Module, $"Can not place, Sensor BufferBBigWaferProtrusion is false");
  67. return Result.FAIL;
  68. }
  69. if (_autoHand)
  70. {
  71. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0))
  72. {
  73. _hand = Hand.Blade1;
  74. }
  75. else if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1))
  76. {
  77. _hand = Hand.Blade2;
  78. }
  79. else
  80. {
  81. EV.PostWarningLog(Module, $"Can not place, Robot both arm no wafer");
  82. return Result.FAIL;
  83. }
  84. }
  85. if (_hand == Hand.Both)
  86. {
  87. if (!SC.GetValueOrDefault<bool>("TM.TMRobot.LowerBladeEnable"))
  88. {
  89. EV.PostAlarmLog(Module, $"Can not pick, Lower Blade is Disabled");
  90. return Result.FAIL;
  91. }
  92. if (!SC.GetValueOrDefault<bool>("TM.TMRobot.UpperBladeEnable"))
  93. {
  94. EV.PostAlarmLog(Module, $"Can not pick, Upper Blade is Disabled");
  95. return Result.FAIL;
  96. }
  97. if (WaferManager.Instance.GetWafers(_source).Length < 2)
  98. {
  99. EV.PostWarningLog(Module, $"Can not place use both arm, Only one slot at {_source}");
  100. return Result.FAIL;
  101. }
  102. if (!WaferManager.Instance.CheckNoWafer(_source, _sourceSlot))
  103. {
  104. EV.PostWarningLog(Module, $"Can not place, should no wafer at {_source}, {_sourceSlot + 1}");
  105. return Result.FAIL;
  106. }
  107. if (!WaferManager.Instance.CheckNoWafer(_source, _sourceSlot + 1))
  108. {
  109. EV.PostWarningLog(Module, $"Can not place, should no wafer at {_source}, {_sourceSlot + 1 + 1}");
  110. return Result.FAIL;
  111. }
  112. if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)Hand.Blade1))
  113. {
  114. EV.PostWarningLog(Module, $"Can not place, Robot arm 1 no wafer");
  115. return Result.FAIL;
  116. }
  117. if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)Hand.Blade2))
  118. {
  119. EV.PostWarningLog(Module, $"Can not place, Robot arm 2 no wafer");
  120. return Result.FAIL;
  121. }
  122. }
  123. else
  124. {
  125. if (_hand == Hand.Blade1 && !SC.GetValueOrDefault<bool>("TM.TMRobot.LowerBladeEnable"))
  126. {
  127. EV.PostAlarmLog(Module, $"Can not pick, Lower Blade is Disabled");
  128. return Result.FAIL;
  129. }
  130. if (_hand == Hand.Blade2 && !SC.GetValueOrDefault<bool>("TM.TMRobot.UpperBladeEnable"))
  131. {
  132. EV.PostAlarmLog(Module, $"Can not pick, Upper Blade is Disabled");
  133. return Result.FAIL;
  134. }
  135. if (!WaferManager.Instance.CheckNoWafer(_source, _sourceSlot))
  136. {
  137. EV.PostWarningLog(Module, $"Can not place, should no wafer at {_source}, {_sourceSlot + 1}");
  138. return Result.FAIL;
  139. }
  140. if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand))
  141. {
  142. EV.PostWarningLog(Module, $"Can not place, Robot arm {(int)_hand + 1} no wafer");
  143. return Result.FAIL;
  144. }
  145. }
  146. Notify($"Start, Place to {_source} slot {_sourceSlot + 1}, by {_hand}");
  147. return Result.RUN;
  148. }
  149. //public Result Start(params object[] objs)
  150. //{
  151. // return Start((ModuleName)objs[0], (int)objs[1], (Hand)objs[2]);
  152. //}
  153. public void Init(ModuleName source, int slot, Hand hand, double temp1, double temp2, bool enableCheckTemp=true)
  154. {
  155. _autoHand = false;
  156. _TargetTemp1 = temp1;
  157. _TargetTemp2 = temp2;
  158. _enableCheck = enableCheckTemp;
  159. _source = source;
  160. _sourceSlot = slot;
  161. _hand = hand;
  162. _target = EquipmentManager.Modules[source] as ITransferTarget;
  163. if (ModuleHelper.IsPm(source))
  164. _postTransferTimeout = SC.GetValue<int>($"{source}.PostTransferTimeout");
  165. }
  166. public void Init(ModuleName source, int slot, double temp1, double temp2, bool enableCheckTemp = true)
  167. {
  168. _autoHand = true;
  169. _TargetTemp1 = temp1;
  170. _TargetTemp2 = temp2;
  171. _enableCheck = enableCheckTemp;
  172. _source = source;
  173. _sourceSlot = slot;
  174. _target = EquipmentManager.Modules[source] as ITransferTarget;
  175. if (ModuleHelper.IsPm(source))
  176. _postTransferTimeout = SC.GetValue<int>($"{source}.PostTransferTimeout");
  177. }
  178. public void Abort()
  179. {
  180. if (_target != null)
  181. {
  182. _target.NoteTransferStop(ModuleName.TMRobot, Hand.Blade1, 0, EnumTransferType.Place);
  183. }
  184. _target = null;
  185. Notify("Abort");
  186. }
  187. public Result Monitor()
  188. {
  189. try
  190. {
  191. if (ModuleHelper.IsPm(_source))
  192. {
  193. PrepareTransfer((int)RoutineStep.PrepareTransfer, _target as PMModuleBase, _hand, _sourceSlot, EnumTransferType.Place, _postTransferTimeout, _TargetTemp1, _TargetTemp2, _enableCheck);
  194. }
  195. CheckBeforePlace((int)RoutineStep.CheckBeforePlace, _source, _sourceSlot, _hand, _postTransferTimeout);
  196. PlaceWafer((int)RoutineStep.PlaceWafer, _source, _sourceSlot, _hand, _timeout);
  197. if (ModuleHelper.IsPm(_source))
  198. {
  199. TransferHandoff((int)RoutineStep.TransferHandoff, _target as PMModuleBase, _hand, _sourceSlot, EnumTransferType.Place, _postTransferTimeout);
  200. PlaceRetract((int)RoutineStep.PlaceRetract, _source, _sourceSlot, _hand, _timeout);
  201. PostTransfer((int)RoutineStep.PostTransfer, _target as PMModuleBase, _hand, _sourceSlot, EnumTransferType.Place, _postTransferTimeout);
  202. }
  203. }
  204. catch (RoutineBreakException)
  205. {
  206. return Result.RUN;
  207. }
  208. catch (RoutineFaildException)
  209. {
  210. return Result.FAIL;
  211. }
  212. _target.NoteTransferStop(ModuleName.TMRobot, Hand.Blade1, 0, EnumTransferType.Place);
  213. //WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _source, _sourceSlot);
  214. Notify($"Finish, Place to {_source} slot {_sourceSlot + 1}, by {_hand}");
  215. return Result.DONE;
  216. }
  217. public void PrepareTransfer(int id, PMModuleBase pm, Hand hand, int slot, EnumTransferType type, int timeout, double temp1, double temp2, bool enableCheckTemp = true)
  218. {
  219. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  220. {
  221. Notify($"{pm.Name}{slot + 1} prepare transfer ");
  222. if (!pm.PrepareTransfer(ModuleName.TMRobot, hand, slot, type, temp1, temp2, enableCheckTemp, out string reason))
  223. {
  224. Stop(reason);
  225. return false;
  226. }
  227. return true;
  228. }, () =>
  229. {
  230. if (pm.IsError)
  231. {
  232. return null;
  233. }
  234. return pm.IsReady;
  235. }, timeout * 1000);
  236. if (ret.Item1)
  237. {
  238. if (ret.Item2 == Result.FAIL)
  239. {
  240. Stop($"{pm.Name}{slot} error");
  241. throw new RoutineFaildException();
  242. }
  243. else if (ret.Item2 == Result.TIMEOUT) //timeout
  244. {
  245. Stop($"{pm.Name}{slot} prepare transfer timeout, over {timeout} seconds");
  246. throw new RoutineFaildException();
  247. }
  248. else
  249. throw new RoutineBreakException();
  250. }
  251. }
  252. public void CheckBeforePlace(int id, ModuleName source, int slot, Hand blade, int timeout)
  253. {
  254. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  255. {
  256. Notify("Check place condition");
  257. string reason = string.Empty;
  258. if (blade == Hand.Blade1)
  259. {
  260. if (!WaferManager.Instance.CheckNoWafer(source, slot))
  261. {
  262. Stop("Source has wafer");
  263. return false;
  264. }
  265. if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)blade))
  266. {
  267. Stop("Blade no wafer");
  268. return false;
  269. }
  270. }
  271. else if (blade == Hand.Blade2)
  272. {
  273. if (!WaferManager.Instance.CheckNoWafer(source, slot))
  274. {
  275. Stop("Source has wafer");
  276. return false;
  277. }
  278. if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)blade))
  279. {
  280. Stop("Blade no wafer");
  281. return false;
  282. }
  283. }
  284. else
  285. {
  286. for (int i = 0; i < 2; i++)
  287. {
  288. if (!WaferManager.Instance.CheckNoWafer(source, slot + i))
  289. {
  290. Stop("Source has wafer");
  291. return false;
  292. }
  293. if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, i))
  294. {
  295. Stop("Blade no wafer");
  296. return false;
  297. }
  298. }
  299. }
  300. return true;
  301. }, () =>
  302. {
  303. if (_robotModule.RobotDevice.IsError)
  304. return null;
  305. if (_target.CheckReadyForTransfer(ModuleName.TMRobot, _hand, _sourceSlot, EnumTransferType.Place, out _))
  306. {
  307. return true;
  308. }
  309. return false;
  310. }, timeout * 1000);
  311. if (ret.Item1)
  312. {
  313. if (ret.Item2 == Result.FAIL)
  314. {
  315. throw (new RoutineFaildException());
  316. }
  317. else if (ret.Item2 == Result.TIMEOUT) //timeout
  318. {
  319. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  320. throw (new RoutineFaildException());
  321. }
  322. else
  323. throw (new RoutineBreakException());
  324. }
  325. }
  326. public void PlaceWafer(int id, ModuleName chamber, int slot, Hand hand, int timeout)
  327. {
  328. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  329. {
  330. Notify("robot start execute place command");
  331. //string reason;
  332. _target.NoteTransferStart(ModuleName.TMRobot, hand, slot, EnumTransferType.Place);
  333. if (!_robotModule.RobotDevice.Place((RobotArmEnum)(int)hand, chamber.ToString(), slot))
  334. {
  335. return false;
  336. }
  337. return true;
  338. }, () =>
  339. {
  340. if (_robotModule.RobotDevice.IsError)
  341. return null;
  342. if (_robotModule.RobotDevice.IsIdle)
  343. return true;
  344. return false;
  345. }, timeout * 1000);
  346. if (ret.Item1)
  347. {
  348. if (ret.Item2 == Result.FAIL)
  349. {
  350. throw (new RoutineFaildException());
  351. }
  352. else if (ret.Item2 == Result.TIMEOUT) //timeout
  353. {
  354. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  355. throw (new RoutineFaildException());
  356. }
  357. else
  358. throw (new RoutineBreakException());
  359. }
  360. }
  361. public void PlaceRetract(int id, ModuleName chamber, int slot, Hand hand, int timeout)
  362. {
  363. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  364. {
  365. Notify("robot execute place retract command");
  366. _target.NoteTransferStart(ModuleName.TMRobot, hand, slot, EnumTransferType.Pick);
  367. if (!_robotModule.RobotDevice.PlaceRetract((RobotArmEnum)(int)hand, chamber.ToString(), slot))
  368. {
  369. return false;
  370. }
  371. return true;
  372. }, () =>
  373. {
  374. if (_robotModule.RobotDevice.IsError)
  375. return null;
  376. if (_robotModule.RobotDevice.IsIdle)
  377. return true;
  378. return false;
  379. }, timeout * 1000);
  380. if (ret.Item1)
  381. {
  382. if (ret.Item2 == Result.FAIL)
  383. {
  384. Stop(string.Format("failed."));
  385. throw new RoutineFaildException();
  386. }
  387. else if (ret.Item2 == Result.TIMEOUT) //timeout
  388. {
  389. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  390. throw new RoutineFaildException();
  391. }
  392. else
  393. throw new RoutineBreakException();
  394. }
  395. }
  396. public void TransferHandoff(int id, PMModuleBase pm, Hand hand, int slot, EnumTransferType type, int timeout)
  397. {
  398. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  399. {
  400. Notify($"{pm.Name}{slot} transfer handoff");
  401. if (!pm.TransferHandoff(ModuleName.TMRobot, hand, slot, type, out string reason))
  402. {
  403. Stop(reason);
  404. return false;
  405. }
  406. return true;
  407. }, () =>
  408. {
  409. if (pm.IsError)
  410. {
  411. return null;
  412. }
  413. return pm.IsReady;
  414. }, timeout * 1000);
  415. if (ret.Item1)
  416. {
  417. if (ret.Item2 == Result.FAIL)
  418. {
  419. Stop($"{pm.Name}{slot} error");
  420. throw new RoutineFaildException();
  421. }
  422. else if (ret.Item2 == Result.TIMEOUT) //timeout
  423. {
  424. Stop($"{pm.Name}{slot} transfer handoff timeout, over {timeout} seconds");
  425. throw new RoutineFaildException();
  426. }
  427. else
  428. throw new RoutineBreakException();
  429. }
  430. }
  431. public void PostTransfer(int id, PMModuleBase pm, Hand hand, int slot, EnumTransferType type, int timeout)
  432. {
  433. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  434. {
  435. Notify($"{pm.Name} post transfer ");
  436. if (!pm.PostTransfer(ModuleName.TMRobot, hand, slot, type, out string reason))
  437. {
  438. Stop(reason);
  439. return false;
  440. }
  441. return true;
  442. }, () =>
  443. {
  444. if (pm.IsError)
  445. {
  446. return null;
  447. }
  448. return pm.IsReady;
  449. }, timeout * 1000);
  450. if (ret.Item1)
  451. {
  452. if (ret.Item2 == Result.FAIL)
  453. {
  454. Stop($"{pm.Name} error");
  455. throw (new RoutineFaildException());
  456. }
  457. else if (ret.Item2 == Result.TIMEOUT) //timeout
  458. {
  459. Stop($"{pm.Name} post transfer timeout, over {timeout} seconds");
  460. throw (new RoutineFaildException());
  461. }
  462. else
  463. throw (new RoutineBreakException());
  464. }
  465. }
  466. }
  467. }