EfemSwapRoutine.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using Aitex.Core.RT.Routine;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Sorter.Common;
  4. using CyberX8_RT.Devices;
  5. using MECF.Framework.Common.Jobs;
  6. using MECF.Framework.Common.Routine;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.SubstrateTrackings;
  9. using CyberX8_Core;
  10. using Aitex.Core.RT.Log;
  11. using Aitex.Core.Util;
  12. using MECF.Framework.Common.Schedulers;
  13. using System.Collections.Generic;
  14. using CyberX8_RT.Devices.EFEM;
  15. namespace CyberX8_RT.Modules.EFEM
  16. {
  17. class EfemSwapRoutine : ModuleRoutineBase, IRoutine
  18. {
  19. private enum SwapStep
  20. {
  21. WaitModuleReady,
  22. ModulePrepare,
  23. OpenSlitDoor,
  24. MoveWafer,
  25. WaitMaferMoved,
  26. CloseSlitDoor,
  27. NotifyDone,
  28. }
  29. private readonly EfemBase _efem;
  30. private int _moveTimeout = 20 * 1000;
  31. Queue<MoveItem> _actionList = new Queue<MoveItem>();
  32. MoveItem _currentAction;
  33. private int _actionCount = 0;
  34. private int _autoPumpOptInWafer = 4;
  35. private int _autoPumpOptOutWafer = 0;
  36. private bool _bAutoMode = true;
  37. public EfemSwapRoutine(EfemBase efem) : base(ModuleName.EfemRobot)
  38. {
  39. _efem = efem;
  40. Name = "Swap";
  41. }
  42. public RState Start(params object[] objs)
  43. {
  44. if (!_efem.IsHomed)
  45. {
  46. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, Module, $"EFEM is not homed, please home it first");
  47. return RState.Failed;
  48. }
  49. _actionList.Clear();
  50. foreach (var item in (Queue<MoveItem>)objs[0])
  51. {
  52. _actionList.Enqueue(new MoveItem(item.SourceModule, item.SourceSlot, item.DestinationModule, item.DestinationSlot, item.RobotHand));
  53. }
  54. var firtItem = _actionList.Peek();
  55. _moveTimeout = SC.GetValue<int>("EFEM.MotionTimeout") * 1000;
  56. _autoPumpOptInWafer = SC.GetValue<int>("EFEM.LLAutoPumpInWaferOpt");
  57. _autoPumpOptOutWafer = SC.GetValue<int>("EFEM.LLAutoPumpOutWaferOpt");
  58. _bAutoMode = Singleton<RouteManager>.Instance.IsAutoMode;
  59. _actionCount = _actionList.Count;
  60. return Runner.Start(Module, $"EFEM Swap with");
  61. }
  62. public RState Monitor()
  63. {
  64. Runner.LoopStart(SwapStep.MoveWafer, loopName(), _actionCount, MoveWafer)
  65. .LoopEnd(SwapStep.WaitMaferMoved, NullFun, WaitWaferMoved, _moveTimeout);
  66. return Runner.Status;
  67. }
  68. private bool ModulePrepare()
  69. {
  70. return true;
  71. }
  72. private string loopName()
  73. {
  74. return "EFEM Swap";
  75. }
  76. private bool VerifyWaferExistence(MoveItem item)
  77. {
  78. if (WaferManager.Instance.CheckHasWafer(item.DestinationModule, item.DestinationSlot))
  79. {
  80. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Cannot move wafer as desitination {item.DestinationModule},{item.DestinationSlot} already a wafer: ");
  81. return false;
  82. }
  83. if (WaferManager.Instance.CheckNoWafer(item.SourceModule, item.SourceSlot))
  84. {
  85. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Cannot move wafer as source {item.SourceModule}, {item.SourceSlot} has no wafer");
  86. return false;
  87. }
  88. return true;
  89. }
  90. private bool MoveWafer()
  91. {
  92. if(_actionList.Count <= 0)
  93. {
  94. Runner.Stop("no action");
  95. return true;
  96. }
  97. _currentAction = _actionList.Dequeue();
  98. if (!VerifyWaferExistence(_currentAction))
  99. return false;
  100. var wafer = WaferManager.Instance.GetWafer(_currentAction.SourceModule, _currentAction.SourceSlot);
  101. LOG.Write(eEvent.EV_EFEM_ROBOT, ModuleName.EfemRobot, $"{wafer.WaferOrigin} will be move from {_currentAction.SourceModule} {_currentAction.SourceSlot + 1} to {_currentAction.DestinationModule} {_currentAction.DestinationSlot + 1}");
  102. return false;
  103. }
  104. private bool WaitWaferMoved()
  105. {
  106. if (_efem.Status == RState.Running)
  107. {
  108. return false;
  109. }
  110. else if (_efem.Status == RState.End)
  111. {
  112. WaferManager.Instance.WaferMoved(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
  113. return true;
  114. }
  115. else
  116. {
  117. Runner.Stop($"EFEM Robot moving wafer failed, {_efem.Status}");
  118. return true;
  119. }
  120. }
  121. public void Abort()
  122. {
  123. _efem.Halt();
  124. }
  125. }
  126. }