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 PunkHPX8_RT.Devices.PowerSupplier; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Navigation; namespace PunkHPX8_RT.Modules.PlatingCell { public class PlatingCellReclaimRoutine : RoutineBase, IRoutine { private enum RunRecipeStep { SetCurrentProtect, SetCurrentProtectWait, VerticalGotoReclaim, CheckVerticalGotoReclaim, PowerDisable, ChangeRotation, RotationDelay, End } #region 常量 #endregion /// /// recipe /// private DepRecipe _recipe; /// /// Rotation axis /// private JetAxisBase _rotationAxis; /// /// Platingcell device /// private PlatingCellDevice _device; /// /// vertical axis entity /// private PlatingCellVerticalEntity _verticalEntity; /// /// 片子是否电镀 /// private bool _isZeroCurrent = false; /// /// reclaim过程是否启用电流保护 /// private bool _isCurrentProtectEnable = false; /// ///reclaim过程vertical运动速度 /// private int _verticalReclaimSpeed = 0; /// /// reclaim过程vertical加速度 /// private int _verticalReclaimAcceleration = 0; /// /// reclaim过程电流保护的电流数值 /// private double _reclaimCurrentSetPoint = 0; /// /// 设置电流并启动routine /// private PowerSupplierSetCurrentRoutine _enablePowerRoutine; /// /// PowerSupplier /// protected CellPowerSupplier _powerSupplier; /// /// 构造函数 /// /// public PlatingCellReclaimRoutine(string module) : base(module) { } /// /// 中止 /// public void Abort() { Runner.Stop("Manual Abort"); } /// /// 监控 /// /// public RState Monitor() { Runner.RunIf(RunRecipeStep.SetCurrentProtect, !_isZeroCurrent && _isCurrentProtectEnable, () => {return _enablePowerRoutine.Start(_reclaimCurrentSetPoint) == RState.Running; }, _delay_1ms) .WaitWithStopConditionIf(RunRecipeStep.SetCurrentProtectWait, !_isZeroCurrent && _isCurrentProtectEnable, () => CommonFunction.CheckRoutineEndState(_enablePowerRoutine), () => CommonFunction.CheckRoutineStopState(_enablePowerRoutine)) .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.ChangeRotation, () => ChangeRotationSpeed(_recipe.ReclaimSpeed), _delay_1ms) .Delay(RunRecipeStep.RotationDelay, _recipe.ReclaimTime*1000) .End(RunRecipeStep.End, NullFun); return Runner.Status; } /// /// 停止电源输出 /// /// private bool DisablePower() { return _device.PowerSupplier.DisableOperation("", null); } /// /// rotation改变速度 /// /// /// private bool ChangeRotationSpeed(int speed) { double _scale = _rotationAxis.ScaleFactor; speed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(speed), 0); return _rotationAxis.ChangeSpeed(speed); } /// /// vertical 运行 /// /// 目标位置名称 /// 偏移量 /// private bool StartVertical(string positionName, double offset,int speed,int accelerate) { return _verticalEntity.CheckToPostMessage(eEvent.INFO_PLATINGCELL, _verticalEntity.Module.ToString(), (int)PlatingCellVerticalEntity.VerticalMsg.Position, positionName, offset, speed, accelerate); } /// /// 检验垂直电机是否运动完成 /// /// private bool CheckVerticalEnd() { return _verticalEntity.IsIdle; } /// /// 检验垂直是否出现错误 /// /// private bool CheckVerticalError() { return _verticalEntity.IsError; } /// /// 启动 /// /// /// public RState Start(params object[] objs) { _recipe = (DepRecipe)objs[0]; _isZeroCurrent = (bool)objs[1]; _powerSupplier = (CellPowerSupplier)objs[2]; if (_powerSupplier != null) { _enablePowerRoutine = new PowerSupplierSetCurrentRoutine(_powerSupplier.DeviceID); } _isCurrentProtectEnable = SC.GetValue("PlatingCell.PostProcessCurrentEnable"); _verticalReclaimSpeed = SC.GetValue("PlatingCell.ReclaimSpeed"); _verticalReclaimAcceleration = SC.GetValue("PlatingCell.ReclaimAcceleration"); _reclaimCurrentSetPoint = SC.GetValue("PlatingCell.PostProcessCurrentSetPoint"); _rotationAxis = DEVICE.GetDevice($"{Module}.Rotation"); _device = DEVICE.GetDevice(Module); //获取vertical entity string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module); _verticalEntity = Singleton.Instance.GetModule(vertical); return Runner.Start(Module, "start Reclaim routine"); } } }