SRDProcessErrorRoutine.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Routine;
  3. using CyberX8_Core;
  4. using CyberX8_RT.Devices.AXIS;
  5. using MECF.Framework.Common.Routine;
  6. using MECF.Framework.Common.Utilities;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace CyberX8_RT.Modules.SRD
  13. {
  14. public class SRDProcessErrorRoutine : RoutineBase, IRoutine
  15. {
  16. private enum ProcessErrorStep
  17. {
  18. RotationStop,
  19. RotationStopWait,
  20. RotationHome,
  21. RotationHomeWait,
  22. Unload,
  23. UnloadWait,
  24. End
  25. }
  26. #region 内部变量
  27. /// <summary>
  28. /// Rotation Axis
  29. /// </summary>
  30. private JetAxisBase _rotationAxis;
  31. /// <summary>
  32. /// unload routine
  33. /// </summary>
  34. private SRDUnloaderRoutine _unloaderRoutine;
  35. /// <summary>
  36. /// Rotation是否正在运动
  37. /// </summary>
  38. private bool _rotationIsRun;
  39. /// <summary>
  40. /// Rotation是否Homed
  41. /// </summary>
  42. private bool _rotationIsHomed;
  43. #endregion
  44. /// <summary>
  45. /// 构造函数
  46. /// </summary>
  47. /// <param name="module"></param>
  48. public SRDProcessErrorRoutine(string module) : base(module)
  49. {
  50. }
  51. /// <summary>
  52. /// 中止
  53. /// </summary>
  54. public void Abort()
  55. {
  56. Runner.Stop("Manual Abort");
  57. }
  58. /// <summary>
  59. /// 监控
  60. /// </summary>
  61. /// <returns></returns>
  62. public RState Monitor()
  63. {
  64. Runner.RunIf(ProcessErrorStep.RotationStop, _rotationIsRun, () => AxisStop(_rotationAxis), _delay_1ms)
  65. .WaitWithStopConditionIf(ProcessErrorStep.RotationStopWait, _rotationIsRun, () => { return _rotationAxis.Status == RState.End; },
  66. () => { return _rotationAxis.Status == RState.Failed || _rotationAxis.Status == RState.Timeout; })
  67. .RunIf(ProcessErrorStep.RotationHome, !_rotationIsHomed, () => AxisHome(_rotationAxis), _delay_1ms)
  68. .WaitWithStopConditionIf(ProcessErrorStep.RotationHomeWait, !_rotationIsHomed, () => { return _rotationAxis.Status == RState.End; },
  69. () => { return _rotationAxis.Status == RState.Failed || _rotationAxis.Status == RState.Timeout; })
  70. .Run(ProcessErrorStep.Unload, () => { return _unloaderRoutine.Start(true) == RState.Running; }, _delay_1ms)
  71. .WaitWithStopCondition(ProcessErrorStep.UnloadWait, () => CommonFunction.CheckRoutineEndState(_unloaderRoutine),
  72. () => CommonFunction.CheckRoutineStopState(_unloaderRoutine))
  73. .End(ProcessErrorStep.End, NullFun, _delay_1ms);
  74. return Runner.Status;
  75. }
  76. /// <summary>
  77. /// axis停止
  78. /// </summary>
  79. /// <param name="jetAxisBase"></param>
  80. /// <returns></returns>
  81. private bool AxisStop(JetAxisBase jetAxisBase)
  82. {
  83. return jetAxisBase.StopPositionOperation();
  84. }
  85. /// <summary>
  86. /// axis home
  87. /// </summary>
  88. /// <param name="jetAxisBase"></param>
  89. /// <returns></returns>
  90. private bool AxisHome(JetAxisBase jetAxisBase)
  91. {
  92. return jetAxisBase.Home(false);
  93. }
  94. /// <summary>
  95. /// 启动
  96. /// </summary>
  97. /// <param name="objs"></param>
  98. /// <returns></returns>
  99. public RState Start(params object[] objs)
  100. {
  101. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  102. _rotationIsRun= _rotationAxis.IsRun;
  103. _rotationIsHomed = _rotationAxis.IsHomed;
  104. _unloaderRoutine = new SRDUnloaderRoutine(Module);
  105. return Runner.Start(Module, "start process error");
  106. }
  107. }
  108. }