ManualTransfer.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. using System.Collections.Generic;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.Util;
  4. using Aitex.Core.RT.Event;
  5. using MECF.Framework.Common.Equipment;
  6. using Virgo_DRT.Scheduler;
  7. using Aitex.Sorter.Common;
  8. using MECF.Framework.Common.Schedulers;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using Virgo_DRT.Modules.PMs;
  11. using Virgo_DRT.Modules.Schedulers;
  12. namespace Virgo_DRT.Modules
  13. {
  14. internal interface IManualTransferRoutine : IRoutine
  15. {
  16. }
  17. public class MoveItemEx : MoveItem
  18. {
  19. public int CoolingTime { get; set; }
  20. public MoveItemEx(ModuleName sourceModule, int sourceSlot, ModuleName destinationModule, int destinationSlot, int coolingTime)
  21. : base(sourceModule, sourceSlot, destinationModule, destinationSlot, Hand.Blade1)
  22. {
  23. CoolingTime = coolingTime;
  24. }
  25. }
  26. public class ManualTransfer : TransferModule
  27. {
  28. private Queue<IRoutine> _moveTaskQueue = new Queue<IRoutine>();
  29. private IRoutine _activeTask;
  30. public Result Start(object[] objs)
  31. {
  32. _moveTaskQueue.Clear();
  33. ModuleName source = (ModuleName)objs[0];
  34. int ss = (int)objs[1];
  35. ModuleName target = (ModuleName)objs[2];
  36. int ds = (int)objs[3];
  37. bool autoAlign = (bool)objs[4];
  38. int alignAngle = (int)objs[5];
  39. bool autoCooling = (bool)objs[6];
  40. int coolingTime = (int)objs[7];
  41. if (!WaferManager.Instance.CheckHasWafer(source, ss))
  42. {
  43. EV.PostWarningLog("System", "source no wafer");
  44. return Result.FAIL;
  45. }
  46. if (!WaferManager.Instance.CheckNoWafer(target, ds))
  47. {
  48. EV.PostWarningLog("System", "destination has wafer");
  49. return Result.FAIL;
  50. }
  51. if (source!=ModuleName.EfemRobot && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  52. {
  53. EV.PostWarningLog("System", "robot has wafer");
  54. return Result.FAIL;
  55. }
  56. if (autoAlign && !ModuleHelper.IsAligner(source) && !ModuleHelper.IsAligner(target) )
  57. {
  58. if (WaferManager.Instance.CheckHasWafer(ModuleName.Aligner1, 0) && WaferManager.Instance.CheckHasWafer(ModuleName.Aligner2, 0))
  59. {
  60. EV.PostWarningLog("System", "Can not transfer, aligner has wafer, can not auto align");
  61. return Result.FAIL;
  62. }
  63. ModuleName aligner = WaferManager.Instance.CheckHasWafer(ModuleName.Aligner1, 0)
  64. ? ModuleName.Aligner2
  65. : ModuleName.Aligner1;
  66. _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(source, ss, aligner, 0, 1)));
  67. _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(aligner, 0, target, ds, 0)));
  68. }
  69. else if(autoCooling && !ModuleHelper.IsAligner(source) && !ModuleHelper.IsAligner(target))
  70. {
  71. if (WaferManager.Instance.CheckHasWafer(ModuleName.Aligner1, 0) && WaferManager.Instance.CheckHasWafer(ModuleName.Aligner2, 0))
  72. {
  73. EV.PostWarningLog("System", "Can not transfer, aligner has wafer, can not auto align");
  74. return Result.FAIL;
  75. }
  76. ModuleName aligner = WaferManager.Instance.CheckHasWafer(ModuleName.Aligner1, 0)
  77. ? ModuleName.Aligner2
  78. : ModuleName.Aligner1;
  79. _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(source, ss, aligner, 0, coolingTime)));
  80. _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(aligner, 0, target, ds, 0)));
  81. }
  82. else
  83. {
  84. _moveTaskQueue.Enqueue(new EfemRobotMover(new MoveItemEx(source, ss, target, ds, coolingTime)));
  85. }
  86. _activeTask = _moveTaskQueue.Dequeue();
  87. return _activeTask.Start();
  88. }
  89. public Result Monitor(object[] objs)
  90. {
  91. System.Diagnostics.Debug.Assert(_activeTask != null, "mover should not be null, call start first");
  92. Result ret = _activeTask.Monitor();
  93. if (ret == Result.FAIL)
  94. return ret;
  95. if (ret == Result.DONE)
  96. {
  97. if (_moveTaskQueue.Count > 0)
  98. {
  99. _activeTask = _moveTaskQueue.Dequeue();
  100. return _activeTask.Start();
  101. }
  102. return Result.DONE;
  103. }
  104. return Result.RUN;
  105. }
  106. public void Clear()
  107. {
  108. _moveTaskQueue.Clear();
  109. _activeTask = null;
  110. }
  111. }
  112. public class EfemRobotMover : TransferModule, IRoutine
  113. {
  114. private MoveItemEx _moveTask;
  115. private SchedulerModule _source;
  116. private SchedulerModule _destination;
  117. public EfemRobotMover(MoveItemEx moveTask)
  118. {
  119. _moveTask = moveTask;
  120. }
  121. public Result Start()
  122. {
  123. _source = GetModule(_moveTask.SourceModule.ToString());
  124. _destination = GetModule(_moveTask.DestinationModule.ToString());
  125. System.Diagnostics.Debug.Assert(_source != null, $"{_moveTask.SourceModule} not valid");
  126. System.Diagnostics.Debug.Assert(_destination != null, $"{_moveTask.DestinationModule} not valid");
  127. if(!WaferManager.Instance.CheckHasWafer(_moveTask.SourceModule, _moveTask.SourceSlot))
  128. {
  129. EV.PostWarningLog("System", $"Failed transfer, source {_moveTask.SourceModule} slot {_moveTask.SourceSlot + 1} has not wafer");
  130. return Result.FAIL;
  131. }
  132. if (WaferManager.Instance.CheckHasWafer(_moveTask.DestinationModule, _moveTask.DestinationSlot))
  133. {
  134. EV.PostWarningLog("System", $"Failed transfer, destination {_moveTask.DestinationModule} slot {_moveTask.DestinationSlot + 1} has wafer");
  135. return Result.FAIL;
  136. }
  137. if (!_source.IsAvailable)
  138. {
  139. EV.PostWarningLog("System", $"Failed transfer, source {_moveTask.SourceModule} not ready");
  140. return Result.FAIL;
  141. }
  142. if (ModuleHelper.IsLoadPort(_source.Module))
  143. {
  144. if (!(_source as SchedulerLoadPort).CheckReadyTransfer())
  145. {
  146. EV.PostWarningLog("System", $"Failed transfer, source {_moveTask.SourceModule} not ready");
  147. return Result.FAIL;
  148. }
  149. }
  150. if (!_destination.IsAvailable)
  151. {
  152. EV.PostWarningLog("System", $"Failed transfer, Destination {_moveTask.DestinationModule} not ready");
  153. return Result.FAIL;
  154. }
  155. if (ModuleHelper.IsLoadPort(_destination.Module))
  156. {
  157. if (!(_destination as SchedulerLoadPort).CheckReadyTransfer())
  158. {
  159. EV.PostWarningLog("System", $"Failed transfer, source {_moveTask.DestinationModule} not ready");
  160. return Result.FAIL;
  161. }
  162. }
  163. if (!_efemRobot.IsAvailable)
  164. {
  165. EV.PostWarningLog("System", $"Failed transfer, EFEM Robot not ready");
  166. return Result.FAIL;
  167. }
  168. if (ModuleHelper.IsAligner(_source.Module))
  169. _source.Cooling(_moveTask.CoolingTime);
  170. if (ModuleHelper.IsAligner(_destination.Module))
  171. _destination.Cooling(_moveTask.CoolingTime);
  172. if (_moveTask.SourceModule == ModuleName.EfemRobot)
  173. _moveTask.RobotHand = (Hand)_moveTask.SourceSlot;
  174. if (_moveTask.DestinationModule == ModuleName.EfemRobot)
  175. _moveTask.RobotHand = (Hand)_moveTask.DestinationSlot;
  176. return Result.RUN;
  177. }
  178. public Result Start(params object[] objs)
  179. {
  180. return this.Start();
  181. }
  182. public Result Monitor()
  183. {
  184. if (_source.IsError || _destination.IsError || _efemRobot.IsError)
  185. return Result.FAIL;
  186. if (!WaferManager.Instance.CheckHasWafer(_moveTask.SourceModule, _moveTask.SourceSlot) &&
  187. WaferManager.Instance.CheckHasWafer(_moveTask.DestinationModule, _moveTask.DestinationSlot) &&
  188. _efemRobot.IsAvailable)
  189. {
  190. if (_source.IsWaitTransfer(ModuleName.EfemRobot))
  191. {
  192. _source.PostTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
  193. //_source.StopWaitTransfer(ModuleName.EfemRobot);
  194. }
  195. if (_destination.IsWaitTransfer(ModuleName.EfemRobot))
  196. {
  197. _destination.PostTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0);
  198. //_destination.StopWaitTransfer(ModuleName.EfemRobot);
  199. }
  200. if (_source.IsAvailable && _destination.IsAvailable)
  201. return Result.DONE;
  202. return Result.RUN;
  203. }
  204. if (!_efemRobot.IsAvailable)
  205. return Result.RUN;
  206. //pick
  207. if (_moveTask.SourceModule != ModuleName.EfemRobot)
  208. {
  209. if (WaferManager.Instance.CheckHasWafer(_moveTask.SourceModule, _moveTask.SourceSlot))
  210. {
  211. if (!_source.IsAvailable)
  212. return Result.RUN;
  213. if (!_source.IsReadyForPick(ModuleName.EfemRobot, _moveTask.SourceSlot))
  214. {
  215. if (!_source.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, _moveTask.SourceSlot))
  216. return Result.FAIL;
  217. }
  218. if (!_source.IsAvailable)
  219. return Result.RUN;
  220. if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_moveTask.RobotHand))
  221. {
  222. if (!_efemRobot.Pick(_moveTask.SourceModule, _moveTask.SourceSlot, _moveTask.RobotHand))
  223. {
  224. return Result.FAIL;
  225. }
  226. _source.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
  227. }
  228. if (!_efemRobot.IsAvailable)
  229. return Result.RUN;
  230. }
  231. else
  232. {
  233. if (!_efemRobot.IsAvailable)
  234. return Result.RUN;
  235. if (_source.IsWaitTransfer(ModuleName.EfemRobot))
  236. {
  237. _source.PostTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
  238. }
  239. }
  240. }
  241. //place
  242. if (_moveTask.DestinationModule != ModuleName.EfemRobot)
  243. {
  244. if (!_destination.IsAvailable)
  245. return Result.RUN;
  246. if (!WaferManager.Instance.CheckHasWafer(_moveTask.DestinationModule, _moveTask.DestinationSlot))
  247. {
  248. if (!_destination.IsReadyForPlace(ModuleName.EfemRobot, _moveTask.DestinationSlot))
  249. {
  250. if (!_destination.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place,
  251. _moveTask.DestinationSlot))
  252. return Result.FAIL;
  253. }
  254. if (!_destination.IsAvailable)
  255. return Result.RUN;
  256. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_moveTask.RobotHand))
  257. {
  258. if (!_efemRobot.Place(_moveTask.DestinationModule, _moveTask.DestinationSlot, _moveTask.RobotHand))
  259. return Result.FAIL;
  260. _destination.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0);
  261. }
  262. if (!_efemRobot.IsAvailable)
  263. return Result.RUN;
  264. }
  265. else
  266. {
  267. if (!_efemRobot.IsAvailable)
  268. return Result.RUN;
  269. if (_destination.IsWaitTransfer(ModuleName.EfemRobot))
  270. {
  271. _destination.PostTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0);
  272. //_destination.StopWaitTransfer(ModuleName.EfemRobot);
  273. }
  274. }
  275. }
  276. return Result.RUN;
  277. }
  278. public void Abort()
  279. {
  280. Clear();
  281. }
  282. public void Clear()
  283. {
  284. _efemRobot.ResetTask();
  285. _source?.ResetTask();
  286. _destination?.ResetTask();
  287. }
  288. }
  289. }