HomeRoutine.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using athosRT.Devices;
  6. using athosRT.FSM;
  7. using athosRT.tool;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  10. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  11. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  12. using MECF.Framework.RT.EquipmentLibrary.LogicUnits;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Diagnostics;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. namespace athosRT.Modules.LPs
  20. {
  21. public class HomeRoutine : ModuleRoutineBase, FSM.IRoutine
  22. {
  23. int _timeout = -1;
  24. protected readonly ModuleName _chamber;
  25. private RobotBaseDevice _robot;
  26. private LoadPortBaseDevice _device = null;
  27. private string _reason = string.Empty;
  28. public HomeRoutine(ModuleName chamber, RobotBaseDevice robot) : base(chamber)
  29. {
  30. _chamber = chamber;
  31. _robot = robot;
  32. _timeout = 3000;
  33. }
  34. public void Abort()
  35. {
  36. }
  37. public RState Monitor()
  38. {
  39. Runner.Run(HomeStep.LoadportReset, LoadportReset, WaitLoadportReset, _timeout)
  40. .End(HomeStep.LoadportInit, LoadportInit, LoadportMotion, _timeout);
  41. //.Wait((int)HomeStep.LoadportMotion, LoadportMotion, _timeout)
  42. //.End((int)HomeStep.WaitLoadportMotion, WaitLoadportMotion, _timeout);
  43. return Runner.Status;
  44. }
  45. //private bool test1()
  46. //{
  47. // Trace.WriteLine("ceshi");
  48. // return true;
  49. //}
  50. public RState Start(params object[] objs)
  51. {
  52. Trace.WriteLine("执行home start");
  53. _device = DEVICE.GetDevice<LoadPortBaseDevice>(this._chamber.ToString());
  54. string reason = string.Empty;
  55. if (SC.GetValue<bool>("System.LPRobotActionIntervene") && !this.CheckLoadportMotionInterlock())
  56. {
  57. //EV.PostMessage<EventEnum>(this._chamber.ToString(), EventEnum.HomeFailed, (object)reason);
  58. return RState.Failed;
  59. }
  60. if (_chamber == ModuleName.LP1)
  61. {
  62. if (DeviceModel.SensorRBNotExtendSIMF1 != null && DeviceModel.SensorRBNotExtendSIMF1.Value)
  63. LogObject.Info(GetName.GetCurrentName(), "robot Extend to LP1.");
  64. //EV.PostMessage<EventEnum>(this._chamber.ToString(), EventEnum.DefaultWarning, (object)"robot Extend to LP1.");
  65. }
  66. else if (DeviceModel.SensorRBNotExtendSIMF2 != null && DeviceModel.SensorRBNotExtendSIMF2.Value)
  67. LogObject.Info(GetName.GetCurrentName(), "robot Extend to LP2.");
  68. //EV.PostMessage<EventEnum>(this._chamber.ToString(), EventEnum.DefaultWarning, (object)"robot Extend to LP2.");
  69. Trace.WriteLine("执行home start结束");
  70. return Runner.Start(ModuleName.LP1, "LP1");
  71. }
  72. public bool LoadportReset(){
  73. LogObject.Info("LP Home", "LoadportReset");
  74. LogObject.Info("LP",$"{_device.Name} clear error");
  75. bool flag = _device.LoadportReset(out _);
  76. Trace.WriteLine($"执行Home{flag}");
  77. return flag;
  78. }
  79. public bool LoadportInit() => _device.Home(out _reason);
  80. public bool LoadportMotion()
  81. {
  82. Trace.WriteLine("LoadportMotion");
  83. if (_device.CurrentState == LoadPortStateEnum.Error || !_device.IsReady())
  84. {
  85. Trace.WriteLine("1" + Runner.Status + " 2" + _device.CurrentState + " 3" + _device.IsReady());
  86. return false;
  87. }
  88. return true;
  89. }
  90. public bool WaitLoadportMotion() {
  91. Trace.WriteLine("WaitLoadportMotion");
  92. return true;
  93. }
  94. public bool WaitLoadportReset() => _device.IsReady();
  95. public enum HomeStep
  96. {
  97. LoadportReset,
  98. WaitLoadportReset,
  99. LoadportInit,
  100. LoadportMotion,
  101. WaitLoadportMotion
  102. }
  103. public bool CheckLoadportMotionInterlock()
  104. {
  105. if (_robot.RobotState != RobotStateEnum.Idle)
  106. {
  107. LogObject.Info("LP and robot", "robot非空闲状态");
  108. return false;
  109. }
  110. if (_robot.IsReady())
  111. {
  112. LogObject.Info("LP and robot", "robot准备好");
  113. return true;
  114. }
  115. return false;
  116. //return true;
  117. }
  118. }
  119. }