TMGotoRoutine.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using System;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Device.Unit;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.Routine;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Sorter.Common;
  8. using MECF.Framework.Common.Equipment;
  9. namespace JetMainframe.TMs
  10. {
  11. public class TMGotoRoutine : ModuleRoutine, IRoutine
  12. {
  13. enum RoutineStep
  14. {
  15. CheckBeforeGoto,
  16. RobotGoto,
  17. }
  18. private int _gotoTimeout;
  19. private ModuleName _source;
  20. private int _sourceSlot;
  21. private Hand _hand;
  22. private TMModule _robotModule;
  23. public TMGotoRoutine(TMModule robotModule)
  24. {
  25. Module = "TM";
  26. Name = "Goto";
  27. _robotModule = robotModule;
  28. }
  29. public Result Start(params object[] objs)
  30. {
  31. _gotoTimeout = SC.GetValue<int>("TM.TMRobot.GotoTimeout");
  32. Reset();
  33. if (!DEVICE.GetDevice<IoSensor>($"System.SensorTMInSafety").Value)
  34. {
  35. EV.PostAlarmLog(Module, $"Can not Goto, Sensor TMInSafety is false");
  36. return Result.FAIL;
  37. }
  38. if (_source == ModuleName.LLA && DEVICE.GetDevice<IoSensor>($"System.SensorBufferABigWaferProtrusion").Value)
  39. {
  40. EV.PostAlarmLog(Module, $"Can not Goto, Sensor BufferABigWaferProtrusion is false");
  41. return Result.FAIL;
  42. }
  43. if (_source == ModuleName.LLB && DEVICE.GetDevice<IoSensor>($"System.SensorBufferBBigWaferProtrusion").Value)
  44. {
  45. EV.PostAlarmLog(Module, $"Can not Goto, Sensor BufferBBigWaferProtrusion is false");
  46. return Result.FAIL;
  47. }
  48. Notify($"Start, Goto {_source} slot {_sourceSlot + 1}, by {_hand}");
  49. return Result.RUN;
  50. }
  51. public void Init(ModuleName source, int slot, Hand hand)
  52. {
  53. _source = source;
  54. _sourceSlot = slot;
  55. _hand = hand;
  56. }
  57. public void Abort()
  58. {
  59. Notify("Abort");
  60. }
  61. public Result Monitor()
  62. {
  63. try
  64. {
  65. CheckBeforeGoto((int)RoutineStep.CheckBeforeGoto, _source, _sourceSlot, _hand);
  66. RobotGoto((int)RoutineStep.RobotGoto, _source, _sourceSlot, _hand, _gotoTimeout);
  67. }
  68. catch (RoutineBreakException)
  69. {
  70. return Result.RUN;
  71. }
  72. catch (RoutineFaildException)
  73. {
  74. return Result.FAIL;
  75. }
  76. Notify($"Finish, robot move to {_source} slot {_sourceSlot + 1}, by {_hand}");
  77. return Result.DONE;
  78. }
  79. public void CheckBeforeGoto(int id, ModuleName source, int slot, Hand blade)
  80. {
  81. Tuple<bool, Result> ret = Execute(id, () =>
  82. {
  83. Notify("Check robot goto motion is enabled");
  84. string reason = string.Empty;
  85. return true;
  86. });
  87. if (ret.Item1)
  88. {
  89. if (ret.Item2 == Result.FAIL)
  90. {
  91. throw new RoutineFaildException();
  92. }
  93. }
  94. }
  95. public void RobotGoto(int id, ModuleName chamber, int slot, Hand hand, int timeout)
  96. {
  97. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  98. {
  99. Notify("robot execute goto command");
  100. string reason;
  101. if (!_robotModule.RobotDevice.Goto(chamber, hand, slot, out reason))
  102. {
  103. Stop(reason);
  104. return false;
  105. }
  106. return true;
  107. }, () =>
  108. {
  109. if (_robotModule.RobotDevice.IsError)
  110. return null;
  111. if (_robotModule.RobotDevice.IsIdle)
  112. return true;
  113. return false;
  114. }, timeout * 1000);
  115. if (ret.Item1)
  116. {
  117. if (ret.Item2 == Result.FAIL)
  118. {
  119. Stop(string.Format("failed."));
  120. throw new RoutineFaildException();
  121. }
  122. else if (ret.Item2 == Result.TIMEOUT) //timeout
  123. {
  124. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  125. throw new RoutineFaildException();
  126. }
  127. else
  128. throw new RoutineBreakException();
  129. }
  130. }
  131. }
  132. }