EfemPlaceRoutine.cs 5.6 KB

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