EfemPlaceRoutine.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using Aitex.Core.RT.Routine;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Sorter.Common;
  4. using Venus_RT.Devices;
  5. using MECF.Framework.Common.Routine;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.SubstrateTrackings;
  8. using Venus_Core;
  9. using Aitex.Core.RT.Log;
  10. using Aitex.Core.Util;
  11. using MECF.Framework.Common.Schedulers;
  12. using System.Collections.Generic;
  13. using Venus_RT.Devices.EFEM;
  14. namespace Venus_RT.Modules.EFEM
  15. {
  16. class EfemPlaceRoutine : ModuleRoutineBase, IRoutine
  17. {
  18. private enum PlaceStep
  19. {
  20. WaitModuleReady,
  21. Placing1,
  22. Placing2,
  23. End,
  24. }
  25. private int _moveTimeout = 20 * 1000;
  26. private ModuleName _targetModule = ModuleName.System;
  27. private ModuleName _targetModule2 = ModuleName.System;
  28. int _targetSlot;
  29. int _targetSlot2;
  30. Hand _hand;
  31. Hand _hand2;
  32. EfemBase _efem;
  33. bool _bDoublePlace = false;
  34. public EfemPlaceRoutine(EfemBase efem) : base(ModuleName.EfemRobot)
  35. {
  36. _efem = efem;
  37. }
  38. public RState Start(params object[] objs)
  39. {
  40. if (!_efem.IsHomed)
  41. {
  42. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"EFEM is not homed, please home it first");
  43. return RState.Failed;
  44. }
  45. _bDoublePlace = false;
  46. var placeItem = (Queue<MoveItem>)objs[0];
  47. if (!WaferManager.Instance.CheckDuplicatedWafersBeforeMove(placeItem))
  48. return RState.Failed;
  49. _targetModule = placeItem.Peek().DestinationModule;
  50. _targetSlot = placeItem.Peek().DestinationSlot;
  51. _hand = placeItem.Peek().RobotHand;
  52. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand))
  53. {
  54. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Efem robot arm{_hand} already has no wafer, cannot do the place action");
  55. return RState.Failed;
  56. }
  57. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  58. {
  59. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"The target: {_targetModule}{_targetSlot} has a wafer, cannot do the place action");
  60. return RState.Failed;
  61. }
  62. if (placeItem.Count >= 2)
  63. {
  64. placeItem.Dequeue();
  65. _targetModule2 = placeItem.Peek().DestinationModule;
  66. if (!ModuleHelper.IsLoadPort(_targetModule2))
  67. {
  68. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Wrong double place command, target is not loadport");
  69. return RState.Failed;
  70. }
  71. _hand2 = _hand != Hand.Blade1 ? Hand.Blade1 : Hand.Blade2;
  72. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand2))
  73. {
  74. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Efem robot arm{_hand2} has no wafer, cannot do the double place action");
  75. return RState.Failed;
  76. }
  77. _targetSlot2 = placeItem.ToArray()[0].DestinationSlot;
  78. if (WaferManager.Instance.CheckHasWafer(_targetModule2, _targetSlot2))
  79. {
  80. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"The target: {_targetModule2} {_targetSlot2} has a wafer, cannot do the double place action");
  81. return RState.Failed;
  82. }
  83. _bDoublePlace = true;
  84. }
  85. _moveTimeout = SC.GetValue<int>($"EFEM.MotionTimeout") * 1000;
  86. string targetModule2 = "";
  87. if (_targetModule2 != ModuleName.System)
  88. {
  89. targetModule2 = _targetModule2.ToString();
  90. }
  91. return Runner.Start(Module, $"Place to {_targetModule} {targetModule2}");
  92. }
  93. public RState Monitor()
  94. {
  95. if (_bDoublePlace)
  96. {
  97. Runner.Wait(PlaceStep.WaitModuleReady, WaitModuleReady)
  98. .Run(PlaceStep.Placing1, Place1, Place1Done, _moveTimeout)
  99. .Run(PlaceStep.Placing2, Place2, Place2Done, _moveTimeout)
  100. .End(PlaceStep.End, ActionDone);
  101. }
  102. else
  103. {
  104. Runner.Wait(PlaceStep.WaitModuleReady, WaitModuleReady)
  105. .Run(PlaceStep.Placing1, Place1, Place1Done, _moveTimeout)
  106. .End(PlaceStep.End, ActionDone);
  107. }
  108. return Runner.Status;
  109. }
  110. public void Abort()
  111. {
  112. _efem.Halt();
  113. }
  114. private bool WaitModuleReady()
  115. {
  116. return true;
  117. }
  118. private bool Place1()
  119. {
  120. return _efem.Place(_targetModule, _targetSlot, _hand);
  121. }
  122. private bool Place1Done()
  123. {
  124. if (_efem.Status == RState.End)
  125. {
  126. WaferManager.Instance.WaferMoved(ModuleName.EfemRobot, (int)_hand, _targetModule, _targetSlot);
  127. return true;
  128. }
  129. else if (_efem.Status != RState.Running)
  130. {
  131. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Efem robot place failed: {_efem.Status}");
  132. return true;
  133. }
  134. return false;
  135. }
  136. private bool Place2()
  137. {
  138. return _efem.Place(_targetModule2, _targetSlot2, _hand2);
  139. }
  140. private bool Place2Done()
  141. {
  142. if (_efem.Status == RState.End)
  143. {
  144. WaferManager.Instance.WaferMoved(ModuleName.EfemRobot, (int)_hand2, _targetModule2, _targetSlot2);
  145. return true;
  146. }
  147. else if (_efem.Status != RState.Running)
  148. {
  149. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Efem robot place failed: {_efem.Status}");
  150. return true;
  151. }
  152. return false;
  153. }
  154. private bool ActionDone()
  155. {
  156. return true;
  157. }
  158. }
  159. }