PMHomeRoutine.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using Aitex.Core.RT.Routine;
  3. using VirgoRT.Devices;
  4. using VirgoCommon;
  5. using Aitex.Core.RT.Event;
  6. namespace VirgoRT.Modules.PMs
  7. {
  8. class PMHomeRoutine : PMRoutineBase, IRoutine
  9. {
  10. enum RoutineStep
  11. {
  12. LiftPinOrig,
  13. ResetPlcSignal,
  14. ResetPlcSignalDelay,
  15. Home,
  16. }
  17. public PMHomeRoutine(JetPM chamber) : base(chamber)
  18. {
  19. Name = "Homing";
  20. }
  21. public Result Init()
  22. {
  23. return Result.DONE;
  24. }
  25. public Result Start(params object[] objs)
  26. {
  27. Reset();
  28. if(_chamber.CheckLiftPinBusy())
  29. {
  30. EV.PostAlarmLog(Module, $"[{Name}] routine failed, the servo lift pin is busy now");
  31. return Result.FAIL;
  32. }
  33. Notify("Start");
  34. return Result.RUN;
  35. }
  36. public Result Monitor()
  37. {
  38. try
  39. {
  40. if (_chamber != null && _chamber.IsInstalled)
  41. {
  42. ResetPlcSignal((int)RoutineStep.ResetPlcSignal, 10);
  43. TimeDelay((int)RoutineStep.ResetPlcSignalDelay, 6);
  44. SetLiftPinPos((int)RoutineStep.LiftPinOrig, MovementPosition.Origin, 200);
  45. Home((int)RoutineStep.Home, 20);
  46. }
  47. }
  48. catch (RoutineBreakException)
  49. {
  50. return Result.RUN;
  51. }
  52. catch (RoutineFaildException)
  53. {
  54. Stop("Error");
  55. return Result.FAIL;
  56. }
  57. catch (Exception ex)
  58. {
  59. Stop(ex.Message);
  60. return Result.FAIL;
  61. }
  62. Notify("Finish");
  63. return Result.DONE;
  64. }
  65. public override void Abort()
  66. {
  67. }
  68. public void ResetPlcSignal(int id, int timeout)
  69. {
  70. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  71. {
  72. Notify($"Run {_chamber.Name} ResetPlcSignal");
  73. _chamber.ResetPlcSignal();
  74. return true;
  75. }, () => true, timeout * 1000);
  76. if (ret.Item1)
  77. {
  78. if (ret.Item2 == Result.FAIL)
  79. {
  80. Stop($"{_chamber.Name} ResetPlcSignal error");
  81. throw new RoutineFaildException();
  82. }
  83. else if (ret.Item2 == Result.TIMEOUT) //timeout
  84. {
  85. Stop($"ResetPlcSignal timeout, over {timeout} seconds");
  86. throw new RoutineFaildException();
  87. }
  88. else
  89. throw new RoutineBreakException();
  90. }
  91. }
  92. public void Home(int id, int timeout)
  93. {
  94. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  95. {
  96. Notify($"Run {_chamber.Name} home");
  97. _chamber.Home();
  98. return true;
  99. }, ()=> true, timeout * 1000);
  100. if (ret.Item1)
  101. {
  102. if (ret.Item2 == Result.FAIL)
  103. {
  104. Stop($"{_chamber.Name} home error");
  105. throw new RoutineFaildException();
  106. }
  107. else if (ret.Item2 == Result.TIMEOUT) //timeout
  108. {
  109. Stop($"home timeout, over {timeout} seconds");
  110. throw new RoutineFaildException();
  111. }
  112. else
  113. throw new RoutineBreakException();
  114. }
  115. }
  116. }
  117. }