ManualTransfer.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Aitex.Core.Common;
  5. using Aitex.Core.RT.Routine;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Sorter.Common;
  8. using Aitex.Core.RT.Log;
  9. using Aitex.Core.Util;
  10. using Aitex.Core.RT.DataCenter;
  11. using Aitex.Core.RT.RecipeCenter;
  12. using Aitex.Core.RT.Fsm;
  13. using MECF.Framework.Common.Jobs;
  14. using MECF.Framework.Common.Routine;
  15. using MECF.Framework.Common.Equipment;
  16. using MECF.Framework.Common.SubstrateTrackings;
  17. using MECF.Framework.Common.Schedulers;
  18. using MECF.Framework.Common.DBCore;
  19. using Venus_Core;
  20. using Venus_RT.Modules.Schedulers;
  21. using Venus_RT.Scheduler;
  22. namespace Venus_RT.Modules
  23. {
  24. public class ManualTransfer : IRoutine
  25. {
  26. SchedulerTMRobot _tmRobot = new SchedulerTMRobot();
  27. SchedulerEfemRobot _efemRobot = new SchedulerEfemRobot();
  28. private Queue<MoveItem> _moveTaskQueue = new Queue<MoveItem>();
  29. private MoveItem _move_item = new MoveItem(ModuleName.System, 0, ModuleName.System, 0, Hand.None);
  30. private MoveItem _current_item = new MoveItem(ModuleName.System, 0, ModuleName.System, 0, Hand.None);
  31. private Guid _wafer_id;
  32. private R_TRIG _wafer_arrive_trig = new R_TRIG();
  33. private MovingStatus _moving_status = MovingStatus.Idle;
  34. public RState Start(params object[] objs)
  35. {
  36. // RESET
  37. _moveTaskQueue.Clear();
  38. _moving_status = MovingStatus.Idle;
  39. _wafer_arrive_trig.RST = true ;
  40. _move_item.SourceModule = (ModuleName)objs[0];
  41. _move_item.SourceSlot = (int)objs[1];
  42. _move_item.DestinationModule = (ModuleName)objs[2];
  43. _move_item.DestinationSlot = (int)objs[3];
  44. _wafer_id = WaferManager.Instance.GetWafer(_move_item.SourceModule, _move_item.SourceSlot).InnerId;
  45. if(IsCrossTransfer(_move_item))
  46. {
  47. var slot = SelectLLFreeSlot();
  48. if (slot.Module == ModuleName.System)
  49. return RState.Failed;
  50. // vac to atm
  51. if (ModuleHelper.IsPm(_move_item.SourceModule) || ModuleHelper.IsTMRobot(_move_item.SourceModule))
  52. {
  53. _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, slot.Module, slot.Slot, Hand.Blade1));
  54. if(ModuleHelper.IsEFEMRobot(_move_item.DestinationModule))
  55. {
  56. _moveTaskQueue.Enqueue(new MoveItem(slot.Module, slot.Slot, _move_item.DestinationModule, _move_item.DestinationSlot, (Hand)_move_item.DestinationSlot));
  57. }
  58. else
  59. {
  60. Hand hand = SelectEfemRobotFreeHand();
  61. if(hand == Hand.None)
  62. {
  63. LOG.Write(eEvent.WARN_ROUTER, ModuleName.EfemRobot, "No free efem robot arm for wafer move.");
  64. return RState.Failed;
  65. }
  66. _moveTaskQueue.Enqueue(new MoveItem(slot.Module, slot.Slot, ModuleName.EfemRobot, (int)hand, hand));
  67. _moveTaskQueue.Enqueue(new MoveItem(ModuleName.EfemRobot, (int)hand, _move_item.DestinationModule, _move_item.DestinationSlot, hand));
  68. }
  69. }
  70. // atm to vac
  71. else
  72. {
  73. if (ModuleHelper.IsEFEMRobot(_move_item.SourceModule))
  74. {
  75. _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, slot.Module, slot.Slot, (Hand)_move_item.SourceSlot));
  76. }
  77. else
  78. {
  79. Hand hand = SelectEfemRobotFreeHand();
  80. if (hand == Hand.None)
  81. {
  82. LOG.Write(eEvent.WARN_ROUTER, ModuleName.EfemRobot, "No free efem robot arm for wafer move.");
  83. return RState.Failed;
  84. }
  85. _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, ModuleName.EfemRobot, (int)hand, hand));
  86. _moveTaskQueue.Enqueue(new MoveItem(ModuleName.EfemRobot, (int)hand, slot.Module, slot.Slot, hand));
  87. }
  88. _moveTaskQueue.Enqueue(new MoveItem(slot.Module, slot.Slot, _move_item.DestinationModule, _move_item.DestinationSlot, Hand.Blade1));
  89. }
  90. }
  91. else if(IsVacTransfer(_move_item))
  92. {
  93. _moveTaskQueue.Enqueue(_move_item);
  94. }
  95. else // atm transfer
  96. {
  97. if(ModuleHelper.IsEFEMRobot(_move_item.SourceModule))
  98. {
  99. _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, _move_item.DestinationModule, _move_item.DestinationSlot, (Hand)_move_item.SourceSlot));
  100. }
  101. else if (ModuleHelper.IsEFEMRobot(_move_item.DestinationModule))
  102. {
  103. _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, _move_item.DestinationModule, _move_item.DestinationSlot, (Hand)_move_item.DestinationSlot));
  104. }
  105. else
  106. {
  107. Hand hand = SelectEfemRobotFreeHand();
  108. if (hand == Hand.None)
  109. {
  110. LOG.Write(eEvent.WARN_ROUTER, ModuleName.EfemRobot, "No free efem robot arm for wafer move.");
  111. return RState.Failed;
  112. }
  113. _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, ModuleName.EfemRobot, (int)hand, hand));
  114. _moveTaskQueue.Enqueue(new MoveItem(ModuleName.EfemRobot, (int)hand, _move_item.DestinationModule, _move_item.DestinationSlot, hand));
  115. }
  116. }
  117. _current_item = _moveTaskQueue.Dequeue();
  118. _moving_status = MovingStatus.Waiting;
  119. return RState.Running;
  120. }
  121. public RState Monitor()
  122. {
  123. return MoveWaferForward();
  124. }
  125. public void Abort()
  126. {
  127. }
  128. public void Clear()
  129. {
  130. _moveTaskQueue.Clear();
  131. }
  132. private RState MoveWaferForward()
  133. {
  134. switch(_moving_status)
  135. {
  136. case MovingStatus.Waiting:
  137. {
  138. if(IsCurrentModuleReady())
  139. {
  140. // Post current item
  141. if(IsVacTransfer(_current_item))
  142. {
  143. _tmRobot.PostMoveItems(new MoveItem[1] { _current_item });
  144. }
  145. else
  146. {
  147. _efemRobot.PostMoveItems(new MoveItem[1] { _current_item });
  148. }
  149. _moving_status = MovingStatus.Moving;
  150. }
  151. }
  152. break;
  153. case MovingStatus.Moving:
  154. {
  155. _wafer_arrive_trig.CLK = IsArriveCurrentTarget();
  156. if (_wafer_arrive_trig.Q)
  157. {
  158. _moving_status = MovingStatus.Idle;
  159. }
  160. }
  161. break;
  162. case MovingStatus.Idle:
  163. {
  164. if(IsCurrentModuleReady())
  165. {
  166. if(_moveTaskQueue.Count > 0)
  167. {
  168. _current_item = _moveTaskQueue.Dequeue();
  169. _moving_status = MovingStatus.Waiting;
  170. }
  171. }
  172. break;
  173. }
  174. }
  175. return TransferStatus();
  176. }
  177. private bool IsVacTransfer(MoveItem item)
  178. {
  179. return ModuleHelper.IsPm(item.SourceModule) ||
  180. ModuleHelper.IsTMRobot(item.SourceModule) ||
  181. ModuleHelper.IsPm(item.DestinationModule) ||
  182. ModuleHelper.IsTMRobot(item.DestinationModule);
  183. }
  184. private bool IsCrossTransfer(MoveItem item)
  185. {
  186. if (ModuleHelper.IsLoadLock(item.DestinationModule) || ModuleHelper.IsLoadLock(item.SourceModule))
  187. return false;
  188. if (((ModuleHelper.IsPm(item.SourceModule) || ModuleHelper.IsTMRobot(item.SourceModule)) &&
  189. !ModuleHelper.IsPm(item.DestinationModule) && !ModuleHelper.IsTMRobot(item.DestinationModule)) ||
  190. ((ModuleHelper.IsPm(item.DestinationModule) || ModuleHelper.IsTMRobot(item.DestinationModule)) &&
  191. !ModuleHelper.IsPm(item.SourceModule) && !ModuleHelper.IsTMRobot(item.SourceModule)))
  192. return true;
  193. return false;
  194. }
  195. private bool IsArriveCurrentTarget()
  196. {
  197. var wafer = WaferManager.Instance.GetWafer(_current_item.DestinationModule, _current_item.DestinationSlot);
  198. return !wafer.IsEmpty && wafer.InnerId == _wafer_id;
  199. }
  200. private bool IsCurrentModuleReady()
  201. {
  202. return (IsVacTransfer(_current_item) ? _tmRobot.IsAvailable : _efemRobot.IsAvailable) &&
  203. _isModuleReady(_current_item.SourceModule) &&
  204. _isModuleReady(_current_item.DestinationModule);
  205. }
  206. private bool IsTransferError()
  207. {
  208. return (IsVacTransfer(_current_item) ? _tmRobot.IsError : _efemRobot.IsError) ||
  209. _isModuleError(_current_item.SourceModule) ||
  210. _isModuleError(_current_item.DestinationModule);
  211. }
  212. private bool _isModuleReady(ModuleName module)
  213. {
  214. return Singleton<TransferModule>.Instance.GetScheduler(module).IsAvailable;
  215. }
  216. private bool _isModuleError(ModuleName module)
  217. {
  218. return Singleton<TransferModule>.Instance.GetScheduler(module).IsError;
  219. }
  220. private Hand SelectEfemRobotFreeHand()
  221. {
  222. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0))
  223. return Hand.Blade1;
  224. else if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1))
  225. return Hand.Blade2;
  226. else
  227. return Hand.None;
  228. }
  229. private SlotItem SelectLLFreeSlot()
  230. {
  231. foreach(var ll in new ModuleName[2] { ModuleName.LLA, ModuleName.LLB})
  232. {
  233. if (ModuleHelper.IsInstalled(ll) && _isModuleReady(ll))
  234. {
  235. for (int i = 0; i < 4; i++)
  236. {
  237. if (WaferManager.Instance.CheckNoWafer(ll, i))
  238. return new SlotItem(ll, i);
  239. }
  240. }
  241. }
  242. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, "Cannot move wafer as no valid Loadlock slot");
  243. return new SlotItem(ModuleName.System, -1);
  244. }
  245. private RState TransferStatus()
  246. {
  247. if (IsTransferError())
  248. return RState.Failed;
  249. if (IsCurrentModuleReady() && _moveTaskQueue.Count == 0 && _moving_status == MovingStatus.Idle)
  250. return RState.End;
  251. return RState.Running;
  252. }
  253. }
  254. public class ReturnAllWafer : IRoutine
  255. {
  256. private List<ModuleName> _moduleList = new List<ModuleName> { ModuleName.EfemRobot, ModuleName.Aligner1, ModuleName.Aligner, ModuleName.LLA, ModuleName.LLB, ModuleName.TMRobot, ModuleName.PMA, ModuleName.PMB, ModuleName.PMC, ModuleName.PMD };
  257. private ManualTransfer _manualTransfer;
  258. private Queue<MoveItem> _returnTaskQueue = new Queue<MoveItem>();
  259. private MoveItem _current_item;
  260. public ReturnAllWafer(ManualTransfer manualTransfer)
  261. {
  262. _manualTransfer = manualTransfer;
  263. }
  264. public RState Start(params object[] objs)
  265. {
  266. foreach(var mod in _moduleList)
  267. {
  268. if (ModuleHelper.IsInstalled(mod) && Singleton<TransferModule>.Instance.GetScheduler(mod).IsAvailable)
  269. {
  270. PushWaferToReturnQueqe(mod, 0);
  271. if (ModuleHelper.IsEFEMRobot(mod) || ModuleHelper.IsTMRobot(mod))
  272. {
  273. PushWaferToReturnQueqe(mod, 1);
  274. }
  275. else if (ModuleHelper.IsLoadLock(mod))
  276. {
  277. int nSlotNumber = SC.GetValue<int>($"{mod}.SlotNumber");
  278. for (int i = 1; i < nSlotNumber; i++)
  279. {
  280. PushWaferToReturnQueqe(mod, i);
  281. }
  282. }
  283. }
  284. }
  285. if (_returnTaskQueue.Count == 0)
  286. return RState.Failed;
  287. _current_item = _returnTaskQueue.Dequeue();
  288. _manualTransfer.Start(_current_item.SourceModule, _current_item.SourceSlot, _current_item.DestinationModule, _current_item.DestinationSlot);
  289. return RState.Running;
  290. }
  291. public RState Monitor()
  292. {
  293. var ret = _manualTransfer.Monitor();
  294. if (ret == RState.End)
  295. {
  296. if (_returnTaskQueue.Count > 0)
  297. {
  298. _current_item = _returnTaskQueue.Dequeue();
  299. _manualTransfer.Start(_current_item.SourceModule, _current_item.SourceSlot, _current_item.DestinationModule, _current_item.DestinationSlot);
  300. }
  301. else
  302. return RState.End;
  303. }
  304. else if (ret == RState.Failed || ret == RState.Timeout)
  305. {
  306. LOG.Write(eEvent.ERR_ROUTINE_FAILED, ModuleName.System, $"Return Wafer {_current_item.SourceModule}{_current_item.SourceSlot} failed");
  307. return RState.Failed;
  308. }
  309. return RState.Running;
  310. }
  311. public void Abort()
  312. {
  313. }
  314. public void Clear()
  315. {
  316. _returnTaskQueue.Clear();
  317. }
  318. private void PushWaferToReturnQueqe(ModuleName mod, int nSlot)
  319. {
  320. var wafer = WaferManager.Instance.GetWafer(mod, nSlot);
  321. if (!wafer.IsEmpty)
  322. {
  323. _returnTaskQueue.Enqueue(new MoveItem(mod, nSlot, (ModuleName)wafer.OriginStation, wafer.OriginSlot, Hand.Blade1));
  324. }
  325. }
  326. }
  327. }