MFPlaceRoutine.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. namespace Venus_RT.Modules.TM
  12. {
  13. class MFPlaceRoutine : ModuleRoutineBase, IRoutine
  14. {
  15. private enum PlaceStep
  16. {
  17. WaitModuleReady,
  18. ModulePrepare,
  19. OpenSlitDoor,
  20. Placing,
  21. CloseSlitDoor,
  22. NotifyDone,
  23. }
  24. private readonly JetTM _JetTM;
  25. private readonly ITransferRobot _robot;
  26. private int _placingTimeout = 120 * 1000;
  27. private ModuleName _targetModule;
  28. private LLEntity _llModule;
  29. int _targetSlot;
  30. Hand _hand;
  31. public MFPlaceRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TM)
  32. {
  33. _JetTM = tm;
  34. _robot = robot;
  35. Name = "Place";
  36. }
  37. public RState Start(params object[] objs)
  38. {
  39. if (!_robot.IsHomed)
  40. {
  41. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  42. return RState.Failed;
  43. }
  44. _targetModule = (ModuleName)objs[0];
  45. _targetSlot = (int)objs[1];
  46. _hand = (Hand)objs[2];
  47. if (ModuleHelper.IsLoadLock(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  48. {
  49. _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);
  50. }
  51. else
  52. {
  53. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for place action");
  54. return RState.Failed;
  55. }
  56. if (WaferManager.Instance.CheckNoWafer(ModuleName.TM, (int)_hand))
  57. {
  58. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as TM Robot Arm: {_hand} has no wafer");
  59. return RState.Failed;
  60. }
  61. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  62. {
  63. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as {_targetModule} Slot {_targetSlot} already has a wafer");
  64. return RState.Failed;
  65. }
  66. Reset();
  67. _placingTimeout = SC.GetValue<int>($"{Module}.PlaceTimeout") * 1000;
  68. return Runner.Start(Module, Name);
  69. }
  70. public RState Monitor()
  71. {
  72. Runner.Wait((int)PlaceStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  73. .Run((int)PlaceStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  74. .Run((int)PlaceStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen)
  75. .Run((int)PlaceStep.Placing, Placing, WaitPlaceDone)
  76. .Run((int)PlaceStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed)
  77. .End((int)PlaceStep.NotifyDone, NotifyLLDone, _delay_50ms);
  78. return Runner.Status;
  79. }
  80. private bool ModulePrepare()
  81. {
  82. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  83. return true;
  84. }
  85. private bool IsModulePrepareReady()
  86. {
  87. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  88. }
  89. private bool OpenSlitDoor()
  90. {
  91. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  92. }
  93. private bool CloseSlitDoor()
  94. {
  95. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  96. }
  97. private bool IsSlitDoorOpen()
  98. {
  99. if (_targetModule == ModuleName.LLA)
  100. return _JetTM.IsLLASlitDoorOpen;
  101. else
  102. return _JetTM.IsLLBSlitDoorOpen;
  103. }
  104. private bool IsSlitDoorClosed()
  105. {
  106. if (_targetModule == ModuleName.LLA)
  107. return _JetTM.IsLLASlitDoorClosed;
  108. else
  109. return _JetTM.IsLLBSlitDoorClosed;
  110. }
  111. private bool Placing()
  112. {
  113. return _robot.Place(_targetModule, _targetSlot, _hand);
  114. }
  115. private bool WaitPlaceDone()
  116. {
  117. if (_robot.Status == RState.Running)
  118. {
  119. return false;
  120. }
  121. else if (_robot.Status == RState.End)
  122. {
  123. WaferManager.Instance.WaferMoved(ModuleName.TM, (int)_hand, _targetModule, _targetSlot);
  124. return true;
  125. }
  126. else
  127. {
  128. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  129. return true;
  130. }
  131. }
  132. private bool NotifyLLDone()
  133. {
  134. _llModule.PostMsg(LLEntity.MSG.TM_Exchange_Ready);
  135. return true;
  136. }
  137. public void Abort()
  138. {
  139. _robot.Halt();
  140. }
  141. }
  142. }