| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- 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 PlatingCellEntryRoutine : RoutineBase, IRoutine
- {
- private enum RunRecipeStep
- {
- RotationStartEntry,
- RotationChangeToEntrySpeed,
- AngleTilt,
- VerticalGotoPlate,
- WaitEntryCurrentProtectedFromRinse,
- WaitEntryCurrentProtectedFromHome,
- RunPowerStepWithEntryProtect,
- CheckVerticalGotoPlate,
- AngleVertical,
- WaitPlatingDelay,
- End
- }
- #region 常量
- /// <summary>
- /// ROTATION电机转速比例
- /// </summary>
- private const int SPEED_RATIO = 1;
- #endregion
- /// <summary>
- /// recipe
- /// </summary>
- private DepRecipe _recipe;
- /// <summary>
- /// Rotation axis
- /// </summary>
- private JetAxisBase _rotationAxis;
- /// <summary>
- /// Vertical axis
- /// </summary>
- private JetAxisBase _verticalAxis;
- /// <summary>
- /// Platingcell device
- /// </summary>
- private PlatingCellDevice _device;
- /// <summary>
- /// rotation运动的目的地
- /// </summary>
- private int _rotationgTargetPosition;
- /// <summary>
- /// vertical axis entity
- /// </summary>
- private PlatingCellVerticalEntity _verticalEntity;
- /// <summary>
- /// Power step集合
- /// </summary>
- List<PowerSupplierStepPeriodData> _powerSupplierStepPeriodDatas = new List<PowerSupplierStepPeriodData>();
- /// <summary>
- /// Plating启动时间
- /// </summary>
- private DateTime _platingStartTime;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public PlatingCellEntryRoutine(string module) : base(module)
- {
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- Runner.Stop("Manual Abort");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- { //启动Rotation/Rotation 设置为entry 转速 (没有intercal rinse 在entry开始的时候启动rotation)
- Runner.RunIf(RunRecipeStep.RotationStartEntry, !_recipe.RinseBeforeEntryEnable, RotationStartEntry, _delay_1ms)
- //有intercal rinse 直接变速 (rotation在interval rinse的时候已经启动了)
- .RunIf(RunRecipeStep.RotationChangeToEntrySpeed, _recipe.RinseBeforeEntryEnable, () => { return ChangeSpeed(_recipe.EntrySpinSpeed); }, _delay_1ms)
- //Angle tilt 操作
- .Run(RunRecipeStep.AngleTilt, _device.HeadtTiltAction, () => { return _device.PlatingCellDeviceData.IsHeadTilt; }, _delay_1s)
- //vertical goto plate
- .Run(RunRecipeStep.VerticalGotoPlate, () => { return StartVertical("Plate", _recipe.DepSteps[0].PlatingZoffset); }, _delay_1ms)
- //vertical 到达entry位置前110ms (多10ms)
- .Delay(RunRecipeStep.WaitEntryCurrentProtectedFromRinse, CalculatePowerDelayTime())
- //有上电保护,此刻给电
- .RunIf(RunRecipeStep.RunPowerStepWithEntryProtect, !_recipe.IsEntryTypeCold, StartPowerStep, _delay_1ms)
- //检查vertical到达plate位置
- .WaitWithStopCondition(RunRecipeStep.CheckVerticalGotoPlate, CheckVerticalEnd, CheckVerticalError)
- //Angle vertical操作
- .Run(RunRecipeStep.AngleVertical, _device.HeadtVerticalAction, () => { return _device.PlatingCellDeviceData.IsHeadVertical; }, _delay_1s)
- //如果不需要上电保护,执行plating delay
- .DelayIf(RunRecipeStep.WaitPlatingDelay, _recipe.IsEntryTypeCold, _recipe.PlatingDelay * 1000)
- .End(RunRecipeStep.End, NullFun);
- return Runner.Status;
- }
- /// <summary>
- /// 计算出上电前需要delay的时间
- /// </summary>
- /// <returns> 返回值单位ms</returns>
- private int CalculatePowerDelayTime()
- {
- int delayTime = 0;
- if (_recipe.RinseBeforeEntryEnable)
- {
- delayTime = _verticalAxis.CalculateVerticaMoveTime($"{_verticalAxis.Module}.Vertical", "Rinse", "Entry", 0 ,_recipe.EntryZoffset) - 110;
- }
- else
- {
- delayTime = _verticalAxis.CalculateVerticaMoveTime($"{_verticalAxis.Module}.Vertical", "Load", "Entry", 0, _recipe.EntryZoffset) - 110;
- }
- return delayTime;
- }
- /// <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>
- /// rotation 从entry步骤开始旋转
- /// </summary>
- /// <returns></returns>
- private bool RotationStartEntry()
- {
- bool result = _rotationAxis.ProfilePosition(_rotationgTargetPosition, _recipe.EntrySpinSpeed * SPEED_RATIO, 0, 0);
- if (!result)
- {
- NotifyError(eEvent.ERR_PLATINGCELL, "Start Rotation is failed", 0);
- return false;
- }
- return true;
- }
- /// <summary>
- /// change speed
- /// </summary>
- /// <returns></returns>
- private bool ChangeSpeed(int speed) //参数speed单位是rmp
- {
- double realSpeed = BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(speed);
- bool result = _rotationAxis.ChangeSpeed((int)realSpeed);
- if (!result)
- {
- NotifyError(eEvent.ERR_PLATINGCELL, "Change Speed failed", 0);
- return false;
- }
- return true;
- }
- /// <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];
- _rotationgTargetPosition = (int)objs[1];
- _powerSupplierStepPeriodDatas = (List<PowerSupplierStepPeriodData>)objs[2];
- _platingStartTime = (DateTime)objs[3];
- _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);
- _verticalAxis = DEVICE.GetDevice<JetAxisBase>($"{vertical}.Vertical");//不能用来移动,移动用vertical entity来操作
- return Runner.Start(Module, "start Entry routine");
- }
- }
- }
|