MFPMPickRoutine.cs 5.5 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 MFPMPickRoutine : ModuleRoutineBase, IRoutine
  17. {
  18. private enum PickStep
  19. {
  20. WaitPMReady,
  21. PMPrepare,
  22. ArmExtend,
  23. DropDownWafer,
  24. ArmRetract,
  25. NotifyDone,
  26. }
  27. private readonly JetTM _JetTM;
  28. private readonly ITransferRobot _robot;
  29. private int _pickingTimeout = 120 * 1000;
  30. private ModuleName _targetModule;
  31. private PMEntity _pmModule;
  32. int _targetSlot;
  33. Hand _hand;
  34. public MFPMPickRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TM)
  35. {
  36. _JetTM = tm;
  37. _robot = robot;
  38. Name = "Pick from 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 pickItem = (Queue<MoveItem>)objs[0];
  48. _targetModule = pickItem.Peek().SourceModule;
  49. _targetSlot = pickItem.Peek().SourceSlot;
  50. _hand = pickItem.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 picking action");
  58. return RState.Failed;
  59. }
  60. if (WaferManager.Instance.CheckHasWafer(ModuleName.TM, (int)_hand))
  61. {
  62. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as TM Robot Arm: {_hand} already has a wafer");
  63. return RState.Failed;
  64. }
  65. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  66. {
  67. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as {_targetModule} Slot {_targetSlot} has no wafer");
  68. return RState.Failed;
  69. }
  70. var wafer = WaferManager.Instance.GetWafer(_targetModule, _targetSlot);
  71. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TM, $"{wafer.WaferOrigin} will be move from {_targetModule} {_targetSlot + 1} to TM Robot {_hand}");
  72. Reset();
  73. _pickingTimeout = SC.GetValue<int>($"{Module}.PickTimeout") * 1000;
  74. return Runner.Start(Module, $"Pick from {_targetModule}");
  75. }
  76. public RState Monitor()
  77. {
  78. Runner.Wait((int)PickStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  79. .Run((int)PickStep.PMPrepare, ModulePrepare, IsModulePrepareReady)
  80. .Run((int)PickStep.ArmExtend, ArmExtend, WaitRobotExtendDone)
  81. .Run((int)PickStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
  82. .Run((int)PickStep.ArmRetract, ArmRetract, WaitRobotRetractDone)
  83. .End((int)PickStep.NotifyDone, NotifyPMDone, _delay_50ms);
  84. return Runner.Status;
  85. }
  86. private bool ModulePrepare()
  87. {
  88. _pmModule.PostMsg(PMEntity.MSG.PreparePick);
  89. return true;
  90. }
  91. private bool IsModulePrepareReady()
  92. {
  93. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick && _pmModule.IsSlitDoorOpen;
  94. }
  95. private bool ArmExtend()
  96. {
  97. return _robot.PickExtend(_targetModule, _targetSlot, _hand);
  98. }
  99. private bool ArmRetract()
  100. {
  101. return _robot.PickRetract(_targetModule, _targetSlot, _hand);
  102. }
  103. private bool WaitRobotExtendDone()
  104. {
  105. if (_robot.Status == RState.Running)
  106. {
  107. return false;
  108. }
  109. else if (_robot.Status == RState.End)
  110. {
  111. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TM, (int)_hand);
  112. return true;
  113. }
  114. else
  115. {
  116. Runner.Stop($"TM Robot Pick Extend failed, {_robot.Status}");
  117. return true;
  118. }
  119. }
  120. private bool NotifyPMPickWafer()
  121. {
  122. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  123. return true;
  124. }
  125. private bool WaitPMWaferDropDown()
  126. {
  127. return _pmModule.Status == PMEntity.PMStatus.Exchange_Ready;
  128. }
  129. private bool WaitRobotRetractDone()
  130. {
  131. if (_robot.Status == RState.Running)
  132. {
  133. return false;
  134. }
  135. else if (_robot.Status == RState.End)
  136. {
  137. return true;
  138. }
  139. else
  140. {
  141. Runner.Stop($"TM Robot Pick Retract failed, {_robot.Status}");
  142. return true;
  143. }
  144. }
  145. private bool NotifyPMDone()
  146. {
  147. _pmModule.PostMsg(PMEntity.MSG.PickReady);
  148. return true;
  149. }
  150. public void Abort()
  151. {
  152. _robot.Halt();
  153. }
  154. }
  155. }