MFPMExtendRoutine.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 MFPMExtendRoutine : ModuleRoutineBase, IRoutine
  15. {
  16. private enum ExtendStep
  17. {
  18. ArmExtend,
  19. End,
  20. }
  21. private readonly JetTM _JetTM;
  22. private readonly ITransferRobot _robot;
  23. private int _extendingTimeout = 120 * 1000;
  24. private ModuleName _targetModule;
  25. private PMEntity _pmModule;
  26. int _targetSlot;
  27. Hand _hand;
  28. public MFPMExtendRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  29. {
  30. _JetTM = tm;
  31. _robot = robot;
  32. Name = "Extend to PM";
  33. }
  34. public RState Start(params object[] objs)
  35. {
  36. if (!_robot.IsHomed)
  37. {
  38. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  39. return RState.Failed;
  40. }
  41. _targetModule = (ModuleName)objs[0];
  42. _targetSlot = (int)objs[1];
  43. _hand = (Hand)objs[2];
  44. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  45. {
  46. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  47. }
  48. else
  49. {
  50. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for extending action");
  51. return RState.Failed;
  52. }
  53. if(_pmModule.IsSlitDoorClose)
  54. {
  55. LOG.Write(eEvent.ERR_TM, Module, $"{_targetModule} slit door closed, can not extend robot arm");
  56. return RState.Failed;
  57. }
  58. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand))
  59. {
  60. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as TM Robot Arm: {_hand} already has a wafer");
  61. return RState.Failed;
  62. }
  63. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  64. {
  65. if(WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand))
  66. {
  67. LOG.Write(eEvent.ERR_TM, Module, $"Both {_targetModule} and robot arm {_hand} have wafers");
  68. return RState.Failed;
  69. }
  70. if(_pmModule.LiftPinIsDown)
  71. {
  72. LOG.Write(eEvent.ERR_TM, Module, $"{_targetModule} has a wafer and Lift Pin is down, can not extend robot arm");
  73. return RState.Failed;
  74. }
  75. }
  76. Reset();
  77. _extendingTimeout = SC.GetValue<int>("TM.ExtendTimeout") * 1000;
  78. return Runner.Start(Module, $"Extend to {_targetModule}");
  79. }
  80. public RState Monitor()
  81. {
  82. Runner.Run(ExtendStep.ArmExtend, ArmExtend, WaitRobotExtendDone)
  83. .End(ExtendStep.End, NullFun, _delay_50ms);
  84. return Runner.Status;
  85. }
  86. private bool ArmExtend()
  87. {
  88. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  89. {
  90. return _robot.PickExtend(_targetModule, _targetSlot, _hand);
  91. }
  92. else
  93. {
  94. return _robot.PickExtend(_targetModule, _targetSlot, _hand);
  95. }
  96. }
  97. private bool WaitRobotExtendDone()
  98. {
  99. if (_robot.Status == RState.Running)
  100. {
  101. return false;
  102. }
  103. else if (_robot.Status == RState.End)
  104. {
  105. return true;
  106. }
  107. else
  108. {
  109. Runner.Stop($"TM Robot Arm Extend failed, {_robot.Status}");
  110. return true;
  111. }
  112. }
  113. public void Abort()
  114. {
  115. //_robot.Halt();
  116. }
  117. }
  118. }