123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using MECF.Framework.Common.Beckhoff.AxisProvider;
- using MECF.Framework.Common.Persistent.Reservoirs;
- using MECF.Framework.Common.RecipeCenter;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.ToolLayout;
- using MECF.Framework.Common.Utilities;
- using PunkHPX8_Core;
- using PunkHPX8_RT.Devices.AXIS;
- using PunkHPX8_RT.Devices.PlatingCell;
- using PunkHPX8_RT.Devices.Reservoir;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PunkHPX8_RT.Modules.PlatingCell
- {
- public class PlatingCellCCRRoutine : RoutineBase, IRoutine
- {
- private enum CCRStep
- {
- CSRStart,
- CSRClamshellClose,
- CSROpenRinseValve,
- CSRStartRotation,
- CSRRinseMonitor,
- CSRCloseRinseValve,
- CSRSetDryRotationSpeed,
- CSRCheckRotationStoped,
- CCR1Start,
- CCR1ClamshellOpen,
- OpenCCR1Valve,
- CCR1StartRotation,
- CCR1CCRMonitor,
- CCR1CloseCCRValve,
- CCR1SetDryRotationSpeed,
- CCR1CheckRotationStoped,
- CCR2Start,
- CCR2ClamshellOpen,
- OpenCCR2Valve,
- CCR2StartRotation,
- CCR2CCRMonitor,
- CCR2CloseCCRValve,
- CCR2SetDryRotationSpeed,
- CCR2CheckRotationStoped,
- End
- }
- #region 常量
- /// <summary>
- /// ROTATION电机转速比例
- /// </summary>
- private const int SPEED_RATIO = 1;
- #endregion
- #region 内部变量
- /// <summary>
- /// 设备对象
- /// </summary>
- private PlatingCellDevice _platingCellDevice;
- /// <summary>
- /// Rotation axis
- /// </summary>
- private JetAxisBase _rotationAxis;
- /// <summary>
- /// SRD rotation Provider对象
- /// </summary>
- private BeckhoffProviderAxis _rotationProviderAxis;
- /// <summary>
- /// startRotationTime,用于控制速度改变
- /// </summary>
- private int _startRotationTime;
- /// <summary>
- /// 当前执行到哪一步的显示
- /// </summary>
- private string _currentStep;
- /// <summary>
- /// 当前执行到哪一步的剩余时间
- /// </summary>
- private double _timeRemain;
- private bool _cSREnable;
- private bool _cCR1Enable;
- private bool _cCR2Enable;
- private int _cSRRinseSpeed;
- private int _cSRDrySpeed;
- private double _cSRRinseTime;
- private double _cSRDryTime;
- private int _cCR1RinseSpeed;
- private int _cCR1DrySpeed;
- private double _cCR1RinseTime;
- private double _cCR1DryTime;
- private int _cCR2RinseSpeed;
- private int _cCR2DrySpeed;
- private double _cCR2RinseTime;
- private double _cCR2DryTime;
- /// <summary>
- /// CCR小步骤的启动时间
- /// </summary>
- private DateTime _cSRStartTime;
- private DateTime _cCR1StartTime;
- private DateTime _cCR2StartTime;
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public PlatingCellCCRRoutine(string module) : base(module)
- {
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- Runner.Stop("CCR Manual Abort");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- {
- CheckCurrentStepAndTimeRemain();
- _platingCellDevice.UpdateStatus(_currentStep);
- Runner.RunIf(CCRStep.CSRStart, _cSREnable , () => RecordCCRStepStartTime(out _cSRStartTime), _delay_1ms)
- .RunIf(CCRStep.CSRClamshellClose, _cSREnable , () => _platingCellDevice.ClamShellClose(), CheckClamShellClosed, _delay_1ms)
- .RunIf(CCRStep.CSROpenRinseValve, _cSREnable, OpenRinseValve, _delay_1ms)
- .RunIf(CCRStep.CSRStartRotation, _cSREnable, () => CSRStartRotation(), _delay_1ms)
- .WaitIf(CCRStep.CSRRinseMonitor, _cSREnable, MonitorCSRRinseRotationEndStatus)
- .RunIf(CCRStep.CSRCloseRinseValve, _cSREnable, CloseRinseValve, _delay_1ms)
- .RunIf(CCRStep.CSRSetDryRotationSpeed, _cSREnable, () => ChangeRotationSpeed(_cSRDrySpeed), _delay_1ms)
- .WaitWithStopConditionIf(CCRStep.CSRCheckRotationStoped, _cSREnable, CheckRotationEndStatus, CheckRotationStopStatus)
- .RunIf(CCRStep.CCR1Start, _cCR1Enable, () => RecordCCRStepStartTime(out _cCR1StartTime), _delay_1ms)
- .RunIf(CCRStep.CCR1ClamshellOpen, _cCR1Enable, () => _platingCellDevice.ClamShellOpen(), CheckClamShellOpen, _delay_1ms)
- .RunIf(CCRStep.OpenCCR1Valve, _cCR1Enable, OpenCCRValve, _delay_1ms)
- .RunIf(CCRStep.CCR1StartRotation, _cCR1Enable, () => CCR1StartRotation(), _delay_1ms)
- .WaitIf(CCRStep.CCR1CCRMonitor, _cCR1Enable, MonitorCCR1RotationEndStatus)
- .RunIf(CCRStep.CCR1CloseCCRValve, _cCR1Enable, CloseCCRValve, _delay_1ms)
- .RunIf(CCRStep.CCR1SetDryRotationSpeed, _cCR1Enable, () => ChangeRotationSpeed(_cCR1DrySpeed), _delay_1ms)
- .WaitWithStopConditionIf(CCRStep.CCR1CheckRotationStoped, _cCR1Enable, CheckRotationEndStatus, CheckRotationStopStatus)
- .RunIf(CCRStep.CCR2Start, _cCR2Enable, () => RecordCCRStepStartTime(out _cCR2StartTime), _delay_1ms)
- .RunIf(CCRStep.CCR2ClamshellOpen, _cCR2Enable, () => _platingCellDevice.ClamShellOpen(), CheckClamShellOpen, _delay_1ms)
- .RunIf(CCRStep.OpenCCR2Valve, _cCR2Enable, OpenCCRValve, _delay_1ms)
- .RunIf(CCRStep.CCR2StartRotation, _cCR2Enable, () => CCR2StartRotation(), _delay_1ms)
- .WaitIf(CCRStep.CCR2CCRMonitor, _cCR2Enable, MonitorCCR2RotationEndStatus)
- .RunIf(CCRStep.CCR2CloseCCRValve, _cCR2Enable, CloseCCRValve, _delay_1ms)
- .RunIf(CCRStep.CCR2SetDryRotationSpeed, _cCR2Enable, () => ChangeRotationSpeed(_cCR2DrySpeed), _delay_1ms)
- .WaitWithStopConditionIf(CCRStep.CCR2CheckRotationStoped, _cCR2Enable, CheckRotationEndStatus, CheckRotationStopStatus)
- .End(CCRStep.End, NullFun, _delay_1ms);
- return Runner.Status;
- }
- /// <summary>
- /// 记录ccr step 起始时间
- /// </summary>
- /// <param name="dateTime"></param>
- /// <returns></returns>
- private bool RecordCCRStepStartTime(out DateTime dateTime)
- {
- dateTime = DateTime.Now;
- return true;
- }
- /// <summary>
- /// 判断当前处于ccr的哪一步
- /// </summary>
- private void CheckCurrentStepAndTimeRemain()
- {
- string currentStep = Runner.CurrentStep.ToString();
- if (currentStep.Contains("CSR"))
- {
- _currentStep ="CSR Rinse/Dry";
- _timeRemain = _cSRRinseTime + _cSRDryTime - (DateTime.Now - _cSRStartTime).TotalSeconds > 0 ? _cSRRinseTime + _cSRDryTime - (DateTime.Now - _cSRStartTime).TotalSeconds : 0;
- }
- else if (currentStep.Contains("CCR1"))
- {
- _currentStep = "CCR Cycle1 Rinse/Dry";
- _timeRemain = _cCR1RinseTime + _cCR1DryTime - (DateTime.Now - _cCR1StartTime).TotalSeconds > 0 ? _cCR1RinseTime + _cCR1DryTime - (DateTime.Now - _cCR1StartTime).TotalSeconds : 0;
- }
- else if (currentStep.Contains("CCR2"))
- {
- _currentStep = "CCR Cycle2 Rinse/Dry";
- _timeRemain = _cCR2RinseTime + _cCR2DryTime - (DateTime.Now - _cCR2StartTime).TotalSeconds > 0 ? _cCR2RinseTime + _cCR2DryTime - (DateTime.Now - _cCR2StartTime).TotalSeconds : 0;
- }
- else
- {
- _currentStep = "End";
- _timeRemain = 0;
- }
- _platingCellDevice.UpdateCCRTimeRemain(_timeRemain);
- }
- /// <summary>
- /// 打开CCR valve
- /// </summary>
- /// <returns></returns>
- private bool OpenCCRValve()
- {
- return _platingCellDevice.CCREnableAction();
- }
- /// <summary>
- /// 关闭CCR valve
- /// </summary>
- /// <returns></returns>
- private bool CloseCCRValve()
- {
- return _platingCellDevice.CCRDisableAction();
- }
- /// <summary>
- /// 打开Rinse valve
- /// </summary>
- /// <returns></returns>
- private bool OpenRinseValve()
- {
- return _platingCellDevice.RinseEnableAction();
- }
- /// <summary>
- /// 关闭Rinse valve
- /// </summary>
- /// <returns></returns>
- private bool CloseRinseValve()
- {
- return _platingCellDevice.RinseDisableAction();
- }
- /// <summary>
- /// 检查ClamShell是否closed
- /// </summary>
- /// <returns></returns>
- private bool CheckClamShellClosed()
- {
- return _platingCellDevice.PlatingCellDeviceData.ClamShellClose;
- }
- /// <summary>
- /// 检查ClamShell是否Open
- /// </summary>
- /// <returns></returns>
- private bool CheckClamShellOpen()
- {
- return !_platingCellDevice.PlatingCellDeviceData.ClamShellClose;
- }
- /// <summary>
- /// 检验Rotation是否停止
- /// </summary>
- /// <returns></returns>
- private bool CheckRotationEndStatus()
- {
- if (!_rotationAxis.IsRun && _rotationAxis.Status == RState.End)
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// 检验Rotation停止状态
- /// </summary>
- /// <returns></returns>
- private bool CheckRotationStopStatus()
- {
- if (_rotationAxis.Status == RState.Failed || _rotationAxis.Status == RState.Timeout)
- {
- NotifyError(eEvent.ERR_PLATINGCELL, $"{Module}.Rotation is failed", 0);
- return true;
- }
- return false;
- }
- /// <summary>
- /// CSR阶段rotation开始旋转
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool CSRStartRotation()
- {
- double _scale = _rotationProviderAxis.ScaleFactor;
- //rinse 目标位置
- double rinsePosition = _cSRRinseTime * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_cSRRinseSpeed);
- //dry目标位置
- double dryPosition = BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_cSRDrySpeed) * _cSRDryTime;
- int targetPosition = (int)Math.Round((rinsePosition + dryPosition ) * _scale, 0);
- int rotationSpeed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_cSRRinseSpeed), 0);
- //启动先用rinse的speed,时间到了转成用dry的speed
- bool result = _rotationAxis.ProfilePosition(targetPosition, rotationSpeed * SPEED_RATIO, 0, 0);
- if (!result)
- {
- NotifyError(eEvent.ERR_PLATINGCELL, "Start Rotation is failed", 0);
- return false;
- }
- LOG.WriteLog(eEvent.INFO_PLATINGCELL, Module, "Start CSR Step Rinse Rotation");
- //Rinse开始时间
- _startRotationTime = Environment.TickCount;
- return true;
- }
- /// <summary>
- /// WaterFlow End Monitor
- /// </summary>
- /// <returns></returns>
- private bool MonitorCSRRinseRotationEndStatus()
- {
- int ticks = Environment.TickCount - _startRotationTime;
- if (ticks >= _cSRRinseTime * 1000)
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// CCR1阶段rotation开始旋转
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool CCR1StartRotation()
- {
- double _scale = _rotationProviderAxis.ScaleFactor;
- //rinse 目标位置
- double rinsePosition = _cCR1RinseTime * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_cCR1RinseSpeed);
- //dry目标位置
- double dryPosition = BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_cCR1DrySpeed) * _cCR1DryTime;
- int targetPosition = (int)Math.Round((rinsePosition + dryPosition) * _scale, 0);
- int rotationSpeed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_cCR1RinseSpeed), 0);
- //启动先用rinse的speed,时间到了转成用dry的speed
- bool result = _rotationAxis.ProfilePosition(targetPosition, rotationSpeed * SPEED_RATIO, 0, 0);
- if (!result)
- {
- NotifyError(eEvent.ERR_PLATINGCELL, "Start Rotation is failed", 0);
- return false;
- }
- LOG.WriteLog(eEvent.INFO_PLATINGCELL, Module, "Start CCR1 Step Rinse Rotation");
- //Rinse开始时间
- _startRotationTime = Environment.TickCount;
- return true;
- }
- /// <summary>
- /// CCR1 WaterFlow End Monitor
- /// </summary>
- /// <returns></returns>
- private bool MonitorCCR1RotationEndStatus()
- {
- int ticks = Environment.TickCount - _startRotationTime;
- if (ticks >= _cCR1RinseTime * 1000)
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// CCR2阶段rotation开始旋转
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool CCR2StartRotation()
- {
- double _scale = _rotationProviderAxis.ScaleFactor;
- //rinse 目标位置
- double rinsePosition = _cCR2RinseTime * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_cCR2RinseSpeed);
- //dry目标位置
- double dryPosition = BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_cCR2DrySpeed) * _cCR2DryTime;
- int targetPosition = (int)Math.Round((rinsePosition + dryPosition) * _scale, 0);
- int rotationSpeed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_cCR2RinseSpeed), 0);
- //启动先用rinse的speed,时间到了转成用dry的speed
- bool result = _rotationAxis.ProfilePosition(targetPosition, rotationSpeed * SPEED_RATIO, 0, 0);
- if (!result)
- {
- NotifyError(eEvent.ERR_PLATINGCELL, "Start Rotation is failed", 0);
- return false;
- }
- LOG.WriteLog(eEvent.INFO_PLATINGCELL, Module, "Start CCR2 Step Rinse Rotation");
- //Rinse开始时间
- _startRotationTime = Environment.TickCount;
- return true;
- }
- /// <summary>
- /// CCR2 WaterFlow End Monitor
- /// </summary>
- /// <returns></returns>
- private bool MonitorCCR2RotationEndStatus()
- {
- int ticks = Environment.TickCount - _startRotationTime;
- if (ticks >= _cCR2RinseTime * 1000)
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// 改变速度
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- private bool ChangeRotationSpeed(int speed)
- {
- double _scale = _rotationProviderAxis.ScaleFactor;
- speed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(speed), 0);
- return _rotationAxis.ChangeSpeed(speed);
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- public RState Start(params object[] objs)
- {
- _platingCellDevice = DEVICE.GetDevice<PlatingCellDevice>(Module);
- _cSREnable = SC.GetValue<bool>("PlatingCell.CSR.CSREnable");
- _cCR1Enable = SC.GetValue<bool>("PlatingCell.CCR1.CCR1Enable");
- _cCR2Enable = SC.GetValue<bool>("PlatingCell.CCR2.CCR2Enable");
- _cSRRinseSpeed = SC.GetValue<int>("PlatingCell.CSR.RinseSpeed");
- _cSRDrySpeed = SC.GetValue<int>("PlatingCell.CSR.DrySpeed");
- _cSRRinseTime = SC.GetValue<double>("PlatingCell.CSR.RinseTime");
- _cSRDryTime = SC.GetValue<double>("PlatingCell.CSR.DryTime");
- _cCR1RinseSpeed = SC.GetValue<int>("PlatingCell.CCR1.RinseSpeed");
- _cCR1DrySpeed = SC.GetValue<int>("PlatingCell.CCR1.DrySpeed");
- _cCR1RinseTime = SC.GetValue<double>("PlatingCell.CCR1.RinseTime");
- _cCR1DryTime = SC.GetValue<double>("PlatingCell.CCR1.DryTime");
- _cCR2RinseSpeed = SC.GetValue<int>("PlatingCell.CCR2.RinseSpeed");
- _cCR2DrySpeed = SC.GetValue<int>("PlatingCell.CCR2.DrySpeed");
- _cCR2RinseTime = SC.GetValue<double>("PlatingCell.CCR2.RinseTime");
- _cCR2DryTime = SC.GetValue<double>("PlatingCell.CCR2.DryTime");
- _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
- _rotationProviderAxis = BeckhoffAxisProviderManager.Instance.GetAxisProvider($"{Module}.Rotation");
- if (_rotationProviderAxis == null)
- {
- NotifyError(eEvent.ERR_SRD, $"{Module}.Rotation Provider is not exist", 0);
- return RState.Failed;
- }
- return Runner.Start(Module, "Start Reservoir Initialize");
- }
- }
- }
|