ManualTransfer.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. using System.Collections.Generic;
  2. using Aitex.Core.Common;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.Util;
  5. using Aitex.Core.RT.Event;
  6. using MECF.Framework.Common.Equipment;
  7. using VirgoRT.Scheduler;
  8. using Aitex.Sorter.Common;
  9. using MECF.Framework.Common.Schedulers;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using VirgoRT.Modules.PMs;
  12. using VirgoRT.Modules.Schedulers;
  13. using Aitex.Core.RT.SCCore;
  14. namespace VirgoRT.Modules
  15. {
  16. internal interface IManualTransferRoutine : IRoutine
  17. {
  18. }
  19. public class MoveItemEx : MoveItem
  20. {
  21. public int CoolingTime { get; set; }
  22. public MoveItemEx(ModuleName sourceModule, int sourceSlot, ModuleName destinationModule, int destinationSlot, int coolingTime, Hand blade)
  23. : base(sourceModule, sourceSlot, destinationModule, destinationSlot, blade)
  24. {
  25. CoolingTime = coolingTime;
  26. }
  27. }
  28. public class ManualTransfer : TransferModule
  29. {
  30. private Queue<IRoutine> _moveTaskQueue = new Queue<IRoutine>();
  31. private IRoutine _activeTask;
  32. public Result Start(object[] objs)
  33. {
  34. _moveTaskQueue.Clear();
  35. ModuleName source = (ModuleName)objs[0];
  36. int ss = (int)objs[1];
  37. ModuleName target = (ModuleName)objs[2];
  38. int ds = (int)objs[3];
  39. bool autoAlign = (bool)objs[4];
  40. int alignAngle = (int)objs[5];
  41. bool autoCooling = (bool)objs[6];
  42. int coolingTime = (int)objs[7];
  43. if (!WaferManager.Instance.CheckWafer(source, ss, WaferStatus.Normal))
  44. {
  45. EV.PostWarningLog("System", $"source {source} slot {ss + 1} no normal wafer");
  46. return Result.FAIL;
  47. }
  48. if (!WaferManager.Instance.CheckNoWafer(target, ds))
  49. {
  50. EV.PostWarningLog("System", "destination has wafer");
  51. return Result.FAIL;
  52. }
  53. if (source != ModuleName.EfemRobot && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1))
  54. {
  55. EV.PostWarningLog("System", "robot has wafer");
  56. return Result.FAIL;
  57. }
  58. Hand blade = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) ? Hand.Blade1 : Hand.Blade2;
  59. if (source == ModuleName.EfemRobot)
  60. blade = ss == 0 ? Hand.Blade1 : Hand.Blade2;
  61. else if (target == ModuleName.EfemRobot)
  62. blade = ds == 0 ? Hand.Blade1 : Hand.Blade2;
  63. if (autoAlign && !ModuleHelper.IsAligner(source) && !ModuleHelper.IsAligner(target))
  64. {
  65. if (WaferManager.Instance.CheckHasWafer(ModuleName.Aligner1, 0) && WaferManager.Instance.CheckHasWafer(ModuleName.Aligner2, 0))
  66. {
  67. EV.PostWarningLog("System", "Can not transfer, aligner has wafer, can not auto align");
  68. return Result.FAIL;
  69. }
  70. ModuleName aligner = WaferManager.Instance.CheckHasWafer(ModuleName.Aligner1, 0)
  71. ? ModuleName.Aligner2
  72. : ModuleName.Aligner1;
  73. _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(source, ss, aligner, 0, 1, blade)));
  74. _moveTaskQueue.Enqueue(new AlignRoutine(aligner.ToString()));
  75. _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(aligner, 0, target, ds, 0, blade)));
  76. }
  77. else if (autoCooling && !ModuleHelper.IsCooling(source) && !ModuleHelper.IsCooling(target))
  78. {
  79. if (WaferManager.Instance.CheckHasWafer(ModuleName.Cooling1, 0) && WaferManager.Instance.CheckHasWafer(ModuleName.Cooling2, 0))
  80. {
  81. EV.PostWarningLog("System", "Can not transfer, cooling has wafer, can not auto cooling");
  82. return Result.FAIL;
  83. }
  84. ModuleName cooling = WaferManager.Instance.CheckHasWafer(ModuleName.Cooling1, 0)
  85. ? ModuleName.Cooling2
  86. : ModuleName.Cooling1;
  87. _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(source, ss, cooling, 0, coolingTime, blade)));
  88. _moveTaskQueue.Enqueue(new CoolingRoutine(cooling.ToString(), coolingTime));
  89. _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(cooling, 0, target, ds, 0, blade)));
  90. }
  91. else
  92. {
  93. _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(source, ss, target, ds, coolingTime, blade)));
  94. if (ModuleHelper.IsAligner(target) || ModuleHelper.IsCooling(target))
  95. {
  96. _moveTaskQueue.Enqueue(new AlignRoutine(target.ToString()));
  97. }
  98. }
  99. _activeTask = _moveTaskQueue.Dequeue();
  100. return _activeTask.Start();
  101. }
  102. public Result Monitor(object[] objs)
  103. {
  104. System.Diagnostics.Debug.Assert(_activeTask != null, "mover should not be null, call start first");
  105. Result ret = _activeTask.Monitor();
  106. if (ret == Result.FAIL)
  107. return ret;
  108. if (ret == Result.DONE)
  109. {
  110. if (_moveTaskQueue.Count > 0)
  111. {
  112. _activeTask = _moveTaskQueue.Dequeue();
  113. return _activeTask.Start();
  114. }
  115. return Result.DONE;
  116. }
  117. return Result.RUN;
  118. }
  119. public void Clear()
  120. {
  121. _moveTaskQueue.Clear();
  122. _activeTask = null;
  123. }
  124. }
  125. public class EfemRobotMover : TransferModule, IRoutine
  126. {
  127. private MoveItemEx _moveTask;
  128. private SchedulerModule _source;
  129. private SchedulerModule _destination;
  130. public EfemRobotMover(MoveItemEx moveTask)
  131. {
  132. _moveTask = moveTask;
  133. }
  134. public Result Start()
  135. {
  136. _source = GetModule(_moveTask.SourceModule.ToString());
  137. _destination = GetModule(_moveTask.DestinationModule.ToString());
  138. System.Diagnostics.Debug.Assert(_source != null, $"{_moveTask.SourceModule} not valid");
  139. System.Diagnostics.Debug.Assert(_destination != null, $"{_moveTask.DestinationModule} not valid");
  140. if (!WaferManager.Instance.CheckHasWafer(_moveTask.SourceModule, _moveTask.SourceSlot))
  141. {
  142. EV.PostWarningLog("System", $"Failed transfer, source {_moveTask.SourceModule} slot {_moveTask.SourceSlot + 1} has not wafer");
  143. return Result.FAIL;
  144. }
  145. if (WaferManager.Instance.CheckHasWafer(_moveTask.DestinationModule, _moveTask.DestinationSlot))
  146. {
  147. EV.PostWarningLog("System", $"Failed transfer, destination {_moveTask.DestinationModule} slot {_moveTask.DestinationSlot + 1} has wafer");
  148. return Result.FAIL;
  149. }
  150. if (!_source.IsAvailable)
  151. {
  152. EV.PostWarningLog("System", $"Failed transfer, source {_moveTask.SourceModule} not ready");
  153. return Result.FAIL;
  154. }
  155. if (ModuleHelper.IsLoadPort(_source.Module))
  156. {
  157. if (!(_source as SchedulerLoadPort).CheckReadyTransfer())
  158. {
  159. EV.PostWarningLog("System", $"Failed transfer, source {_moveTask.SourceModule} not ready");
  160. return Result.FAIL;
  161. }
  162. }
  163. if (!_destination.IsAvailable)
  164. {
  165. EV.PostWarningLog("System", $"Failed transfer, Destination {_moveTask.DestinationModule} not ready");
  166. return Result.FAIL;
  167. }
  168. if (ModuleHelper.IsLoadPort(_destination.Module))
  169. {
  170. if (!(_destination as SchedulerLoadPort).CheckReadyTransfer())
  171. {
  172. EV.PostWarningLog("System", $"Failed transfer, source {_moveTask.DestinationModule} not ready");
  173. return Result.FAIL;
  174. }
  175. }
  176. if (!_efemRobot.IsAvailable)
  177. {
  178. EV.PostWarningLog("System", $"Failed transfer, EFEM Robot not ready");
  179. return Result.FAIL;
  180. }
  181. //if (ModuleHelper.IsAligner(_source.Module) || ModuleHelper.IsCooling(_source.Module))
  182. // _source.Cooling(_moveTask.CoolingTime);
  183. //if (ModuleHelper.IsAligner(_destination.Module) || ModuleHelper.IsCooling(_destination.Module))
  184. // _destination.Cooling(_moveTask.CoolingTime);
  185. //&& !SC.GetValue<bool>("EFEM.EfemRobot.UpperBladeEnable")
  186. if (_moveTask.SourceModule == ModuleName.EfemRobot || _moveTask.DestinationModule == ModuleName.EfemRobot)
  187. {
  188. if (_moveTask.SourceModule == ModuleName.EfemRobot)
  189. {
  190. if (_moveTask.SourceSlot == 0 && SC.GetValue<bool>("EFEM.EfemRobot.LowerBladeEnable"))
  191. {
  192. _moveTask.RobotHand = (Hand)_moveTask.SourceSlot;
  193. }
  194. else if (_moveTask.SourceSlot == 1 && SC.GetValue<bool>("EFEM.EfemRobot.UpperBladeEnable"))
  195. {
  196. _moveTask.RobotHand = (Hand)_moveTask.SourceSlot;
  197. }
  198. else
  199. {
  200. EV.PostWarningLog("System", $"手臂已被禁用");
  201. return Result.FAIL;
  202. }
  203. }
  204. else if (_moveTask.DestinationModule == ModuleName.EfemRobot)
  205. {
  206. if (_moveTask.DestinationSlot == 0 && SC.GetValue<bool>("EFEM.EfemRobot.LowerBladeEnable"))
  207. {
  208. _moveTask.RobotHand = (Hand)_moveTask.DestinationSlot;
  209. }
  210. else if (_moveTask.DestinationSlot == 1 && SC.GetValue<bool>("EFEM.EfemRobot.UpperBladeEnable"))
  211. {
  212. _moveTask.RobotHand = (Hand)_moveTask.DestinationSlot;
  213. }
  214. else
  215. {
  216. EV.PostWarningLog("System", $"手臂已被禁用");
  217. return Result.FAIL;
  218. }
  219. //_moveTask.RobotHand = (Hand)_moveTask.DestinationSlot;
  220. }
  221. }
  222. else
  223. {
  224. if (SC.GetValue<bool>("EFEM.EfemRobot.LowerBladeEnable") && !WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  225. {
  226. _moveTask.RobotHand = (Hand)0;
  227. }
  228. else if (SC.GetValue<bool>("EFEM.EfemRobot.UpperBladeEnable") && !WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1))
  229. {
  230. _moveTask.RobotHand = (Hand)1;
  231. }
  232. else
  233. {
  234. EV.PostWarningLog("System", $"手臂已被禁用");
  235. return Result.FAIL;
  236. }
  237. }
  238. return Result.RUN;
  239. }
  240. public Result Start(params object[] objs)
  241. {
  242. return this.Start();
  243. }
  244. public Result Monitor()
  245. {
  246. if (_source.IsError || _destination.IsError || _efemRobot.IsError)
  247. return Result.FAIL;
  248. if (!WaferManager.Instance.CheckHasWafer(_moveTask.SourceModule, _moveTask.SourceSlot) &&
  249. WaferManager.Instance.CheckHasWafer(_moveTask.DestinationModule, _moveTask.DestinationSlot) &&
  250. _efemRobot.IsAvailable)
  251. {
  252. if (_source.IsWaitTransfer(ModuleName.EfemRobot))
  253. {
  254. _source.PostTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
  255. //_source.StopWaitTransfer(ModuleName.EfemRobot);
  256. }
  257. if (_destination.IsWaitTransfer(ModuleName.EfemRobot))
  258. {
  259. _destination.PostTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0);
  260. //_destination.StopWaitTransfer(ModuleName.EfemRobot);
  261. }
  262. if (_source.IsAvailable && _destination.IsAvailable)
  263. {
  264. if (_moveTask.CoolingTime > 0 && ModuleHelper.IsCooling(_moveTask.DestinationModule))
  265. {
  266. _destination.Cooling(_moveTask.CoolingTime);
  267. _moveTask.CoolingTime = 0;
  268. return Result.RUN;
  269. }
  270. return Result.DONE;
  271. }
  272. return Result.RUN;
  273. }
  274. if (!_efemRobot.IsAvailable)
  275. return Result.RUN;
  276. //pick
  277. if (_moveTask.SourceModule != ModuleName.EfemRobot)
  278. {
  279. if (WaferManager.Instance.CheckHasWafer(_moveTask.SourceModule, _moveTask.SourceSlot))
  280. {
  281. if (!_source.IsAvailable)
  282. return Result.RUN;
  283. if (!_source.IsReadyForPick(ModuleName.EfemRobot, _moveTask.SourceSlot, _moveTask.RobotHand))
  284. {
  285. if (!_source.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, _moveTask.SourceSlot))
  286. return Result.FAIL;
  287. }
  288. if (!_source.IsAvailable)
  289. return Result.RUN;
  290. if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_moveTask.RobotHand))
  291. {
  292. if (!_efemRobot.Pick(_moveTask.SourceModule, _moveTask.SourceSlot, _moveTask.RobotHand))
  293. {
  294. return Result.FAIL;
  295. }
  296. _source.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
  297. }
  298. if (!_efemRobot.IsAvailable)
  299. return Result.RUN;
  300. }
  301. else
  302. {
  303. if (!_efemRobot.IsAvailable)
  304. return Result.RUN;
  305. if (_source.IsWaitTransfer(ModuleName.EfemRobot))
  306. {
  307. _source.PostTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
  308. }
  309. }
  310. }
  311. //place
  312. if (_moveTask.DestinationModule != ModuleName.EfemRobot)
  313. {
  314. if (!_destination.IsAvailable)
  315. return Result.RUN;
  316. if (!WaferManager.Instance.CheckHasWafer(_moveTask.DestinationModule, _moveTask.DestinationSlot))
  317. {
  318. if (!_destination.IsReadyForPlace(ModuleName.EfemRobot, _moveTask.DestinationSlot, _moveTask.RobotHand))
  319. {
  320. if (!_destination.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place,
  321. _moveTask.DestinationSlot))
  322. return Result.FAIL;
  323. }
  324. if (!_destination.IsAvailable)
  325. return Result.RUN;
  326. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_moveTask.RobotHand))
  327. {
  328. if (!_efemRobot.Place(_moveTask.DestinationModule, _moveTask.DestinationSlot, _moveTask.RobotHand))
  329. return Result.FAIL;
  330. _destination.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0);
  331. }
  332. if (!_efemRobot.IsAvailable)
  333. return Result.RUN;
  334. }
  335. else
  336. {
  337. if (!_efemRobot.IsAvailable)
  338. return Result.RUN;
  339. if (_destination.IsWaitTransfer(ModuleName.EfemRobot))
  340. {
  341. _destination.PostTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0);
  342. //_destination.StopWaitTransfer(ModuleName.EfemRobot);
  343. }
  344. }
  345. }
  346. return Result.RUN;
  347. }
  348. public void Abort()
  349. {
  350. Clear();
  351. }
  352. public void Clear()
  353. {
  354. _efemRobot.ResetTask();
  355. _source?.ResetTask();
  356. _destination?.ResetTask();
  357. }
  358. }
  359. public class AlignRoutine : TransferModule, IRoutine
  360. {
  361. private SchedulerAligner _aligner;
  362. public AlignRoutine(string module)
  363. {
  364. _aligner = GetModule(module) as SchedulerAligner;
  365. }
  366. public Result Start(params object[] objs)
  367. {
  368. _aligner.Align(0);
  369. return Result.RUN;
  370. }
  371. public Result Monitor()
  372. {
  373. if (_aligner.IsAvailable)
  374. return Result.DONE;
  375. return Result.RUN;
  376. }
  377. public void Abort()
  378. {
  379. }
  380. }
  381. public class CoolingRoutine : TransferModule, IRoutine
  382. {
  383. private SchedulerAligner _cooling;
  384. private int _coolingTimeS;
  385. public CoolingRoutine(string module, int coolingTimeS)
  386. {
  387. _cooling = GetModule(module) as SchedulerAligner;
  388. _coolingTimeS = coolingTimeS;
  389. }
  390. public Result Start(params object[] objs)
  391. {
  392. _cooling.Cooling(_coolingTimeS);
  393. return Result.RUN;
  394. }
  395. public Result Monitor()
  396. {
  397. if (_cooling.IsAvailable)
  398. return Result.DONE;
  399. return Result.RUN;
  400. }
  401. public void Abort()
  402. {
  403. }
  404. }
  405. }