SetSpeedRoutine.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  7. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  8. namespace EFEM.RT.Routines
  9. {
  10. public class SetSpeedRoutine : CommonRoutine, IRoutine
  11. {
  12. enum Set
  13. {
  14. H, //No-wafer transfer speed,
  15. M, //With-wafer transfer speed
  16. L, //Low speed
  17. O, //Home speed
  18. B, //Speed in low-speed-area
  19. }
  20. public int Speed = 5;
  21. private SCConfigItem _scItemSpeed;
  22. private SCConfigItem _scItemTimeout;
  23. private int _timeout = 5;
  24. public SetSpeedRoutine(string module, string name)
  25. {
  26. }
  27. public bool Initalize()
  28. {
  29. _scItemTimeout = SC.GetConfigItem(SorterCommon.ScPathName.Robot_TimeLimitRobotHome);
  30. _scItemSpeed = SC.GetConfigItem(SorterCommon.ScPathName.Robot_RobotSpeed);
  31. return true;
  32. }
  33. public void Terminate()
  34. {
  35. }
  36. public Result Start(params object[] objs)
  37. {
  38. Reset();
  39. _timeout = _scItemTimeout.IntValue;
  40. EV.PostMessage(ModuleName.Robot.ToString(), EventEnum.GeneralInfo, string.Format("Set robot speed start.{0}",Speed));
  41. Speed = SC.GetValue<int>(SorterCommon.ScPathName.Robot_RobotSpeed);
  42. return Result.RUN;
  43. }
  44. public Result Monitor()
  45. {
  46. try
  47. {
  48. SetSpeed((int)Set.H, "Set No-wafer transfer speed", SpeedType.H, Speed, _timeout, Notify, Stop);
  49. SetSpeed((int)Set.M, "Set With-wafer transfer speed", SpeedType.M, Speed, _timeout, Notify, Stop);
  50. SetSpeed((int)Set.L, "Set Low speed", SpeedType.L, Speed, _timeout, Notify, Stop);
  51. SetSpeed((int)Set.O, "Set Home speed", SpeedType.O, Speed, _timeout, Notify, Stop);
  52. SetSpeed((int)Set.B, "Set Speed in low-speed-area", SpeedType.B, Speed, _timeout, Notify, Stop);
  53. }
  54. catch (RoutineBreakException)
  55. {
  56. return Result.RUN;
  57. }
  58. catch (RoutineFaildException)
  59. {
  60. return Result.FAIL;
  61. }
  62. EV.PostMessage(ModuleName.Robot.ToString(), EventEnum.GeneralInfo, "Set speed end");
  63. return Result.DONE;
  64. }
  65. public new void Abort()
  66. {
  67. }
  68. protected void SetSpeed(int id, string name, SpeedType type, int speed, int time, Action<string> notify, Action<string> error)
  69. {
  70. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  71. {
  72. notify(name);
  73. string reason = string.Empty;
  74. robot.SetSpeed(new object[] {type.ToString(),speed });
  75. return true;
  76. }, () =>
  77. {
  78. if (robot.RobotState == RobotStateEnum.Idle)
  79. {
  80. return true;
  81. }
  82. return false;
  83. }, time * 1000);
  84. if (ret.Item1)
  85. {
  86. if (ret.Item2 == Result.FAIL)
  87. {
  88. throw (new RoutineFaildException());
  89. }
  90. else if (ret.Item2 == Result.TIMEOUT) //timeout
  91. {
  92. error(String.Format("set speed timeout, than {0} seconds", time));
  93. throw (new RoutineFaildException());
  94. }
  95. else
  96. throw (new RoutineBreakException());
  97. }
  98. }
  99. protected override void Notify(string message)
  100. {
  101. EV.PostMessage(Module, EventEnum.GeneralInfo, String.Format("Set Speed :{0}", message));
  102. }
  103. /// <summary>
  104. /// prepare process failed
  105. /// </summary>
  106. /// <param name="failReason"></param>
  107. /// <param name="reactor"></param>
  108. protected override void Stop(string failReason)
  109. {
  110. string reason = String.Empty;
  111. EV.PostMessage(Module, EventEnum.DefaultWarning, string.Format("Set speed failed:{0}", failReason));
  112. }
  113. }
  114. }