EfemPlaceRoutine.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. _targetModule = placeItem.Peek().DestinationModule;
  48. _targetSlot = placeItem.Peek().DestinationSlot;
  49. _hand = placeItem.Peek().RobotHand;
  50. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand))
  51. {
  52. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Efem robot arm{_hand} already has no wafer, cannot do the place action");
  53. return RState.Failed;
  54. }
  55. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  56. {
  57. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"The target: {_targetModule}{_targetSlot} has a wafer, cannot do the place action");
  58. return RState.Failed;
  59. }
  60. if (placeItem.Count >= 2)
  61. {
  62. placeItem.Dequeue();
  63. _targetModule2 = placeItem.Peek().DestinationModule;
  64. if (!ModuleHelper.IsLoadPort(_targetModule2))
  65. {
  66. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Wrong double place command, target is not loadport");
  67. return RState.Failed;
  68. }
  69. _hand2 = _hand != Hand.Blade1 ? Hand.Blade1 : Hand.Blade2;
  70. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand2))
  71. {
  72. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Efem robot arm{_hand2} has no wafer, cannot do the double place action");
  73. return RState.Failed;
  74. }
  75. _targetSlot2 = placeItem.ToArray()[0].DestinationSlot;
  76. if (WaferManager.Instance.CheckHasWafer(_targetModule2, _targetSlot2))
  77. {
  78. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"The target: {_targetModule2} {_targetSlot2} has a wafer, cannot do the double place action");
  79. return RState.Failed;
  80. }
  81. _bDoublePlace = true;
  82. }
  83. _moveTimeout = SC.GetValue<int>($"EFEM.MotionTimeout") * 1000;
  84. string targetModule2 = "";
  85. if (_targetModule2 != ModuleName.System)
  86. {
  87. targetModule2 = _targetModule2.ToString();
  88. }
  89. return Runner.Start(Module, $"Place to {_targetModule} {targetModule2}");
  90. }
  91. public RState Monitor()
  92. {
  93. if (_bDoublePlace)
  94. {
  95. Runner.Wait(PlaceStep.WaitModuleReady, WaitModuleReady)
  96. .Run(PlaceStep.Placing1, Place1, Place1Done, _moveTimeout)
  97. .Run(PlaceStep.Placing2, Place2, Place2Done, _moveTimeout)
  98. .End(PlaceStep.End, ActionDone);
  99. }
  100. else
  101. {
  102. Runner.Wait(PlaceStep.WaitModuleReady, WaitModuleReady)
  103. .Run(PlaceStep.Placing1, Place1, Place1Done, _moveTimeout)
  104. .End(PlaceStep.End, ActionDone);
  105. }
  106. return Runner.Status;
  107. }
  108. public void Abort()
  109. {
  110. _efem.Halt();
  111. }
  112. private bool WaitModuleReady()
  113. {
  114. return true;
  115. }
  116. private bool Place1()
  117. {
  118. return _efem.Place(_targetModule, _targetSlot, _hand);
  119. }
  120. private bool Place1Done()
  121. {
  122. if (_efem.Status == RState.End)
  123. {
  124. WaferManager.Instance.WaferMoved(ModuleName.EfemRobot, (int)_hand, _targetModule, _targetSlot);
  125. return true;
  126. }
  127. else if (_efem.Status != RState.Running)
  128. {
  129. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Efem robot place failed: {_efem.Status}");
  130. return true;
  131. }
  132. return false;
  133. }
  134. private bool Place2()
  135. {
  136. return _efem.Place(_targetModule2, _targetSlot2, _hand2);
  137. }
  138. private bool Place2Done()
  139. {
  140. if (_efem.Status == RState.End)
  141. {
  142. WaferManager.Instance.WaferMoved(ModuleName.EfemRobot, (int)_hand2, _targetModule2, _targetSlot2);
  143. return true;
  144. }
  145. else if (_efem.Status != RState.Running)
  146. {
  147. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Efem robot place failed: {_efem.Status}");
  148. return true;
  149. }
  150. return false;
  151. }
  152. private bool ActionDone()
  153. {
  154. return true;
  155. }
  156. }
  157. }