PlatingCellDryRoutine.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.Util;
  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 PlatingCellDryRoutine : RoutineBase, IRoutine
  18. {
  19. private enum RunRecipeStep
  20. {
  21. VerticalGotoDry,
  22. CheckVerticalGotoDry,
  23. ChangeRotation,
  24. RotationDelay,
  25. RotationStop,
  26. CheckRotationStoped,
  27. End
  28. }
  29. #region 常量
  30. #endregion
  31. /// <summary>
  32. /// recipe
  33. /// </summary>
  34. private DepRecipe _recipe;
  35. /// <summary>
  36. /// Rotation axis
  37. /// </summary>
  38. private JetAxisBase _rotationAxis;
  39. /// <summary>
  40. /// Platingcell device
  41. /// </summary>
  42. private PlatingCellDevice _device;
  43. /// <summary>
  44. /// vertical axis entity
  45. /// </summary>
  46. private PlatingCellVerticalEntity _verticalEntity;
  47. /// <summary>
  48. /// 构造函数
  49. /// </summary>
  50. /// <param name="module"></param>
  51. public PlatingCellDryRoutine(string module) : base(module)
  52. {
  53. }
  54. /// <summary>
  55. /// 中止
  56. /// </summary>
  57. public void Abort()
  58. {
  59. Runner.Stop("Manual Abort");
  60. }
  61. /// <summary>
  62. /// 监控
  63. /// </summary>
  64. /// <returns></returns>
  65. public RState Monitor()
  66. {
  67. Runner.RunIf(RunRecipeStep.VerticalGotoDry, _recipe.RinseZoffset != _recipe.DryZoffset,() => StartVertical("Rinse", _recipe.DryZoffset, 0, 0), _delay_1ms)
  68. .WaitWithStopConditionIf(RunRecipeStep.CheckVerticalGotoDry, _recipe.RinseZoffset != _recipe.DryZoffset, CheckVerticalEnd, CheckVerticalError)
  69. .Run(RunRecipeStep.ChangeRotation, () => ChangeRotationSpeed(_recipe.DrySpeed), _delay_1ms)
  70. .Delay(RunRecipeStep.RotationDelay, _recipe.DryTime * 1000)
  71. .Run(RunRecipeStep.RotationStop, _rotationAxis.StopPositionOperation, _delay_1ms)
  72. .WaitWithStopCondition(RunRecipeStep.CheckRotationStoped, CheckRotationPositionStatus, CheckRotationPositionRunStop)
  73. .End(RunRecipeStep.End, NullFun);
  74. return Runner.Status;
  75. }
  76. /// <summary>
  77. /// rotation改变速度
  78. /// </summary>
  79. /// <param name="speed"></param>
  80. /// <returns></returns>
  81. private bool ChangeRotationSpeed(int speed)
  82. {
  83. double _scale = _rotationAxis.ScaleFactor;
  84. speed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(speed), 0);
  85. return _rotationAxis.ChangeSpeed(speed);
  86. }
  87. /// <summary>
  88. /// 检验Rotation移动状态
  89. /// </summary>
  90. /// <returns></returns>
  91. private bool CheckRotationPositionStatus()
  92. {
  93. return _rotationAxis.Status == RState.End;
  94. }
  95. /// <summary>
  96. /// 检验Rotation是否运动失败
  97. /// </summary>
  98. /// <returns></returns>
  99. private bool CheckRotationPositionRunStop()
  100. {
  101. return _rotationAxis.Status == RState.Failed || _rotationAxis.Status == RState.Timeout;
  102. }
  103. /// <summary>
  104. /// vertical 运行
  105. /// </summary>
  106. /// <param name="positionName"></param> 目标位置名称
  107. /// <param name="offset"></param> 偏移量
  108. /// <returns></returns>
  109. private bool StartVertical(string positionName, double offset, int speed, int accelerate)
  110. {
  111. return _verticalEntity.CheckToPostMessage<PlatingCellVerticalState, PlatingCellVerticalEntity.VerticalMsg>(Aitex.Core.RT.Log.eEvent.INFO_PLATINGCELL,
  112. Module, (int)PlatingCellVerticalEntity.VerticalMsg.Position, positionName, offset, speed, accelerate);
  113. }
  114. /// <summary>
  115. /// 检验垂直电机是否运动完成
  116. /// </summary>
  117. /// <returns></returns>
  118. private bool CheckVerticalEnd()
  119. {
  120. return _verticalEntity.IsIdle;
  121. }
  122. /// <summary>
  123. /// 检验垂直是否出现错误
  124. /// </summary>
  125. /// <returns></returns>
  126. private bool CheckVerticalError()
  127. {
  128. return _verticalEntity.IsError;
  129. }
  130. /// <summary>
  131. /// 启动
  132. /// </summary>
  133. /// <param name="objs"></param>
  134. /// <returns></returns>
  135. public RState Start(params object[] objs)
  136. {
  137. _recipe = (DepRecipe)objs[0];
  138. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  139. _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
  140. //获取vertical entity
  141. string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module);
  142. _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
  143. return Runner.Start(Module, "start Dry Routine");
  144. }
  145. }
  146. }