TransporterRetractRoutine.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.IOCore;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using MECF.Framework.Common.Beckhoff.ModuleIO;
  6. using MECF.Framework.Common.Routine;
  7. using MECF.Framework.Common.TwinCat;
  8. using CyberX8_Core;
  9. using CyberX8_RT.Devices.Loader;
  10. using CyberX8_RT.Devices.TransPorter;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using Aitex.Core.RT.Log;
  17. using MECF.Framework.Common.IOCore;
  18. namespace CyberX8_RT.Devices.AXIS.CANOpen
  19. {
  20. public class TransporterRetractRoutine : RoutineBase, IRoutine
  21. {
  22. private enum RetractStep
  23. {
  24. CheckInUpPosition,
  25. WriteRetract,
  26. End
  27. }
  28. #region 常量
  29. private const string IMMOBILIZE_ACTIVE = "ImmobilizeActive";
  30. private const string IMMOBILIZE_ACTIVE2 = "ImmobilizeActive2";
  31. #endregion
  32. #region 内部变量
  33. private int _timeout = 5000;
  34. private TransporterCommon _transporterCommon;
  35. #endregion
  36. /// <summary>
  37. /// 构造函数
  38. /// </summary>
  39. /// <param name="module"></param>
  40. public TransporterRetractRoutine(string module) : base(module)
  41. {
  42. if (SC.ContainsItem($"Transporter.{module}.RetractCheckTime"))
  43. {
  44. _timeout = SC.GetValue<int>($"Transporter.{module}.RetractCheckTime") * 1000;
  45. }
  46. }
  47. /// <summary>
  48. /// 中止
  49. /// </summary>
  50. public void Abort()
  51. {
  52. Runner.Stop("Manual Abort");
  53. }
  54. /// <summary>
  55. /// 监控
  56. /// </summary>
  57. /// <returns></returns>
  58. public RState Monitor()
  59. {
  60. Runner.Run(RetractStep.CheckInUpPosition, CheckPosition, _delay_1ms)
  61. .Run(RetractStep.WriteRetract, WriteRetract, CheckRetract,_timeout)
  62. .End(RetractStep.End,NullFun,100);
  63. return Runner.Status;
  64. }
  65. /// <summary>
  66. /// 检查Elevate当前是否在UP Place
  67. /// </summary>
  68. /// <returns></returns>
  69. private bool CheckPosition()
  70. {
  71. JetAxisBase elevatorAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Elevator");
  72. if (elevatorAxis != null && !elevatorAxis.CurrentStation.Contains("UP"))
  73. {
  74. return false;
  75. }
  76. return true;
  77. }
  78. /// <summary>
  79. /// 写入Retract数值
  80. /// </summary>
  81. /// <returns></returns>
  82. private bool WriteRetract()
  83. {
  84. bool active = WriteIo(IMMOBILIZE_ACTIVE, false);
  85. if (active)
  86. {
  87. return WriteIo(IMMOBILIZE_ACTIVE2, false);
  88. }
  89. return false;
  90. }
  91. /// <summary>
  92. /// 写入IO
  93. /// </summary>
  94. /// <param name="name"></param>
  95. /// <param name="value"></param>
  96. /// <returns></returns>
  97. private bool WriteIo(string name,bool value)
  98. {
  99. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{name}");
  100. if (!string.IsNullOrEmpty(ioName))
  101. {
  102. return IOModuleManager.Instance.WriteIoValue(ioName, value);
  103. }
  104. else
  105. {
  106. return false;
  107. }
  108. }
  109. /// <summary>
  110. /// 检验Retract状态
  111. /// </summary>
  112. /// <returns></returns>
  113. private bool CheckRetract()
  114. {
  115. return _transporterCommon.TransporterData.ImmobilizeRetracted1 && _transporterCommon.TransporterData.ImmobilizeRetracted2;
  116. }
  117. /// <summary>
  118. /// 启动
  119. /// </summary>
  120. /// <param name="objs"></param>
  121. /// <returns></returns>
  122. public RState Start(params object[] objs)
  123. {
  124. _transporterCommon = DEVICE.GetDevice<TransporterCommon>($"{Module}.Common");
  125. return Runner.Start(Module, "Retract");
  126. }
  127. }
  128. }