| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.Util;
- using MECF.Framework.Common.Beckhoff.Station;
- using MECF.Framework.Common.CommonData.PowerSupplier;
- 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 PlatingCellDepositionRoutine : RoutineBase, IRoutine
- {
- private enum RunRecipeStep
- {
- RunPowerStep,
- RunPowerStepWait,
- LoopRotationStart,
- LoopVerticalGotoOffSet,
- LoopVerticalGotoOffSetCheck,
- LoopRotationStartIfCurrentIsStoped,//如果当前电机是停止状态,启动起来
- LoopRotationChangeSpeed,
- LoopRotationDelay,
- LoopRotationStopIfCurrentIsRuning, //如果当前电机是启动状态,则停止
- LoopROtationStopCheck,
- LoopRotationBiRotation,
- LoopRotationBiRotationCheck,
- LoopUpdateDepositionIndex,
- LoopEnd,
- RotationStartIfCurrentIsStoped,
- End
- }
- #region 常量
- /// <summary>
- /// ROTATION电机转速比例
- /// </summary>
- private const int SPEED_RATIO = 1;
- private const int ROTATION_FAR_POSITION = 12 * 60 * 60 * 500 * 6; //以500rmp 运行12个小时的位置
- #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>
- /// vertical 轴的位置数据
- /// </summary>
- private BeckhoffStationAxis _verticalBeckhoffStation;
- /// <summary>
- /// 不通电
- /// </summary>
- private bool _isZeroCurrent = false;
- /// <summary>
- /// 是否双有双向旋转
- /// </summary>
- private bool _isBiRotation = false;
- /// <summary>
- /// 是否启动smart spin
- /// </summary>
- private bool _isSmartSpin = false;
- /// <summary>
- /// Power step集合
- /// </summary>
- List<PowerSupplierStepPeriodData> _powerSupplierStepPeriodDatas = new List<PowerSupplierStepPeriodData>();
- /// <summary>
- /// 双向旋转routine
- /// </summary>
- private RotationBiDirectionRoutine _rotationBiDirectionRoutine;
- /// <summary>
- /// Plating启动时间
- /// </summary>
- private DateTime _platingStartTime;
- /// <summary>
- /// 当前执行到电镀步骤的索引
- /// </summary>
- private int _depositionStepIndex = 0;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public PlatingCellDepositionRoutine(string module) : base(module)
- {
- _rotationBiDirectionRoutine = new RotationBiDirectionRoutine(module);
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- Runner.Stop("Manual Abort");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- {
- Runner //没有上电保护,此刻给电
- .RunIf(RunRecipeStep.RunPowerStep, _recipe.IsEntryTypeCold, StartPowerStep, _delay_1ms)
- .LoopStart(RunRecipeStep.LoopRotationStart, "Start rotation cycle",_recipe.DepStepCount,NullFun)
- //vertical 调整位置
- .LoopRunIf(RunRecipeStep.LoopVerticalGotoOffSet, _recipe.DepSteps[_depositionStepIndex].PlatingZoffset!=0, () => StartVertical("Plate", _recipe.DepSteps[_depositionStepIndex].PlatingZoffset),_delay_1ms)
- .LoopRunIf(RunRecipeStep.LoopVerticalGotoOffSetCheck, _recipe.DepSteps[_depositionStepIndex].PlatingZoffset!=0, CheckVerticalEnd, CheckVerticalError)
-
- //不带双向旋转,时间到了直接变速(如果当前电机是停止状态,启动起来)
- .LoopRunIf(RunRecipeStep.LoopRotationStartIfCurrentIsStoped, CheckRotationIsIdle() && !_recipe.DepSteps[_depositionStepIndex].BiDireaction,
- () => { return StartRotation(ROTATION_FAR_POSITION); }, _delay_1ms)
- .LoopRunIf(RunRecipeStep.LoopRotationChangeSpeed, !_recipe.DepSteps[_depositionStepIndex].BiDireaction,() => ChangeRotationSpeed(_recipe.DepSteps[_depositionStepIndex].PlatingSpeed),_delay_1ms)
- .LoopDelayIf(RunRecipeStep.LoopRotationDelay, !_recipe.DepSteps[_depositionStepIndex].BiDireaction, _recipe.DepSteps[_depositionStepIndex].DurartionSeconds *1000)
-
- //带双向旋转,启动双向旋转的routine(如果当前电机是启动状态,则停止)
- .LoopRunIf(RunRecipeStep.LoopRotationStopIfCurrentIsRuning, checkRotationIsRunning() && _recipe.DepSteps[_depositionStepIndex].BiDireaction,
- _rotationAxis.StopPositionOperation, _delay_1ms)
- .LoopRunIfWithStopStatus(RunRecipeStep.LoopROtationStopCheck, checkRotationIsRunning() && _recipe.DepSteps[_depositionStepIndex].BiDireaction,
- CheckRotationIsIdle, CheckRotationPositionRunStop)
- .LoopRunIf(RunRecipeStep.LoopRotationBiRotation, _recipe.DepSteps[_depositionStepIndex].BiDireaction,
- () => _rotationBiDirectionRoutine.Start(_recipe.DepSteps[_depositionStepIndex].DurartionSeconds, _recipe.DepSteps[_depositionStepIndex].BiDFrequency, _recipe.DepSteps[_depositionStepIndex].PlatingSpeed) == RState.Running,_delay_1ms)
- .LoopRunIfWithStopStatus(RunRecipeStep.LoopRotationBiRotationCheck, _recipe.DepSteps[_depositionStepIndex].BiDireaction,
- () => CommonFunction.CheckRoutineEndState(_rotationBiDirectionRoutine),
- () => CommonFunction.CheckRoutineStopState(_rotationBiDirectionRoutine))
-
- .LoopRun(RunRecipeStep.LoopUpdateDepositionIndex, UpdateDepositionIndex, _delay_1ms)
- .LoopEnd(RunRecipeStep.LoopEnd,NullFun,_delay_1ms)
- //检验步阶电流是否完成
- .WaitWithStopCondition(RunRecipeStep.RunPowerStepWait, CheckRecipeStepEndStatus, CheckRecipeStepStopStatus, _delay_1ms)
-
- //如果电镀最后一步带双向旋转,后续电机会停止,需要再把电机启动起来
- .RunIf(RunRecipeStep.RotationStartIfCurrentIsStoped, CheckRotationIsIdle(), () => { return StartRotation(ROTATION_FAR_POSITION); }, _delay_1ms)
- .End(RunRecipeStep.End, NullFun);
- return Runner.Status;
- }
- /// <summary>
- /// 判断当前电机是否在转
- /// </summary>
- /// <returns></returns>
- private bool checkRotationIsRunning()
- {
- return _rotationAxis.Status == RState.Running;
- }
- /// <summary>
- /// 判断电机当前状态是否停止
- /// </summary>
- /// <returns></returns>
- private bool CheckRotationIsIdle()
- {
- return _rotationAxis.Status == RState.End;
- }
- /// <summary>
- /// 检验Rotation是否运动失败
- /// </summary>
- /// <returns></returns>
- private bool CheckRotationPositionRunStop()
- {
- return _rotationAxis.Status == RState.Failed || _rotationAxis.Status == RState.Timeout;
- }
- /// <summary>
- /// 更新电镀步骤索引
- /// </summary>
- /// <returns></returns>
- private bool UpdateDepositionIndex()
- {
- _depositionStepIndex++;
- return true;
- }
- /// <summary>
- /// 启动PowerSupplier
- /// </summary>
- /// <returns></returns>
- private bool StartPowerStep()
- {
- bool result = _device.PowerSupplier.StartSetStepPeriodNoWaitEnd(_powerSupplierStepPeriodDatas);
- if (!result)
- {
- _device.PowerSupplier.DisableOperation("", null);
- return false;
- }
- _platingStartTime = DateTime.Now;
- return true;
- }
- /// <summary>
- /// 检验Powerstep是否启动完成
- /// </summary>
- /// <returns></returns>
- private bool CheckRecipeStepEndStatus()
- {
- if (_isZeroCurrent)
- {
- return true;
- }
- return _device.PowerSupplier.Status == RState.End;
- }
- /// <summary>
- /// 检验Powerstep是否启动失败
- /// </summary>
- /// <returns></returns>
- private bool CheckRecipeStepStopStatus()
- {
- if (_isZeroCurrent)
- {
- return false;
- }
- return _device.PowerSupplier.Status == RState.Failed || _device.PowerSupplier.Status == RState.Timeout;
- }
- /// <summary>
- /// rotation开始旋转
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool StartRotation(int targetPosition)
- {
- bool result = _rotationAxis.ProfilePosition(targetPosition, _recipe.IntervalRinseSpeed * SPEED_RATIO * 6, 0, 0); //rpm->deg/s
- if (!result)
- {
- NotifyError(eEvent.ERR_PLATINGCELL, "Start Rotation is failed", 0);
- return false;
- }
- return true;
- }
- /// <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)
- {
- return _verticalEntity.CheckToPostMessage<PlatingCellVerticalState, PlatingCellVerticalEntity.VerticalMsg>(Aitex.Core.RT.Log.eEvent.INFO_PLATINGCELL,
- Module, (int)PlatingCellVerticalEntity.VerticalMsg.Position, positionName, offset);
- }
- /// <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];
- _isBiRotation = (bool)objs[2];
- _powerSupplierStepPeriodDatas = (List<PowerSupplierStepPeriodData>)objs[3];
- _platingStartTime = (DateTime)objs[4];
- _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
- _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
- _depositionStepIndex = 0;
- //获取vertical entity
- string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module);
- _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
- //获取vertical station信息对象
- _verticalBeckhoffStation = BeckhoffStationLocationManager.Instance.GetStationAxis($"{_verticalEntity.Module}", "Vertical");
- return Runner.Start(Module, "start intervale rinse");
- }
- }
- }
|