PlatingCellInterRinseRoutine.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.RT.Routine;
  3. using MECF.Framework.Common.Beckhoff.AxisProvider;
  4. using MECF.Framework.Common.RecipeCenter;
  5. using MECF.Framework.Common.Routine;
  6. using MECF.Framework.Common.Utilities;
  7. using PunkHPX8_Core;
  8. using PunkHPX8_RT.Devices.AXIS;
  9. using PunkHPX8_RT.Devices.PlatingCell;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace PunkHPX8_RT.Modules.PlatingCell
  16. {
  17. public class PlatingCellInterRinseRoutine : RoutineBase, IRoutine
  18. {
  19. private enum RunRecipeStep
  20. {
  21. OpenRinseValve,
  22. StartRotation,
  23. CheckRotationStop,
  24. CloseRinseValve,
  25. End
  26. }
  27. #region 常量
  28. /// <summary>
  29. /// ROTATION电机转速比例
  30. /// </summary>
  31. private const int SPEED_RATIO = 1;
  32. #endregion
  33. /// <summary>
  34. /// recipe
  35. /// </summary>
  36. private DepRecipe _recipe;
  37. /// <summary>
  38. /// Rotation axis
  39. /// </summary>
  40. private JetAxisBase _rotationAxis;
  41. /// <summary>
  42. /// Platingcell device
  43. /// </summary>
  44. private PlatingCellDevice _device;
  45. /// <summary>
  46. ///rotation Provider对象
  47. /// </summary>
  48. private BeckhoffProviderAxis _rotationProviderAxis;
  49. /// <summary>
  50. /// 构造函数
  51. /// </summary>
  52. /// <param name="module"></param>
  53. public PlatingCellInterRinseRoutine(string module) : base(module)
  54. {
  55. }
  56. /// <summary>
  57. /// 中止
  58. /// </summary>
  59. public void Abort()
  60. {
  61. Runner.Stop("Manual Abort");
  62. }
  63. /// <summary>
  64. /// 监控
  65. /// </summary>
  66. /// <returns></returns>
  67. public RState Monitor()
  68. {
  69. Runner.Run(RunRecipeStep.OpenRinseValve, _device.RinseEnableAction, _delay_1ms)
  70. .Run(RunRecipeStep.StartRotation, StartRotation, _delay_1ms)
  71. .WaitWithStopCondition(RunRecipeStep.CheckRotationStop, CheckRotationEndStatus, CheckRotationStopStatus)
  72. .Run(RunRecipeStep.CloseRinseValve, _device.RinseDisableAction, _delay_1ms)
  73. .End(RunRecipeStep.End, NullFun);
  74. return Runner.Status;
  75. }
  76. /// <summary>
  77. /// rotation开始旋转
  78. /// </summary>
  79. /// <param name="param"></param>
  80. /// <returns></returns>
  81. private bool StartRotation()
  82. {
  83. //比例
  84. double _scale = _rotationProviderAxis.ScaleFactor;
  85. //rinse 目标位置
  86. double rinsePosition = _recipe.IntervalRinseTime * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_recipe.IntervalRinseSpeed);
  87. int targetPosition = (int)Math.Round((rinsePosition + _recipe.IntervalRinseZoffset) * _scale, 0);
  88. bool result = _rotationAxis.ProfilePosition(targetPosition, _recipe.IntervalRinseSpeed * SPEED_RATIO, 0, 0);
  89. if (!result)
  90. {
  91. NotifyError(eEvent.ERR_PLATINGCELL, "Start Rotation is failed", 0);
  92. return false;
  93. }
  94. return true;
  95. }
  96. /// <summary>
  97. /// 检验Rotation是否停止
  98. /// </summary>
  99. /// <returns></returns>
  100. private bool CheckRotationEndStatus()
  101. {
  102. if (!_rotationAxis.IsRun && _rotationAxis.Status == RState.End)
  103. {
  104. return true;
  105. }
  106. return false;
  107. }
  108. /// <summary>
  109. /// 检验Rotation停止状态
  110. /// </summary>
  111. /// <returns></returns>
  112. private bool CheckRotationStopStatus()
  113. {
  114. if (_rotationAxis.Status == RState.Failed || _rotationAxis.Status == RState.Timeout)
  115. {
  116. NotifyError(eEvent.ERR_PLATINGCELL, $"{Module}.Rotation is failed", 0);
  117. return true;
  118. }
  119. return false;
  120. }
  121. /// <summary>
  122. /// 启动
  123. /// </summary>
  124. /// <param name="objs"></param>
  125. /// <returns></returns>
  126. public RState Start(params object[] objs)
  127. {
  128. _recipe = (DepRecipe)objs[0];
  129. _rotationAxis = (JetAxisBase)objs[1];
  130. _device = (PlatingCellDevice)objs[2];
  131. _rotationProviderAxis = (BeckhoffProviderAxis)objs[3];
  132. return Runner.Start(Module, "start intervale rinse");
  133. }
  134. }
  135. }