MFPlaceRoutine.cs 5.1 KB

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