SafetyAllOnRoutine.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.Util;
  5. using PunkHPX8_Core;
  6. using PunkHPX8_RT.Modules;
  7. using PunkHPX8_RT.Modules.SRD;
  8. using PunkHPX8_RT.Modules.Transporter;
  9. using MECF.Framework.Common.Beckhoff.ModuleIO;
  10. using MECF.Framework.Common.Equipment;
  11. using MECF.Framework.Common.Routine;
  12. using MECF.Framework.Common.Utilities;
  13. using System.Runtime.InteropServices;
  14. using PunkHPX8_RT.Devices.AXIS;
  15. namespace PunkHPX8_RT.Devices.Safety
  16. {
  17. internal class SafetyAllOnRoutine : RoutineBase, IRoutine
  18. {
  19. private enum SafetyAllOnStep
  20. {
  21. VpwCell1SwitchOn,
  22. WaitSwitchOnVpwCell1,
  23. VpwCell2SwitchOn,
  24. WaitSwitchOnVpwCell2,
  25. PlatingCell1RotationSwitchOn,
  26. WaitSwitchOnPlatingCell1Rotation,
  27. PlatingCell2RotationSwitchOn,
  28. WaitSwitchOnPlatingCell2Rotation,
  29. PlatingCell3RotationSwitchOn,
  30. WaitSwitchOnPlatingCell3Rotation,
  31. PlatingCell4RotationSwitchOn,
  32. WaitSwitchOnPlatingCell4Rotation,
  33. PlatingCell12LiftSwitchOn,
  34. WaitSwitchOnPlatingCell12Lift,
  35. PlatingCell34LiftSwitchOn,
  36. WaitSwitchOnPlatingCell34Lift,
  37. SwitchOnSRD1,
  38. WaitSwitchOnSRD1,
  39. SwitchOnSRD2,
  40. WaitSwitchOnSRD2,
  41. End
  42. }
  43. #region 内部变量
  44. private SafetyDevice _device;
  45. private JetAxisBase _vpwCell1Rotation;
  46. private JetAxisBase _vpwCell2Rotation;
  47. private JetAxisBase _platingCell1Rotation;
  48. private JetAxisBase _platingCell2Rotation;
  49. private JetAxisBase _platingCell3Rotation;
  50. private JetAxisBase _platingCell4Rotation;
  51. private JetAxisBase _platingCell12Lift;
  52. private JetAxisBase _platingCell34Lift;
  53. private JetAxisBase _srd1Rotation;
  54. private JetAxisBase _srd2Rotation;
  55. #endregion
  56. /// <summary>
  57. /// 构造函数
  58. /// </summary>
  59. /// <param name="module"></param>
  60. public SafetyAllOnRoutine(string module) : base(module)
  61. {
  62. }
  63. /// <summary>
  64. /// 中止
  65. /// </summary>
  66. public void Abort()
  67. {
  68. Runner.Stop($"Safety All On Abort");
  69. }
  70. /// <summary>
  71. /// 监控
  72. /// </summary>
  73. /// <returns></returns>
  74. public RState Monitor()
  75. {
  76. Runner.RunIf(SafetyAllOnStep.VpwCell1SwitchOn,ModuleHelper.IsInstalled(ModuleName.VPW1),()=>SwitchOnAxis(_vpwCell1Rotation),_delay_1ms)
  77. .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnVpwCell1, ModuleHelper.IsInstalled(ModuleName.VPW1),
  78. ()=>CheckSwitchOn(_vpwCell1Rotation),()=>CheckSwitchOnStopStatus(_vpwCell1Rotation))
  79. .RunIf(SafetyAllOnStep.VpwCell2SwitchOn, ModuleHelper.IsInstalled(ModuleName.VPW2), () => SwitchOnAxis(_vpwCell2Rotation), _delay_1ms)
  80. .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnVpwCell2, ModuleHelper.IsInstalled(ModuleName.VPW2),
  81. () => CheckSwitchOn(_vpwCell2Rotation), () => CheckSwitchOnStopStatus(_vpwCell2Rotation))
  82. .End(SafetyAllOnStep.End, NullFun, _delay_1ms);
  83. return Runner.Status;
  84. }
  85. /// <summary>
  86. /// 电机SwitchOn
  87. /// </summary>
  88. /// <param name="axis"></param>
  89. /// <returns></returns>
  90. private bool SwitchOnAxis(JetAxisBase axis)
  91. {
  92. return axis.SwitchOn();
  93. }
  94. /// <summary>
  95. /// 检验电机是否上电
  96. /// </summary>
  97. /// <param name="axis"></param>
  98. /// <returns></returns>
  99. private bool CheckSwitchOn(JetAxisBase axis)
  100. {
  101. return axis.IsSwitchOn && axis.Status == RState.End;
  102. }
  103. /// <summary>
  104. /// 检验电机上电是否异常
  105. /// </summary>
  106. /// <param name="axis"></param>
  107. /// <returns></returns>
  108. private bool CheckSwitchOnStopStatus(JetAxisBase axis)
  109. {
  110. return axis.Status == RState.Failed;
  111. }
  112. /// <summary>
  113. /// 启动
  114. /// </summary>
  115. /// <param name="objs"></param>
  116. /// <returns></returns>
  117. public RState Start(params object[] objs)
  118. {
  119. _device = DEVICE.GetDevice<SafetyDevice>(Module);
  120. _vpwCell1Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.VPW1}.Rotation");
  121. _vpwCell2Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.VPW2}.Rotation");
  122. return Runner.Start(Module, $"Safety All On");
  123. }
  124. }
  125. }