EfemGotoRoutine.cs 3.7 KB

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