PlatingCellDepositionRoutine.cs 14 KB

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