MFPMPlaceRoutine.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 Venus_RT.Modules.PMs;
  12. using MECF.Framework.Common.Schedulers;
  13. using System.Collections.Generic;
  14. namespace Venus_RT.Modules.TM
  15. {
  16. class MFPMPlaceRoutine : ModuleRoutineBase, IRoutine
  17. {
  18. private enum PlaceStep
  19. {
  20. WaitPMReady,
  21. PMPrepare,
  22. ArmExtend,
  23. LiftUpWafer,
  24. PlaceDelay,
  25. ArmRetract,
  26. NotifyDone,
  27. }
  28. private readonly JetTM _JetTM;
  29. private readonly ITransferRobot _robot;
  30. private int _placingTimeout = 120 * 1000;
  31. private int _placeDelayTime = 0;
  32. private ModuleName _targetModule;
  33. private PMEntity _pmModule;
  34. private int _targetSlot;
  35. private Hand _hand;
  36. public MFPMPlaceRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  37. {
  38. _JetTM = tm;
  39. _robot = robot;
  40. Name = "Place to PM";
  41. }
  42. public RState Start(params object[] objs)
  43. {
  44. if (!_robot.IsHomed)
  45. {
  46. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  47. return RState.Failed;
  48. }
  49. var placeItem = (Queue<MoveItem>)objs[0];
  50. _targetModule = placeItem.Peek().DestinationModule;
  51. _targetSlot = placeItem.Peek().DestinationSlot;
  52. _hand = placeItem.Peek().RobotHand;
  53. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  54. {
  55. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  56. }
  57. else
  58. {
  59. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for placing action");
  60. return RState.Failed;
  61. }
  62. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_hand))
  63. {
  64. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as TM Robot Arm: {_hand} has no wafer");
  65. return RState.Failed;
  66. }
  67. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  68. {
  69. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as {_targetModule} Slot {_targetSlot + 1} already has a wafer");
  70. return RState.Failed;
  71. }
  72. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)_hand);
  73. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from TM Robot {_hand} to {_targetModule} {_targetSlot + 1}");
  74. Reset();
  75. _placingTimeout = SC.GetValue<int>("TM.PlaceTimeout") * 1000;
  76. _placeDelayTime = SC.GetValue<int>($"{_targetModule}.PlaceDelayTime");
  77. return Runner.Start(Module, $"Place to {_targetModule}");
  78. }
  79. public RState Monitor()
  80. {
  81. Runner.Wait((int)PlaceStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  82. .Run((int)PlaceStep.PMPrepare, ModulePrepare, IsModulePrepareReady, _delay_60s)
  83. .Run((int)PlaceStep.ArmExtend, ArmExtend, WaitRobotExtendDone, _placingTimeout)
  84. .Run((int)PlaceStep.LiftUpWafer, NotifyPMPlaceWafer, WaitPMWaferLiftUp, _delay_30s)
  85. .Delay((int)PlaceStep.PlaceDelay, _placeDelayTime)
  86. .Run((int)PlaceStep.ArmRetract, ArmRetract, WaitRobotRetractDone, _delay_30s)
  87. .End((int)PlaceStep.NotifyDone, NotifyPMDone, _delay_50ms);
  88. return Runner.Status;
  89. }
  90. private bool ModulePrepare()
  91. {
  92. _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
  93. return true;
  94. }
  95. private bool IsModulePrepareReady()
  96. {
  97. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
  98. }
  99. private bool ArmExtend()
  100. {
  101. return _robot.PlaceExtend(_targetModule, _targetSlot, _hand);
  102. }
  103. private bool ArmRetract()
  104. {
  105. return _robot.PlaceRetract(_targetModule, _targetSlot, _hand);
  106. }
  107. private bool WaitRobotExtendDone()
  108. {
  109. if (_robot.Status == RState.Running)
  110. {
  111. return false;
  112. }
  113. else if (_robot.Status == RState.End)
  114. {
  115. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  116. return true;
  117. }
  118. else
  119. {
  120. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  121. return true;
  122. }
  123. }
  124. private bool NotifyPMPlaceWafer()
  125. {
  126. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  127. return true;
  128. }
  129. private bool WaitPMWaferLiftUp()
  130. {
  131. return _pmModule.Status == PMEntity.PMStatus.Exchange_Ready;
  132. }
  133. private bool WaitRobotRetractDone()
  134. {
  135. if (_robot.Status == RState.Running)
  136. {
  137. return false;
  138. }
  139. else if (_robot.Status == RState.End)
  140. {
  141. return true;
  142. }
  143. else
  144. {
  145. Runner.Stop($"TM Robot Place Retract failed, {_robot.Status}");
  146. return true;
  147. }
  148. }
  149. private bool NotifyPMDone()
  150. {
  151. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  152. return true;
  153. }
  154. public void Abort()
  155. {
  156. _robot.Halt();
  157. }
  158. }
  159. }