PlatingCellReclaimRoutine.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using MECF.Framework.Common.RecipeCenter;
  7. using MECF.Framework.Common.Routine;
  8. using MECF.Framework.Common.Utilities;
  9. using PunkHPX8_Core;
  10. using PunkHPX8_RT.Devices.AXIS;
  11. using PunkHPX8_RT.Devices.PlatingCell;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. namespace PunkHPX8_RT.Modules.PlatingCell
  18. {
  19. public class PlatingCellReclaimRoutine : RoutineBase, IRoutine
  20. {
  21. private enum RunRecipeStep
  22. {
  23. SetCurrentProtect,
  24. SetCurrentProtectWait,
  25. PowerEnable,
  26. VerticalGotoReclaim,
  27. CheckVerticalGotoReclaim,
  28. PowerDisable,
  29. ChangeRotation,
  30. RotationDelay,
  31. End
  32. }
  33. #region 常量
  34. #endregion
  35. /// <summary>
  36. /// recipe
  37. /// </summary>
  38. private DepRecipe _recipe;
  39. /// <summary>
  40. /// Rotation axis
  41. /// </summary>
  42. private JetAxisBase _rotationAxis;
  43. /// <summary>
  44. /// Platingcell device
  45. /// </summary>
  46. private PlatingCellDevice _device;
  47. /// <summary>
  48. /// vertical axis entity
  49. /// </summary>
  50. private PlatingCellVerticalEntity _verticalEntity;
  51. /// <summary>
  52. /// 片子是否电镀
  53. /// </summary>
  54. private bool _isZeroCurrent = false;
  55. /// <summary>
  56. /// reclaim过程是否启用电流保护
  57. /// </summary>
  58. private bool _isCurrentProtectEnable = false;
  59. /// <summary>
  60. ///reclaim过程vertical运动速度
  61. /// </summary>
  62. private int _verticalReclaimSpeed = 0;
  63. /// <summary>
  64. /// reclaim过程vertical加速度
  65. /// </summary>
  66. private int _verticalReclaimAcceleration = 0;
  67. /// <summary>
  68. /// reclaim过程电流保护的电流数值
  69. /// </summary>
  70. private double _reclaimCurrentSetPoint = 0;
  71. /// <summary>
  72. /// 构造函数
  73. /// </summary>
  74. /// <param name="module"></param>
  75. public PlatingCellReclaimRoutine(string module) : base(module)
  76. {
  77. }
  78. /// <summary>
  79. /// 中止
  80. /// </summary>
  81. public void Abort()
  82. {
  83. Runner.Stop("Manual Abort");
  84. }
  85. /// <summary>
  86. /// 监控
  87. /// </summary>
  88. /// <returns></returns>
  89. public RState Monitor()
  90. {
  91. Runner.RunIf(RunRecipeStep.SetCurrentProtect, !_isZeroCurrent && _isCurrentProtectEnable , SetCurrent, _delay_1ms)
  92. .DelayIf(RunRecipeStep.SetCurrentProtectWait, !_isZeroCurrent && _isCurrentProtectEnable,500)
  93. .RunIf(RunRecipeStep.PowerEnable, !_isZeroCurrent && _isCurrentProtectEnable,EnablePower, _delay_1ms)
  94. .Run(RunRecipeStep.VerticalGotoReclaim, () => StartVertical("Reclaim",_recipe.ReclaimZoffset, _verticalReclaimSpeed, _verticalReclaimAcceleration), _delay_1ms)
  95. .WaitWithStopCondition(RunRecipeStep.CheckVerticalGotoReclaim, CheckVerticalEnd, CheckVerticalError)
  96. .RunIf(RunRecipeStep.PowerDisable, !_isZeroCurrent && _isCurrentProtectEnable, DisablePower, _delay_1ms)
  97. .Run(RunRecipeStep.PowerDisable, () => ChangeRotationSpeed(_recipe.ReclaimSpeed), _delay_1ms)
  98. .Delay(RunRecipeStep.RotationDelay, _recipe.ReclaimTime*1000)
  99. .End(RunRecipeStep.End, NullFun);
  100. return Runner.Status;
  101. }
  102. /// <summary>
  103. /// 设置电流
  104. /// </summary>
  105. /// <returns></returns>
  106. private bool SetCurrent()
  107. {
  108. return _device.PowerSupplier.SetCurrent(_reclaimCurrentSetPoint);
  109. }
  110. /// <summary>
  111. /// 启动电源输出
  112. /// </summary>
  113. /// <returns></returns>
  114. private bool EnablePower()
  115. {
  116. return _device.PowerSupplier.EnableOperation("", null);
  117. }
  118. /// <summary>
  119. /// 停止电源输出
  120. /// </summary>
  121. /// <returns></returns>
  122. private bool DisablePower()
  123. {
  124. return _device.PowerSupplier.DisableOperation("", null);
  125. }
  126. /// <summary>
  127. /// rotation改变速度
  128. /// </summary>
  129. /// <param name="speed"></param>
  130. /// <returns></returns>
  131. private bool ChangeRotationSpeed(int speed)
  132. {
  133. double _scale = _rotationAxis.ScaleFactor;
  134. speed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(speed), 0);
  135. return _rotationAxis.ChangeSpeed(speed);
  136. }
  137. /// <summary>
  138. /// vertical 运行
  139. /// </summary>
  140. /// <param name="positionName"></param> 目标位置名称
  141. /// <param name="offset"></param> 偏移量
  142. /// <returns></returns>
  143. private bool StartVertical(string positionName, double offset,int speed,int accelerate)
  144. {
  145. return _verticalEntity.CheckToPostMessage<PlatingCellVerticalState, PlatingCellVerticalEntity.VerticalMsg>(Aitex.Core.RT.Log.eEvent.INFO_PLATINGCELL,
  146. Module, (int)PlatingCellVerticalEntity.VerticalMsg.Position, positionName, offset, speed, accelerate);
  147. }
  148. /// <summary>
  149. /// 检验垂直电机是否运动完成
  150. /// </summary>
  151. /// <returns></returns>
  152. private bool CheckVerticalEnd()
  153. {
  154. return _verticalEntity.IsIdle;
  155. }
  156. /// <summary>
  157. /// 检验垂直是否出现错误
  158. /// </summary>
  159. /// <returns></returns>
  160. private bool CheckVerticalError()
  161. {
  162. return _verticalEntity.IsError;
  163. }
  164. /// <summary>
  165. /// 启动
  166. /// </summary>
  167. /// <param name="objs"></param>
  168. /// <returns></returns>
  169. public RState Start(params object[] objs)
  170. {
  171. _recipe = (DepRecipe)objs[0];
  172. _isZeroCurrent = (bool)objs[1];
  173. _isCurrentProtectEnable = SC.GetValue<bool>("PlatingCell.PostProcessCurrentEnable");
  174. _verticalReclaimSpeed = SC.GetValue<int>("PlatingCell.ReclaimSpeed");
  175. _verticalReclaimAcceleration = SC.GetValue<int>("PlatingCell.ReclaimAcceleration");
  176. _reclaimCurrentSetPoint = SC.GetValue<double>("PlatingCell.PostProcessCurrentSetPoint");
  177. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  178. _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
  179. //获取vertical entity
  180. string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module);
  181. _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
  182. return Runner.Start(Module, "start Reclaim routine");
  183. }
  184. }
  185. }