MFPMPickRoutine.cs 5.1 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. namespace Venus_RT.Modules.TM
  13. {
  14. class MFPMPickRoutine : ModuleRoutineBase, IRoutine
  15. {
  16. private enum PickStep
  17. {
  18. WaitPMReady,
  19. PMPrepare,
  20. ArmExtend,
  21. DropDownWafer,
  22. ArmRetract,
  23. NotifyDone,
  24. }
  25. private readonly JetTM _JetTM;
  26. private readonly ITransferRobot _robot;
  27. private int _pickingTimeout = 120 * 1000;
  28. private ModuleName _targetModule;
  29. private PMEntity _pmModule;
  30. int _targetSlot;
  31. Hand _hand;
  32. public MFPMPickRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TM)
  33. {
  34. _JetTM = tm;
  35. _robot = robot;
  36. Name = "Pick from PM";
  37. }
  38. public RState Start(params object[] objs)
  39. {
  40. if (!_robot.IsHomed)
  41. {
  42. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  43. return RState.Failed;
  44. }
  45. _targetModule = (ModuleName)objs[0];
  46. _targetSlot = (int)objs[1];
  47. _hand = (Hand)objs[2];
  48. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  49. {
  50. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  51. }
  52. else
  53. {
  54. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for picking action");
  55. return RState.Failed;
  56. }
  57. if (WaferManager.Instance.CheckHasWafer(ModuleName.TM, (int)_hand))
  58. {
  59. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as TM Robot Arm: {_hand} already has a wafer");
  60. return RState.Failed;
  61. }
  62. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  63. {
  64. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as {_targetModule} Slot {_targetSlot} has no wafer");
  65. return RState.Failed;
  66. }
  67. Reset();
  68. _pickingTimeout = SC.GetValue<int>($"{Module}.PickTimeout") * 1000;
  69. return Runner.Start(Module, Name);
  70. }
  71. public RState Monitor()
  72. {
  73. Runner.Wait((int)PickStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  74. .Run((int)PickStep.PMPrepare, ModulePrepare, IsModulePrepareReady)
  75. .Run((int)PickStep.ArmExtend, ArmExtend, WaitRobotExtendDone)
  76. .Run((int)PickStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
  77. .Run((int)PickStep.ArmRetract, ArmRetract, WaitRobotRetractDone)
  78. .End((int)PickStep.NotifyDone, NotifyPMDone, _delay_50ms);
  79. return Runner.Status;
  80. }
  81. private bool ModulePrepare()
  82. {
  83. _pmModule.PostMsg(PMEntity.MSG.PreparePick);
  84. return true;
  85. }
  86. private bool IsModulePrepareReady()
  87. {
  88. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick && _pmModule.IsSlitDoorOpen;
  89. }
  90. private bool ArmExtend()
  91. {
  92. return _robot.PickExtend(_targetModule, _targetSlot, _hand);
  93. }
  94. private bool ArmRetract()
  95. {
  96. return _robot.PickRetract(_targetModule, _targetSlot, _hand);
  97. }
  98. private bool WaitRobotExtendDone()
  99. {
  100. if (_robot.Status == RState.Running)
  101. {
  102. return false;
  103. }
  104. else if (_robot.Status == RState.End)
  105. {
  106. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TM, (int)_hand);
  107. return true;
  108. }
  109. else
  110. {
  111. Runner.Stop($"TM Robot Pick Extend failed, {_robot.Status}");
  112. return true;
  113. }
  114. }
  115. private bool NotifyPMPickWafer()
  116. {
  117. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  118. return true;
  119. }
  120. private bool WaitPMWaferDropDown()
  121. {
  122. return _pmModule.Status == PMEntity.PMStatus.Exchange_Ready;
  123. }
  124. private bool WaitRobotRetractDone()
  125. {
  126. if (_robot.Status == RState.Running)
  127. {
  128. return false;
  129. }
  130. else if (_robot.Status == RState.End)
  131. {
  132. return true;
  133. }
  134. else
  135. {
  136. Runner.Stop($"TM Robot Pick Retract failed, {_robot.Status}");
  137. return true;
  138. }
  139. }
  140. private bool NotifyPMDone()
  141. {
  142. _pmModule.PostMsg(PMEntity.MSG.PickReady);
  143. return true;
  144. }
  145. public void Abort()
  146. {
  147. _robot.Halt();
  148. }
  149. }
  150. }