EfemGotoRoutine.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 JetEfemLib.Efems
  7. {
  8. public class EfemGotoRoutine : ModuleRoutineBase, IStepRoutine
  9. {
  10. enum RoutineStep
  11. {
  12. CheckBeforeGoto,
  13. RobotGoto,
  14. End,
  15. }
  16. private int _gotoTimeout;
  17. private ModuleName _source;
  18. private int _sourceSlot;
  19. private Hand _hand;
  20. private EfemModule _robotModule;
  21. public EfemGotoRoutine(EfemModule robotModule) : base("EfemRobot")
  22. {
  23. Name = "Goto";
  24. _robotModule = robotModule;
  25. }
  26. public RState 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 Runner.Start("EfemRobot", Name);
  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 RState Monitor()
  44. {
  45. Runner.Run(RoutineStep.CheckBeforeGoto, BeforeGoto, NullFun, _gotoTimeout * 1000)
  46. .Run(RoutineStep.RobotGoto, RobotGoto, CheckRobotGoto, _gotoTimeout * 1000)
  47. .End(RoutineStep.End, NullFun, _delay_1s);
  48. if(Runner.Status == RState.End)
  49. Notify($"Finish, robot move to {_source} slot {_sourceSlot + 1}, by {_hand}");
  50. return Runner.Status;
  51. }
  52. public bool BeforeGoto()
  53. {
  54. Notify("Check robot goto motion is enabled");
  55. string reason = string.Empty;
  56. return true;
  57. }
  58. public bool RobotGoto()
  59. {
  60. Notify("robot execute goto command");
  61. string reason;
  62. if (!_robotModule.RobotDevice.Goto(_source, _hand, _sourceSlot, out reason))
  63. {
  64. Stop(reason);
  65. return false;
  66. }
  67. return true;
  68. }
  69. bool CheckRobotGoto()
  70. {
  71. return !_robotModule.RobotDevice.IsError && _robotModule.RobotDevice.IsIdle;
  72. }
  73. }
  74. }