ManualTransfer.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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 = (SchedulerTMRobot)Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot);
  27. SchedulerEfemRobot _efemRobot = (SchedulerEfemRobot)Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot);
  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. private int _tmRobotSingleArmOption = 0;
  35. private int _efemRobotSingleArmOption = 0;
  36. public ManualTransfer()
  37. {
  38. _tmRobotSingleArmOption = SC.GetValue<int>("TM.SingleArmOption");
  39. _efemRobotSingleArmOption = SC.GetValue<int>("EFEM.SingleArmOption");
  40. }
  41. public RState Start(params object[] objs)
  42. {
  43. _tmRobotSingleArmOption = SC.GetValue<int>("TM.SingleArmOption");
  44. _efemRobotSingleArmOption = SC.GetValue<int>("EFEM.SingleArmOption");
  45. // rounding the single arm option
  46. if (_tmRobotSingleArmOption > 2)
  47. _tmRobotSingleArmOption = 0;
  48. if (_efemRobotSingleArmOption > 2)
  49. _efemRobotSingleArmOption = 0;
  50. // RESET
  51. _moveTaskQueue.Clear();
  52. _moving_status = MovingStatus.Idle;
  53. _wafer_arrive_trig.RST = true ;
  54. _move_item.SourceModule = (ModuleName)objs[0];
  55. _move_item.SourceSlot = (int)objs[1];
  56. _move_item.DestinationModule = (ModuleName)objs[2];
  57. _move_item.DestinationSlot = (int)objs[3];
  58. _wafer_id = WaferManager.Instance.GetWafer(_move_item.SourceModule, _move_item.SourceSlot).InnerId;
  59. if (ModuleHelper.IsLoadPort(_move_item.DestinationModule) && !Singleton<TransferModule>.Instance.GetScheduler(_move_item.DestinationModule).IsAvailable)
  60. {
  61. LOG.Write(eEvent.ERR_ROUTER, _move_item.DestinationModule, $"The destination Loadport {_move_item.DestinationModule} is not ready for move wafer.");
  62. return RState.Failed;
  63. }
  64. if (!CheckSingleArmOption(_move_item.DestinationModule, _move_item.DestinationSlot))
  65. return RState.Failed;
  66. if (!CheckSingleArmOption(_move_item.SourceModule, _move_item.SourceSlot))
  67. return RState.Failed;
  68. if (IsCrossTransfer(_move_item))
  69. {
  70. var slot = SelectLLFreeSlot();
  71. if (slot.Module == ModuleName.System)
  72. return RState.Failed;
  73. // vac to atm
  74. if (ModuleHelper.IsPm(_move_item.SourceModule) || ModuleHelper.IsTMRobot(_move_item.SourceModule))
  75. {
  76. _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, slot.Module, slot.Slot, Hand.Blade1));
  77. if(ModuleHelper.IsEFEMRobot(_move_item.DestinationModule))
  78. {
  79. _moveTaskQueue.Enqueue(new MoveItem(slot.Module, slot.Slot, _move_item.DestinationModule, _move_item.DestinationSlot, (Hand)_move_item.DestinationSlot));
  80. }
  81. else
  82. {
  83. Hand hand = SelectEfemRobotFreeHand();
  84. if(hand == Hand.None)
  85. {
  86. LOG.Write(eEvent.WARN_ROUTER, ModuleName.EfemRobot, "No free efem robot arm for wafer move.");
  87. return RState.Failed;
  88. }
  89. _moveTaskQueue.Enqueue(new MoveItem(slot.Module, slot.Slot, ModuleName.EfemRobot, (int)hand, hand));
  90. _moveTaskQueue.Enqueue(new MoveItem(ModuleName.EfemRobot, (int)hand, _move_item.DestinationModule, _move_item.DestinationSlot, hand));
  91. }
  92. }
  93. // atm to vac
  94. else
  95. {
  96. if (ModuleHelper.IsEFEMRobot(_move_item.SourceModule))
  97. {
  98. _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, slot.Module, slot.Slot, (Hand)_move_item.SourceSlot));
  99. }
  100. else
  101. {
  102. Hand hand = SelectEfemRobotFreeHand();
  103. if (hand == Hand.None)
  104. {
  105. LOG.Write(eEvent.WARN_ROUTER, ModuleName.EfemRobot, "No free efem robot arm for wafer move.");
  106. return RState.Failed;
  107. }
  108. _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, ModuleName.EfemRobot, (int)hand, hand));
  109. _moveTaskQueue.Enqueue(new MoveItem(ModuleName.EfemRobot, (int)hand, slot.Module, slot.Slot, hand));
  110. }
  111. _moveTaskQueue.Enqueue(new MoveItem(slot.Module, slot.Slot, _move_item.DestinationModule, _move_item.DestinationSlot, Hand.Blade1));
  112. }
  113. }
  114. else if(IsVacTransfer(_move_item))
  115. {
  116. _moveTaskQueue.Enqueue(_move_item);
  117. }
  118. else // atm transfer
  119. {
  120. if(ModuleHelper.IsEFEMRobot(_move_item.SourceModule))
  121. {
  122. _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, _move_item.DestinationModule, _move_item.DestinationSlot, (Hand)_move_item.SourceSlot));
  123. }
  124. else if (ModuleHelper.IsEFEMRobot(_move_item.DestinationModule))
  125. {
  126. _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, _move_item.DestinationModule, _move_item.DestinationSlot, (Hand)_move_item.DestinationSlot));
  127. }
  128. else
  129. {
  130. Hand hand = SelectEfemRobotFreeHand();
  131. if (hand == Hand.None)
  132. {
  133. LOG.Write(eEvent.WARN_ROUTER, ModuleName.EfemRobot, "No free efem robot arm for wafer move.");
  134. return RState.Failed;
  135. }
  136. _moveTaskQueue.Enqueue(new MoveItem(_move_item.SourceModule, _move_item.SourceSlot, ModuleName.EfemRobot, (int)hand, hand));
  137. _moveTaskQueue.Enqueue(new MoveItem(ModuleName.EfemRobot, (int)hand, _move_item.DestinationModule, _move_item.DestinationSlot, hand));
  138. }
  139. }
  140. _current_item = _moveTaskQueue.Dequeue();
  141. _moving_status = MovingStatus.Waiting;
  142. return RState.Running;
  143. }
  144. public RState Monitor()
  145. {
  146. return MoveWaferForward();
  147. }
  148. public void Abort()
  149. {
  150. }
  151. public void Clear()
  152. {
  153. _moveTaskQueue.Clear();
  154. Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot).ResetTask();
  155. Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot).ResetTask();
  156. }
  157. private RState MoveWaferForward()
  158. {
  159. switch(_moving_status)
  160. {
  161. case MovingStatus.Waiting:
  162. {
  163. if(IsCurrentModuleReady())
  164. {
  165. // Post current item
  166. if(IsVacTransfer(_current_item))
  167. {
  168. _tmRobot.PostMoveItems(new MoveItem[1] { _current_item });
  169. }
  170. else
  171. {
  172. _efemRobot.PostMoveItems(new MoveItem[1] { _current_item });
  173. }
  174. _moving_status = MovingStatus.Moving;
  175. }
  176. }
  177. break;
  178. case MovingStatus.Moving:
  179. {
  180. _wafer_arrive_trig.CLK = IsArriveCurrentTarget();
  181. if (_wafer_arrive_trig.Q)
  182. {
  183. _moving_status = MovingStatus.Idle;
  184. }
  185. }
  186. break;
  187. case MovingStatus.Idle:
  188. {
  189. if(IsCurrentModuleReady())
  190. {
  191. if(_moveTaskQueue.Count > 0)
  192. {
  193. _current_item = _moveTaskQueue.Dequeue();
  194. _moving_status = MovingStatus.Waiting;
  195. }
  196. }
  197. break;
  198. }
  199. }
  200. return TransferStatus();
  201. }
  202. private bool IsVacTransfer(MoveItem item)
  203. {
  204. return ModuleHelper.IsPm(item.SourceModule) ||
  205. ModuleHelper.IsTMRobot(item.SourceModule) ||
  206. ModuleHelper.IsPm(item.DestinationModule) ||
  207. ModuleHelper.IsTMRobot(item.DestinationModule);
  208. }
  209. private bool IsCrossTransfer(MoveItem item)
  210. {
  211. if (ModuleHelper.IsLoadLock(item.DestinationModule) || ModuleHelper.IsLoadLock(item.SourceModule))
  212. return false;
  213. if (((ModuleHelper.IsPm(item.SourceModule) || ModuleHelper.IsTMRobot(item.SourceModule)) &&
  214. !ModuleHelper.IsPm(item.DestinationModule) && !ModuleHelper.IsTMRobot(item.DestinationModule)) ||
  215. ((ModuleHelper.IsPm(item.DestinationModule) || ModuleHelper.IsTMRobot(item.DestinationModule)) &&
  216. !ModuleHelper.IsPm(item.SourceModule) && !ModuleHelper.IsTMRobot(item.SourceModule)))
  217. return true;
  218. return false;
  219. }
  220. private bool IsArriveCurrentTarget()
  221. {
  222. var wafer = WaferManager.Instance.GetWafer(_current_item.DestinationModule, _current_item.DestinationSlot);
  223. return !wafer.IsEmpty && wafer.InnerId == _wafer_id;
  224. }
  225. private bool IsCurrentModuleReady()
  226. {
  227. return (IsVacTransfer(_current_item) ? _tmRobot.IsAvailable : _efemRobot.IsAvailable) &&
  228. _isModuleReady(_current_item.SourceModule) &&
  229. _isModuleReady(_current_item.DestinationModule);
  230. }
  231. private bool IsTransferError()
  232. {
  233. return (IsVacTransfer(_current_item) ? _tmRobot.IsError : _efemRobot.IsError) ||
  234. _isModuleError(_current_item.SourceModule) ||
  235. _isModuleError(_current_item.DestinationModule);
  236. }
  237. private bool _isModuleReady(ModuleName module)
  238. {
  239. return Singleton<TransferModule>.Instance.GetScheduler(module).IsAvailable;
  240. }
  241. private bool _isModuleError(ModuleName module)
  242. {
  243. return Singleton<TransferModule>.Instance.GetScheduler(module).IsError;
  244. }
  245. private Hand SelectEfemRobotFreeHand()
  246. {
  247. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0))
  248. return Hand.Blade1;
  249. else if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1))
  250. return Hand.Blade2;
  251. else
  252. return Hand.None;
  253. }
  254. private SlotItem SelectLLFreeSlot()
  255. {
  256. foreach(var ll in new ModuleName[2] { ModuleName.LLA, ModuleName.LLB})
  257. {
  258. if (ModuleHelper.IsInstalled(ll) && _isModuleReady(ll))
  259. {
  260. for (int i = 0; i < 4; i++)
  261. {
  262. if (WaferManager.Instance.CheckNoWafer(ll, i))
  263. return new SlotItem(ll, i);
  264. }
  265. }
  266. }
  267. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, "Cannot move wafer as no valid Loadlock slot");
  268. return new SlotItem(ModuleName.System, -1);
  269. }
  270. private RState TransferStatus()
  271. {
  272. if (IsTransferError())
  273. return RState.Failed;
  274. if (IsCurrentModuleReady() && _moveTaskQueue.Count == 0 && _moving_status == MovingStatus.Idle)
  275. return RState.End;
  276. return RState.Running;
  277. }
  278. private bool CheckSingleArmOption(ModuleName robot, int slot)
  279. {
  280. if(ModuleHelper.IsTMRobot(robot))
  281. {
  282. if (_tmRobotSingleArmOption != 0 && _tmRobotSingleArmOption != slot + 1)
  283. {
  284. LOG.Write(eEvent.ERR_ROUTER, ModuleName.TMRobot, $"Cannot move the wafer as TM Robot {(Hand)slot} is disabled.");
  285. return false;
  286. }
  287. }
  288. else if(ModuleHelper.IsEFEMRobot(robot))
  289. {
  290. if (_efemRobotSingleArmOption != 0 && _efemRobotSingleArmOption != slot + 1)
  291. {
  292. LOG.Write(eEvent.ERR_ROUTER, ModuleName.EfemRobot, $"Cannot move the wafer as EFEM Robot {(Hand)slot} is disabled.");
  293. return false;
  294. }
  295. }
  296. return true;
  297. }
  298. public int GetSingleArmOption(ModuleName robot)
  299. {
  300. return ModuleHelper.IsTMRobot(robot) ? _tmRobotSingleArmOption : _efemRobotSingleArmOption;
  301. }
  302. }
  303. public class ReturnAllWafer : IRoutine
  304. {
  305. 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 };
  306. private ManualTransfer _manualTransfer;
  307. private Queue<MoveItem> _returnTaskQueue = new Queue<MoveItem>();
  308. private MoveItem _current_item;
  309. public ReturnAllWafer(ManualTransfer manualTransfer)
  310. {
  311. _manualTransfer = manualTransfer;
  312. }
  313. public RState Start(params object[] objs)
  314. {
  315. Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot).ResetTask();
  316. Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot).ResetTask();
  317. foreach(var mod in _moduleList)
  318. {
  319. if (ModuleHelper.IsInstalled(mod) && Singleton<TransferModule>.Instance.GetScheduler(mod).IsAvailable)
  320. {
  321. if (ModuleHelper.IsEFEMRobot(mod) || ModuleHelper.IsTMRobot(mod))
  322. {
  323. if (_manualTransfer.GetSingleArmOption(mod) != 2)
  324. PushWaferToReturnQueqe(mod, 0);
  325. if (_manualTransfer.GetSingleArmOption(mod) != 1)
  326. PushWaferToReturnQueqe(mod, 1);
  327. }
  328. else if (ModuleHelper.IsLoadLock(mod))
  329. {
  330. int nSlotNumber = SC.GetValue<int>($"{mod}.SlotNumber");
  331. for (int i = 0; i < nSlotNumber; i++)
  332. {
  333. PushWaferToReturnQueqe(mod, i);
  334. }
  335. }
  336. else
  337. {
  338. PushWaferToReturnQueqe(mod, 0);
  339. }
  340. }
  341. }
  342. if (_returnTaskQueue.Count == 0)
  343. return RState.Failed;
  344. _current_item = _returnTaskQueue.Dequeue();
  345. _manualTransfer.Start(_current_item.SourceModule, _current_item.SourceSlot, _current_item.DestinationModule, _current_item.DestinationSlot);
  346. return RState.Running;
  347. }
  348. public RState Monitor()
  349. {
  350. var ret = _manualTransfer.Monitor();
  351. if (ret == RState.End)
  352. {
  353. if (_returnTaskQueue.Count > 0)
  354. {
  355. _current_item = _returnTaskQueue.Dequeue();
  356. _manualTransfer.Start(_current_item.SourceModule, _current_item.SourceSlot, _current_item.DestinationModule, _current_item.DestinationSlot);
  357. }
  358. else
  359. return RState.End;
  360. }
  361. else if (ret == RState.Failed || ret == RState.Timeout)
  362. {
  363. LOG.Write(eEvent.ERR_ROUTINE_FAILED, ModuleName.System,"Manual Transfer", $"Return Wafer {_current_item.SourceModule}{_current_item.SourceSlot} failed");
  364. return RState.Failed;
  365. }
  366. return RState.Running;
  367. }
  368. public void Abort()
  369. {
  370. }
  371. public void Clear()
  372. {
  373. _returnTaskQueue.Clear();
  374. Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot).ResetTask();
  375. Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot).ResetTask();
  376. }
  377. private void PushWaferToReturnQueqe(ModuleName mod, int nSlot)
  378. {
  379. var wafer = WaferManager.Instance.GetWafer(mod, nSlot);
  380. if (!wafer.IsEmpty)
  381. {
  382. _returnTaskQueue.Enqueue(new MoveItem(mod, nSlot, (ModuleName)wafer.OriginStation, wafer.OriginSlot, Hand.Blade1));
  383. }
  384. }
  385. }
  386. }