SafetyAllOnRoutine.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. PlatingCell12VerticalSwitchOn,
  34. WaitSwitchOnPlatingCell12Vertical,
  35. PlatingCell34VerticalSwitchOn,
  36. WaitSwitchOnPlatingCell34Vertical,
  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 _platingCell1_2Vertical;
  52. private JetAxisBase _platingCell3_4Vertical;
  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. .RunIf(SafetyAllOnStep.PlatingCell12VerticalSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell1), () => SwitchOnAxis(_platingCell1_2Vertical), _delay_1ms)
  83. .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell12Vertical, ModuleHelper.IsInstalled(ModuleName.PlatingCell1),
  84. () => CheckSwitchOn(_platingCell1_2Vertical), () => CheckSwitchOnStopStatus(_platingCell1_2Vertical))
  85. .RunIf(SafetyAllOnStep.PlatingCell34VerticalSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell3), () => SwitchOnAxis(_platingCell3_4Vertical), _delay_1ms)
  86. .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell34Vertical, ModuleHelper.IsInstalled(ModuleName.PlatingCell3),
  87. () => CheckSwitchOn(_platingCell3_4Vertical), () => CheckSwitchOnStopStatus(_platingCell3_4Vertical))
  88. .RunIf(SafetyAllOnStep.PlatingCell1RotationSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell1), () => SwitchOnAxis(_platingCell1Rotation), _delay_1ms)
  89. .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell1Rotation, ModuleHelper.IsInstalled(ModuleName.PlatingCell1),
  90. () => CheckSwitchOn(_platingCell1Rotation), () => CheckSwitchOnStopStatus(_platingCell1Rotation))
  91. .RunIf(SafetyAllOnStep.PlatingCell2RotationSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell2), () => SwitchOnAxis(_platingCell2Rotation), _delay_1ms)
  92. .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell2Rotation, ModuleHelper.IsInstalled(ModuleName.PlatingCell2),
  93. () => CheckSwitchOn(_platingCell2Rotation), () => CheckSwitchOnStopStatus(_platingCell2Rotation))
  94. .RunIf(SafetyAllOnStep.PlatingCell3RotationSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell3), () => SwitchOnAxis(_platingCell3Rotation), _delay_1ms)
  95. .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell3Rotation, ModuleHelper.IsInstalled(ModuleName.PlatingCell3),
  96. () => CheckSwitchOn(_platingCell3Rotation), () => CheckSwitchOnStopStatus(_platingCell3Rotation))
  97. .RunIf(SafetyAllOnStep.PlatingCell4RotationSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell4), () => SwitchOnAxis(_platingCell4Rotation), _delay_1ms)
  98. .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell4Rotation, ModuleHelper.IsInstalled(ModuleName.PlatingCell4),
  99. () => CheckSwitchOn(_platingCell4Rotation), () => CheckSwitchOnStopStatus(_platingCell4Rotation))
  100. .RunIf(SafetyAllOnStep.SwitchOnSRD1, ModuleHelper.IsInstalled(ModuleName.SRD1), () => SwitchOnAxis(_srd1Rotation), _delay_1ms)
  101. .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnSRD1, ModuleHelper.IsInstalled(ModuleName.SRD1),
  102. () => CheckSwitchOn(_srd1Rotation), () => CheckSwitchOnStopStatus(_srd1Rotation))
  103. .RunIf(SafetyAllOnStep.SwitchOnSRD2, ModuleHelper.IsInstalled(ModuleName.SRD2), () => SwitchOnAxis(_srd2Rotation), _delay_1ms)
  104. .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnSRD2, ModuleHelper.IsInstalled(ModuleName.SRD2),
  105. () => CheckSwitchOn(_srd2Rotation), () => CheckSwitchOnStopStatus(_srd2Rotation))
  106. .End(SafetyAllOnStep.End, NullFun, _delay_1ms);
  107. return Runner.Status;
  108. }
  109. /// <summary>
  110. /// 电机SwitchOn
  111. /// </summary>
  112. /// <param name="axis"></param>
  113. /// <returns></returns>
  114. private bool SwitchOnAxis(JetAxisBase axis)
  115. {
  116. return axis.SwitchOn();
  117. }
  118. /// <summary>
  119. /// 检验电机是否上电
  120. /// </summary>
  121. /// <param name="axis"></param>
  122. /// <returns></returns>
  123. private bool CheckSwitchOn(JetAxisBase axis)
  124. {
  125. return axis.IsSwitchOn && axis.Status == RState.End;
  126. }
  127. /// <summary>
  128. /// 检验电机上电是否异常
  129. /// </summary>
  130. /// <param name="axis"></param>
  131. /// <returns></returns>
  132. private bool CheckSwitchOnStopStatus(JetAxisBase axis)
  133. {
  134. return axis.Status == RState.Failed;
  135. }
  136. /// <summary>
  137. /// 启动
  138. /// </summary>
  139. /// <param name="objs"></param>
  140. /// <returns></returns>
  141. public RState Start(params object[] objs)
  142. {
  143. _device = DEVICE.GetDevice<SafetyDevice>(Module);
  144. _vpwCell1Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.VPW1}.Rotation");
  145. _vpwCell2Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.VPW2}.Rotation");
  146. _platingCell1Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PlatingCell1}.Rotation");
  147. _platingCell2Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PlatingCell2}.Rotation");
  148. _platingCell3Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PlatingCell3}.Rotation");
  149. _platingCell4Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PlatingCell4}.Rotation");
  150. _platingCell1_2Vertical = DEVICE.GetDevice<JetAxisBase>($"PlatingCell1_2.Vertical");
  151. _platingCell3_4Vertical = DEVICE.GetDevice<JetAxisBase>($"PlatingCell3_4.Vertical");
  152. _srd1Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.SRD1}.Rotation");
  153. _srd2Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.SRD2}.Rotation");
  154. return Runner.Start(Module, $"Safety All On");
  155. }
  156. }
  157. }