MFPMPlaceRoutine.cs 5.3 KB

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