PlatingCellRinseRoutine.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.RT.SCCore;
  4. using Aitex.Core.Util;
  5. using MECF.Framework.Common.RecipeCenter;
  6. using MECF.Framework.Common.Routine;
  7. using MECF.Framework.Common.Utilities;
  8. using PunkHPX8_Core;
  9. using PunkHPX8_RT.Devices.AXIS;
  10. using PunkHPX8_RT.Devices.PlatingCell;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Reflection;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. namespace PunkHPX8_RT.Modules.PlatingCell
  18. {
  19. public class PlatingCellRinseRoutine : RoutineBase, IRoutine
  20. {
  21. private enum RunRecipeStep
  22. {
  23. VerticalGotoRinse,
  24. CheckVerticalGotoRinse,
  25. OpenRinseValve,
  26. ChangeRotation,
  27. RotationDelay,
  28. CloseRinseValve,
  29. End
  30. }
  31. #region 常量
  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. /// vertical axis entity
  47. /// </summary>
  48. private PlatingCellVerticalEntity _verticalEntity;
  49. /// <summary>
  50. /// 构造函数
  51. /// </summary>
  52. /// <param name="module"></param>
  53. public PlatingCellRinseRoutine(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.VerticalGotoRinse, () => StartVertical("Rinse", _recipe.RinseZoffset, 0, 0), _delay_1ms)
  70. .WaitWithStopCondition(RunRecipeStep.CheckVerticalGotoRinse, CheckVerticalEnd, CheckVerticalError)
  71. .Run(RunRecipeStep.OpenRinseValve, () => _device.RinseEnableAction(),_delay_1ms)
  72. .Run(RunRecipeStep.ChangeRotation, () => ChangeRotationSpeed(_recipe.RinseSpeed), _delay_1ms)
  73. .Delay(RunRecipeStep.RotationDelay, _recipe.RinseTime*1000)
  74. .Run(RunRecipeStep.CloseRinseValve, () => _device.RinseDisableAction(),_delay_1ms)
  75. .End(RunRecipeStep.End, NullFun);
  76. return Runner.Status;
  77. }
  78. /// <summary>
  79. /// rotation改变速度
  80. /// </summary>
  81. /// <param name="speed"></param>
  82. /// <returns></returns>
  83. private bool ChangeRotationSpeed(int speed)
  84. {
  85. double _scale = _rotationAxis.ScaleFactor;
  86. speed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(speed), 0);
  87. return _rotationAxis.ChangeSpeed(speed);
  88. }
  89. /// <summary>
  90. /// vertical 运行
  91. /// </summary>
  92. /// <param name="positionName"></param> 目标位置名称
  93. /// <param name="offset"></param> 偏移量
  94. /// <returns></returns>
  95. private bool StartVertical(string positionName, double offset, int speed, int accelerate)
  96. {
  97. return _verticalEntity.CheckToPostMessage<PlatingCellVerticalState, PlatingCellVerticalEntity.VerticalMsg>(Aitex.Core.RT.Log.eEvent.INFO_PLATINGCELL,
  98. Module, (int)PlatingCellVerticalEntity.VerticalMsg.Position, positionName, offset, speed, accelerate);
  99. }
  100. /// <summary>
  101. /// 检验垂直电机是否运动完成
  102. /// </summary>
  103. /// <returns></returns>
  104. private bool CheckVerticalEnd()
  105. {
  106. return _verticalEntity.IsIdle;
  107. }
  108. /// <summary>
  109. /// 检验垂直是否出现错误
  110. /// </summary>
  111. /// <returns></returns>
  112. private bool CheckVerticalError()
  113. {
  114. return _verticalEntity.IsError;
  115. }
  116. /// <summary>
  117. /// 启动
  118. /// </summary>
  119. /// <param name="objs"></param>
  120. /// <returns></returns>
  121. public RState Start(params object[] objs)
  122. {
  123. _recipe = (DepRecipe)objs[0];
  124. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  125. _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
  126. //获取vertical entity
  127. string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module);
  128. _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
  129. return Runner.Start(Module, "start rinse routine");
  130. }
  131. }
  132. }