| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using MECF.Framework.Common.RecipeCenter;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.Utilities;
- using PunkHPX8_Core;
- using PunkHPX8_RT.Devices.AXIS;
- using PunkHPX8_RT.Devices.PlatingCell;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PunkHPX8_RT.Modules.PlatingCell
- {
- public class PlatingCellReclaimRoutine : RoutineBase, IRoutine
- {
- private enum RunRecipeStep
- {
- SetCurrentProtect,
- SetCurrentProtectWait,
- PowerEnable,
- VerticalGotoReclaim,
- CheckVerticalGotoReclaim,
- PowerDisable,
- ChangeRotation,
- RotationDelay,
- End
- }
- #region 常量
- #endregion
- /// <summary>
- /// recipe
- /// </summary>
- private DepRecipe _recipe;
- /// <summary>
- /// Rotation axis
- /// </summary>
- private JetAxisBase _rotationAxis;
- /// <summary>
- /// Platingcell device
- /// </summary>
- private PlatingCellDevice _device;
- /// <summary>
- /// vertical axis entity
- /// </summary>
- private PlatingCellVerticalEntity _verticalEntity;
- /// <summary>
- /// 片子是否电镀
- /// </summary>
- private bool _isZeroCurrent = false;
- /// <summary>
- /// reclaim过程是否启用电流保护
- /// </summary>
- private bool _isCurrentProtectEnable = false;
- /// <summary>
- ///reclaim过程vertical运动速度
- /// </summary>
- private int _verticalReclaimSpeed = 0;
- /// <summary>
- /// reclaim过程vertical加速度
- /// </summary>
- private int _verticalReclaimAcceleration = 0;
- /// <summary>
- /// reclaim过程电流保护的电流数值
- /// </summary>
- private double _reclaimCurrentSetPoint = 0;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public PlatingCellReclaimRoutine(string module) : base(module)
- {
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- Runner.Stop("Manual Abort");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- {
- Runner.RunIf(RunRecipeStep.SetCurrentProtect, !_isZeroCurrent && _isCurrentProtectEnable , SetCurrent, _delay_1ms)
- .DelayIf(RunRecipeStep.SetCurrentProtectWait, !_isZeroCurrent && _isCurrentProtectEnable,500)
- .RunIf(RunRecipeStep.PowerEnable, !_isZeroCurrent && _isCurrentProtectEnable,EnablePower, _delay_1ms)
- .Run(RunRecipeStep.VerticalGotoReclaim, () => StartVertical("Reclaim",_recipe.ReclaimZoffset, _verticalReclaimSpeed, _verticalReclaimAcceleration), _delay_1ms)
- .WaitWithStopCondition(RunRecipeStep.CheckVerticalGotoReclaim, CheckVerticalEnd, CheckVerticalError)
- .RunIf(RunRecipeStep.PowerDisable, !_isZeroCurrent && _isCurrentProtectEnable, DisablePower, _delay_1ms)
- .Run(RunRecipeStep.PowerDisable, () => ChangeRotationSpeed(_recipe.ReclaimSpeed), _delay_1ms)
- .Delay(RunRecipeStep.RotationDelay, _recipe.ReclaimTime*1000)
- .End(RunRecipeStep.End, NullFun);
- return Runner.Status;
- }
- /// <summary>
- /// 设置电流
- /// </summary>
- /// <returns></returns>
- private bool SetCurrent()
- {
- return _device.PowerSupplier.SetCurrent(_reclaimCurrentSetPoint);
- }
- /// <summary>
- /// 启动电源输出
- /// </summary>
- /// <returns></returns>
- private bool EnablePower()
- {
- return _device.PowerSupplier.EnableOperation("", null);
- }
- /// <summary>
- /// 停止电源输出
- /// </summary>
- /// <returns></returns>
- private bool DisablePower()
- {
- return _device.PowerSupplier.DisableOperation("", null);
- }
- /// <summary>
- /// rotation改变速度
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- private bool ChangeRotationSpeed(int speed)
- {
- double _scale = _rotationAxis.ScaleFactor;
- speed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(speed), 0);
- return _rotationAxis.ChangeSpeed(speed);
- }
- /// <summary>
- /// vertical 运行
- /// </summary>
- /// <param name="positionName"></param> 目标位置名称
- /// <param name="offset"></param> 偏移量
- /// <returns></returns>
- private bool StartVertical(string positionName, double offset,int speed,int accelerate)
- {
- return _verticalEntity.CheckToPostMessage<PlatingCellVerticalState, PlatingCellVerticalEntity.VerticalMsg>(Aitex.Core.RT.Log.eEvent.INFO_PLATINGCELL,
- Module, (int)PlatingCellVerticalEntity.VerticalMsg.Position, positionName, offset, speed, accelerate);
- }
- /// <summary>
- /// 检验垂直电机是否运动完成
- /// </summary>
- /// <returns></returns>
- private bool CheckVerticalEnd()
- {
- return _verticalEntity.IsIdle;
- }
- /// <summary>
- /// 检验垂直是否出现错误
- /// </summary>
- /// <returns></returns>
- private bool CheckVerticalError()
- {
- return _verticalEntity.IsError;
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- public RState Start(params object[] objs)
- {
- _recipe = (DepRecipe)objs[0];
- _isZeroCurrent = (bool)objs[1];
-
- _isCurrentProtectEnable = SC.GetValue<bool>("PlatingCell.PostProcessCurrentEnable");
- _verticalReclaimSpeed = SC.GetValue<int>("PlatingCell.ReclaimSpeed");
- _verticalReclaimAcceleration = SC.GetValue<int>("PlatingCell.ReclaimAcceleration");
- _reclaimCurrentSetPoint = SC.GetValue<double>("PlatingCell.PostProcessCurrentSetPoint");
-
- _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
- _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
- //获取vertical entity
- string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module);
- _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
- return Runner.Start(Module, "start Reclaim routine");
- }
- }
- }
|