PlatingCellDepositionRoutine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.Util;
  5. using MECF.Framework.Common.Beckhoff.Station;
  6. using MECF.Framework.Common.CommonData.PowerSupplier;
  7. using MECF.Framework.Common.RecipeCenter;
  8. using MECF.Framework.Common.Routine;
  9. using MECF.Framework.Common.Utilities;
  10. using PunkHPX8_Core;
  11. using PunkHPX8_RT.Devices.AXIS;
  12. using PunkHPX8_RT.Devices.PlatingCell;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. namespace PunkHPX8_RT.Modules.PlatingCell
  19. {
  20. public class PlatingCellDepositionRoutine : RoutineBase, IRoutine
  21. {
  22. private enum RunRecipeStep
  23. {
  24. RunPowerStep,
  25. RunPowerStepWait,
  26. LoopRotationStart,
  27. LoopVerticalGotoOffSet,
  28. LoopVerticalGotoOffSetCheck,
  29. LoopRotationStartIfCurrentIsStoped,//如果当前电机是停止状态,启动起来
  30. LoopRotationChangeSpeed,
  31. LoopRotationDelay,
  32. LoopRotationStopIfCurrentIsRuning, //如果当前电机是启动状态,则停止
  33. LoopROtationStopCheck,
  34. LoopRotationBiRotation,
  35. LoopRotationBiRotationCheck,
  36. LoopEnd,
  37. RotationStartIfCurrentIsStoped,
  38. End
  39. }
  40. #region 常量
  41. /// <summary>
  42. /// ROTATION电机转速比例
  43. /// </summary>
  44. private const int SPEED_RATIO = 1;
  45. private const int ROTATION_FAR_POSITION = 12 * 60 * 60 * 500 * 6; //以500rmp 运行12个小时的位置
  46. #endregion
  47. /// <summary>
  48. /// recipe
  49. /// </summary>
  50. private DepRecipe _recipe;
  51. /// <summary>
  52. /// Rotation axis
  53. /// </summary>
  54. private JetAxisBase _rotationAxis;
  55. /// <summary>
  56. /// Platingcell device
  57. /// </summary>
  58. private PlatingCellDevice _device;
  59. /// <summary>
  60. /// vertical axis entity
  61. /// </summary>
  62. private PlatingCellVerticalEntity _verticalEntity;
  63. /// <summary>
  64. /// 不通电
  65. /// </summary>
  66. private bool _isZeroCurrent = false;
  67. /// <summary>
  68. /// 是否双有双向旋转
  69. /// </summary>
  70. private bool _isBiRotation = false;
  71. /// <summary>
  72. /// 是否启动smart spin
  73. /// </summary>
  74. private bool _isSmartSpin = false;
  75. /// <summary>
  76. /// Power step集合
  77. /// </summary>
  78. List<PowerSupplierStepPeriodData> _powerSupplierStepPeriodDatas = new List<PowerSupplierStepPeriodData>();
  79. /// <summary>
  80. /// 双向旋转routine
  81. /// </summary>
  82. private RotationBiDirectionRoutine _rotationBiDirectionRoutine;
  83. /// <summary>
  84. /// Plating启动时间
  85. /// </summary>
  86. private DateTime _platingStartTime;
  87. /// <summary>
  88. /// 当前执行到电镀步骤的索引
  89. /// </summary>
  90. private int _depositionStepIndex = 0;
  91. /// <summary>
  92. /// 构造函数
  93. /// </summary>
  94. /// <param name="module"></param>
  95. public PlatingCellDepositionRoutine(string module) : base(module)
  96. {
  97. _rotationBiDirectionRoutine = new RotationBiDirectionRoutine(module);
  98. }
  99. /// <summary>
  100. /// 中止
  101. /// </summary>
  102. public void Abort()
  103. {
  104. Runner.Stop("Manual Abort");
  105. }
  106. /// <summary>
  107. /// 监控
  108. /// </summary>
  109. /// <returns></returns>
  110. public RState Monitor()
  111. { //没有上电保护,此刻给电
  112. Runner.RunIf(RunRecipeStep.RunPowerStep, _recipe.IsEntryTypeCold, StartPowerStep, _delay_1ms)
  113. .LoopStart(RunRecipeStep.LoopRotationStart, "Start rotation cycle",_recipe.DepStepCount,NullFun)
  114. //vertical 调整位置(第一步不用调,entry过程已经走到位置了)
  115. .LoopRunIf(RunRecipeStep.LoopVerticalGotoOffSet, _recipe.DepSteps[_depositionStepIndex].PlatingZoffset!=0 && _depositionStepIndex!=0, () => StartVertical("Plate", _recipe.DepSteps[_depositionStepIndex].PlatingZoffset),_delay_1ms)
  116. .LoopRunIf(RunRecipeStep.LoopVerticalGotoOffSetCheck, _recipe.DepSteps[_depositionStepIndex].PlatingZoffset!=0 && _depositionStepIndex != 0, CheckVerticalEnd, CheckVerticalError)
  117. //不带双向旋转,时间到了直接变速(如果当前电机是停止状态,启动起来)
  118. .LoopRunIf(RunRecipeStep.LoopRotationStartIfCurrentIsStoped, CheckRotationIsIdle() && !_recipe.DepSteps[_depositionStepIndex].BiDireaction,
  119. () => { return StartRotation(ROTATION_FAR_POSITION); }, _delay_1ms)
  120. .LoopRunIf(RunRecipeStep.LoopRotationChangeSpeed, !_recipe.DepSteps[_depositionStepIndex].BiDireaction,() => ChangeRotationSpeed(_recipe.DepSteps[_depositionStepIndex].PlatingSpeed),_delay_1ms)
  121. .LoopDelayIf(RunRecipeStep.LoopRotationDelay, !_recipe.DepSteps[_depositionStepIndex].BiDireaction, _recipe.DepSteps[_depositionStepIndex].DurartionSeconds *1000)
  122. //带双向旋转,启动双向旋转的routine(如果当前电机是启动状态,则停止)
  123. .LoopRunIf(RunRecipeStep.LoopRotationStopIfCurrentIsRuning, checkRotationIsRunning() && _recipe.DepSteps[_depositionStepIndex].BiDireaction,
  124. _rotationAxis.StopPositionOperation, _delay_1ms)
  125. .LoopRunIfWithStopStatus(RunRecipeStep.LoopROtationStopCheck, checkRotationIsRunning() && _recipe.DepSteps[_depositionStepIndex].BiDireaction,
  126. CheckRotationIsIdle, CheckRotationPositionRunStop)
  127. .LoopRunIf(RunRecipeStep.LoopRotationBiRotation, _recipe.DepSteps[_depositionStepIndex].BiDireaction,
  128. () => _rotationBiDirectionRoutine.Start(_recipe.DepSteps[_depositionStepIndex].DurartionSeconds, _recipe.DepSteps[_depositionStepIndex].BiDFrequency, _recipe.DepSteps[_depositionStepIndex].PlatingSpeed) == RState.Running,_delay_1ms)
  129. .LoopRunIfWithStopStatus(RunRecipeStep.LoopRotationBiRotationCheck, _recipe.DepSteps[_depositionStepIndex].BiDireaction,
  130. () => CommonFunction.CheckRoutineEndState(_rotationBiDirectionRoutine),
  131. () => CommonFunction.CheckRoutineStopState(_rotationBiDirectionRoutine))
  132. .LoopEnd(RunRecipeStep.LoopEnd, UpdateDepositionIndex, _delay_1ms)
  133. //检验步阶电流是否完成
  134. .WaitWithStopCondition(RunRecipeStep.RunPowerStepWait, CheckRecipeStepEndStatus, CheckRecipeStepStopStatus, _delay_1ms)
  135. //如果电镀最后一步带双向旋转,后续电机会停止,需要再把电机启动起来
  136. .RunIf(RunRecipeStep.RotationStartIfCurrentIsStoped, CheckRotationIsIdle(), () => { return StartRotation(ROTATION_FAR_POSITION); }, _delay_1ms)
  137. .End(RunRecipeStep.End, NullFun);
  138. return Runner.Status;
  139. }
  140. /// <summary>
  141. /// 判断当前电机是否在转
  142. /// </summary>
  143. /// <returns></returns>
  144. private bool checkRotationIsRunning()
  145. {
  146. return _rotationAxis.Status == RState.Running;
  147. }
  148. /// <summary>
  149. /// 判断电机当前状态是否停止
  150. /// </summary>
  151. /// <returns></returns>
  152. private bool CheckRotationIsIdle()
  153. {
  154. return _rotationAxis.Status == RState.End;
  155. }
  156. /// <summary>
  157. /// 检验Rotation是否运动失败
  158. /// </summary>
  159. /// <returns></returns>
  160. private bool CheckRotationPositionRunStop()
  161. {
  162. return _rotationAxis.Status == RState.Failed || _rotationAxis.Status == RState.Timeout;
  163. }
  164. /// <summary>
  165. /// 更新电镀步骤索引
  166. /// </summary>
  167. /// <returns></returns>
  168. private bool UpdateDepositionIndex()
  169. {
  170. if (_depositionStepIndex < _recipe.DepStepCount - 1)
  171. {
  172. _depositionStepIndex++;
  173. }
  174. return true;
  175. }
  176. /// <summary>
  177. /// 启动PowerSupplier
  178. /// </summary>
  179. /// <returns></returns>
  180. private bool StartPowerStep()
  181. {
  182. bool result = _device.PowerSupplier.StartSetStepPeriodNoWaitEnd(_powerSupplierStepPeriodDatas);
  183. if (!result)
  184. {
  185. _device.PowerSupplier.DisableOperation("", null);
  186. return false;
  187. }
  188. _platingStartTime = DateTime.Now;
  189. return true;
  190. }
  191. /// <summary>
  192. /// 检验Powerstep是否启动完成
  193. /// </summary>
  194. /// <returns></returns>
  195. private bool CheckRecipeStepEndStatus()
  196. {
  197. if (_isZeroCurrent)
  198. {
  199. return true;
  200. }
  201. return _device.PowerSupplier.Status == RState.End;
  202. }
  203. /// <summary>
  204. /// 检验Powerstep是否启动失败
  205. /// </summary>
  206. /// <returns></returns>
  207. private bool CheckRecipeStepStopStatus()
  208. {
  209. if (_isZeroCurrent)
  210. {
  211. return false;
  212. }
  213. return _device.PowerSupplier.Status == RState.Failed || _device.PowerSupplier.Status == RState.Timeout;
  214. }
  215. /// <summary>
  216. /// rotation开始旋转
  217. /// </summary>
  218. /// <param name="param"></param>
  219. /// <returns></returns>
  220. private bool StartRotation(int targetPosition)
  221. {
  222. bool result = _rotationAxis.ProfilePosition(targetPosition, _recipe.IntervalRinseSpeed * SPEED_RATIO * 6, 0, 0); //rpm->deg/s
  223. if (!result)
  224. {
  225. NotifyError(eEvent.ERR_PLATINGCELL, "Start Rotation is failed", 0);
  226. return false;
  227. }
  228. return true;
  229. }
  230. /// <summary>
  231. /// rotation改变速度
  232. /// </summary>
  233. /// <param name="speed"></param>
  234. /// <returns></returns>
  235. private bool ChangeRotationSpeed(int speed)
  236. {
  237. double _scale = _rotationAxis.ScaleFactor;
  238. speed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(speed), 0);
  239. return _rotationAxis.ChangeSpeed(speed);
  240. }
  241. /// <summary>
  242. /// vertical 运行
  243. /// </summary>
  244. /// <param name="positionName"></param> 目标位置名称
  245. /// <param name="offset"></param> 偏移量
  246. /// <returns></returns>
  247. private bool StartVertical(string positionName, double offset)
  248. {
  249. return _verticalEntity.CheckToPostMessage<PlatingCellVerticalState, PlatingCellVerticalEntity.VerticalMsg>(Aitex.Core.RT.Log.eEvent.INFO_PLATINGCELL,
  250. Module, (int)PlatingCellVerticalEntity.VerticalMsg.Position, positionName, offset);
  251. }
  252. /// <summary>
  253. /// 检验垂直电机是否运动完成
  254. /// </summary>
  255. /// <returns></returns>
  256. private bool CheckVerticalEnd()
  257. {
  258. return _verticalEntity.IsIdle;
  259. }
  260. /// <summary>
  261. /// 检验垂直是否出现错误
  262. /// </summary>
  263. /// <returns></returns>
  264. private bool CheckVerticalError()
  265. {
  266. return _verticalEntity.IsError;
  267. }
  268. /// <summary>
  269. /// 启动
  270. /// </summary>
  271. /// <param name="objs"></param>
  272. /// <returns></returns>
  273. public RState Start(params object[] objs)
  274. {
  275. _recipe = (DepRecipe)objs[0];
  276. _isZeroCurrent = (bool)objs[1];
  277. _isBiRotation = (bool)objs[2];
  278. _powerSupplierStepPeriodDatas = (List<PowerSupplierStepPeriodData>)objs[3];
  279. _platingStartTime = (DateTime)objs[4];
  280. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  281. _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
  282. _depositionStepIndex = 0;
  283. //获取vertical entity
  284. string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module);
  285. _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
  286. return Runner.Start(Module, "start Deposition routine");
  287. }
  288. }
  289. }