| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 | using Aitex.Core.RT.Device;using Aitex.Core.RT.Routine;using MECF.Framework.Common.Equipment;using MECF.Framework.Common.Routine;using CyberX8_Core;using CyberX8_RT.Devices.AXIS;using CyberX8_RT.Devices.Loader;using System;using System.Collections.Generic;using Aitex.Core.RT.Log;using MECF.Framework.Common.Utilities;using MECF.Framework.Common.CommonData.Loader;using MECF.Framework.Common.CommonData;using Aitex.Core.RT.DataCenter;namespace CyberX8_RT.Modules.Loader{    public class LoaderUnloadAllSideRoutine : RoutineBase, IRoutine    {        private enum UnloadStep        {            RotationGoToLOADA,            RotationGoToLOADAWait,            SideAUnload,            Delay,            SideBUnload,            UnloadAllWait,            End        }        #region 常量        private const string SIDE_A = "SideA";        private const string SIDE_B = "SideB";        private const int LOTTRACK_TIME = 1000;        #endregion        #region 内部变量        private JetAxisBase _rotationAxis;        private LoaderUnloadRoutine _sideAUnloadRoutine;        private LoaderUnloadRoutine _sideBUnloadRoutine;        private bool _isSideAUnloaded = false;        private bool _isSideBunloaded = false;        private bool _isSideAStop = false;        private bool _isSideBStop = false;        /// <summary>        /// lotTrack time        /// </summary>        private DateTime _lotTackTime = DateTime.Now;        /// <summary>        /// Loader Common        /// </summary>        private LoaderCommonDevice _loaderCommon;        /// <summary>        /// LoaderSide A        /// </summary>        private LoaderSideDevice _loaderSideA;        /// <summary>        /// LoaderSide B        /// </summary>        private LoaderSideDevice _loaderSideB;        /// <summary>        /// Loader LotTrackData        /// </summary>        private List<LoaderLotTrackData> _datas = new List<LoaderLotTrackData>();        #endregion        #region 属性        /// <summary>        /// UnLoad LotTrackData        /// </summary>        public List<LoaderLotTrackData> UnloadLotTrackDatas { get { return _datas; } }        #endregion        /// <summary>        /// 构造函数        /// </summary>        /// <param name="module"></param>        public LoaderUnloadAllSideRoutine(string module) : base(module)        {        }        /// <summary>        /// 中止        /// </summary>        public void Abort()        {        }        /// <summary>        /// 监控        /// </summary>        /// <returns></returns>        public RState Monitor()        {            LottrackRecord();            Runner.Run(UnloadStep.RotationGoToLOADA,RotationGotoLOADA,_delay_1ms)                .WaitWithStopCondition(UnloadStep.RotationGoToLOADAWait,CheckRotationPositionStatus,CheckRotationPositionRunStop)                .Run(UnloadStep.SideAUnload, () => StartUnloadRoutine(_sideAUnloadRoutine,_isSideAUnloaded), _delay_1ms)                .Delay(UnloadStep.Delay,500)                .Run(UnloadStep.SideBUnload, () => StartUnloadRoutine(_sideBUnloadRoutine,_isSideBunloaded), _delay_1ms)                .WaitWithStopCondition(UnloadStep.UnloadAllWait, CheckUnloadAllRoutineEndStatus,CheckUnloadAllRoutineStopStatus)                .End(UnloadStep.End, NullFun, _delay_1ms);            return Runner.Status;        }        /// <summary>        /// Rotation Goto LOADA        /// </summary>        /// <returns></returns>        private bool RotationGotoLOADA()        {            bool result = _rotationAxis.PositionStation("LOADA", false);            if (!result)            {                NotifyError(eEvent.ERR_LOADER, "rotation start goto LOADA failed", 0);            }            return result;        }        /// <summary>        /// 检验Rotation移动状态        /// </summary>        /// <returns></returns>        private bool CheckRotationPositionStatus()        {            return _rotationAxis.Status == RState.End;        }        /// <summary>        /// 检验Rotation是否还在运动        /// </summary>        /// <returns></returns>        private bool CheckRotationPositionRunStop()        {            bool result = _rotationAxis.Status == RState.Failed || _rotationAxis.Status == RState.Timeout ;            if (result)            {                NotifyError(eEvent.ERR_LOADER, "rotation goto position failed",0);            }            return result;        }        /// <summary>        /// 启动Unload routine        /// </summary>        /// <param name="unloadRoutine"></param>        /// <returns></returns>        private bool StartUnloadRoutine(LoaderUnloadRoutine unloadRoutine,bool isSideUnloaded)        {            if (isSideUnloaded)            {                return true;            }            bool result= unloadRoutine.Start()==RState.Running;            if(!result)            {                NotifyError(eEvent.ERR_LOADER, unloadRoutine.ErrorMsg, 0);            }            return result;        }        /// <summary>        /// 检验UnloadAll完成状态        /// </summary>        /// <returns></returns>        private bool CheckUnloadAllRoutineEndStatus()        {            bool sideAResult = true;            if (!_isSideAUnloaded)            {                sideAResult = CheckUnloadRoutineEndStatus(_sideAUnloadRoutine);            }            bool sideBResult = true;            if (!_isSideBunloaded)            {                sideBResult = CheckUnloadRoutineEndStatus(_sideBUnloadRoutine);            }            return sideAResult && sideBResult;        }        /// <summary>        /// 检查UnloadAll停止状态        /// </summary>        /// <returns></returns>        private bool CheckUnloadAllRoutineStopStatus()        {            bool sideAComplete = false;            if (!_isSideAUnloaded&&!_isSideAStop)            {                RState ret = _sideAUnloadRoutine.Monitor();                _isSideAStop = ret == RState.Failed || ret == RState.Timeout;                sideAComplete = (ret != RState.Running);                if (_isSideAStop)                {                    NotifyError(eEvent.ERR_LOADER, $"unload A failed\r\n{_sideAUnloadRoutine.ErrorMsg}", 1);                }            }            bool sideBComplete = false;            if(!_isSideBunloaded&&!_isSideBStop)            {                RState ret = _sideBUnloadRoutine.Monitor();                _isSideBStop = ret == RState.Failed || ret == RState.Timeout;                sideBComplete = (ret != RState.Running);                if (_isSideBunloaded)                {                    NotifyError(eEvent.ERR_LOADER, $"unload B failed\r\n{_sideBUnloadRoutine.ErrorMsg}", 1);                }            }            return (_isSideAStop && sideBComplete) || (_isSideBStop && sideAComplete);        }        /// <summary>        /// 检验routine完成状态        /// </summary>        /// <param name="unloadRoutine"></param>        /// <returns></returns>        private bool CheckUnloadRoutineEndStatus(LoaderUnloadRoutine unloadRoutine)        {            return unloadRoutine.Monitor() == RState.End;        }        /// <summary>        /// 检验Routine结束状态        /// </summary>        /// <param name="unloadRoutine"></param>        /// <returns></returns>        private bool CheckUnloadRoutineStopStatus(LoaderUnloadRoutine unloadRoutine,string side)         {            RState state=unloadRoutine.Monitor();            if (state == RState.Failed || state == RState.Timeout)            {                NotifyError(eEvent.ERR_LOADER, $"{side} Unload failed", 0);                return true;            }            return false;        }        /// <summary>        /// 启动        /// </summary>        /// <param name="objs"></param>        /// <returns></returns>        public RState Start(params object[] objs)        {            InitializeParameters();            _loaderCommon = DEVICE.GetDevice<LoaderCommonDevice>($"{Module}.Common");            _loaderSideA = DEVICE.GetDevice<LoaderSideDevice>($"{Module}.SideA");            _loaderSideB = DEVICE.GetDevice<LoaderSideDevice>($"{Module}.SideB");            return Runner.Start(Module, "Start UnloadAll");        }        /// <summary>        /// 初始化参数        /// </summary>        private void InitializeParameters()        {            _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");            _sideAUnloadRoutine = new LoaderUnloadRoutine(ModuleName.Loader1.ToString(), "SideA");            _sideBUnloadRoutine = new LoaderUnloadRoutine(ModuleName.Loader1.ToString(), "SideB");            _isSideAUnloaded = false;            _isSideBunloaded = false;            _isSideAStop = false;            _isSideBStop = false;        }        /// <summary>        /// 重试        /// </summary>        /// <param name="step"></param>        public RState Retry(int step)        {            InitializeParameters();            List<Enum> preStepIds = new List<Enum>();            if (step == 0||step==-1)            {                return Runner.Retry(UnloadStep.RotationGoToLOADA,preStepIds,Module,"UnloadAll Retry");            }            else            {                _isSideAUnloaded = CheckSideUnloadCondition("A", step,false);                _isSideBunloaded= CheckSideUnloadCondition("B", step,false);                AddPreSteps(UnloadStep.SideAUnload, preStepIds);                return Runner.Retry(UnloadStep.SideBUnload,preStepIds, Module, $"UnloadAll step {UnloadStep.SideBUnload} Retry");            }        }        /// <summary>        /// 忽略前        /// </summary>        /// <param name="step"></param>        /// <param name="preStepIds"></param>        private void AddPreSteps(UnloadStep step,List<Enum> preStepIds)        {            for(int i = 0;i<(int)step;i++)            {                preStepIds.Add((UnloadStep)i);            }        }        /// <summary>        /// 检验前面Unload完成状态        /// </summary>        /// <returns></returns>        public bool CheckCompleteCondition(int index)        {            if (!CheckSideUnloadCondition("A", index,true))            {                return false;            }            if (!CheckSideUnloadCondition("B", index, true))            {                return false;            }            return true;        }        /// <summary>        /// 检验Side Unload情况         /// </summary>        /// <param name="side"></param>        /// <param name="index"></param>        /// <returns></returns>        private bool CheckSideUnloadCondition(string side, int index,bool showError)        {            JetAxisBase shuttleAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.Shuttle{side}");            double shuttlePosition = shuttleAxis.MotionData.MotorPosition;            if (!shuttleAxis.CheckPositionIsInStation(shuttlePosition, "OPEN"))            {                if (showError)                {                    NotifyError(eEvent.ERR_LOADER, $"shuttle{side} {shuttlePosition} is not in open", index);                }                return false;            }            JetAxisBase tiltAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.Tilt{side}");            double tiltPosition = tiltAxis.MotionData.MotorPosition;            if (!tiltAxis.CheckPositionIsInStation(tiltPosition, "HORI"))            {                if (showError)                {                    NotifyError(eEvent.ERR_LOADER, $"tilt{side} {tiltPosition} is not in HORI", index);                    return false;                }            }            JetAxisBase crsAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.LS{side}");            double crsPosition = crsAxis.MotionData.MotorPosition;            if (!crsAxis.CheckPositionIsInStation(crsPosition, "Unlock"))            {                if (showError)                {                    NotifyError(eEvent.ERR_LOADER, $"LS{side} {crsPosition} is not in Unlock", index);                }                return false;            }            LoaderSideDevice loaderSideDevice = DEVICE.GetDevice<LoaderSideDevice>($"{ModuleName.Loader1}.Side{side}");            if (loaderSideDevice.SideData.DoorLowerLocked || loaderSideDevice.SideData.DoorUpperLocked)            {                if (showError)                {                    NotifyError(eEvent.ERR_LOADER, $"side{side} door locked", index);                }            }            return true;        }        /// <summary>        /// 记录Lottrack        /// </summary>        private void LottrackRecord()        {            //记录Lottrack            if (DateTime.Now.Subtract(_lotTackTime).TotalMilliseconds >= LOTTRACK_TIME)            {                AddLotTrackData();                _lotTackTime = DateTime.Now;            }        }        /// <summary>        /// 获取Lot Track数据        /// </summary>        /// <returns></returns>        private void AddLotTrackData()        {            LoaderLotTrackData data = new LoaderLotTrackData();            data.TimeStamp = DateTime.Now;            data.LoaderABernoulliBladderEnable = _loaderSideA.SideData.BernoulliBladder;            data.LoaderABernoulliExtended = _loaderSideA.SideData.BernoulliExtended;            data.LoaderABernoulliBladderPressure = _loaderSideA.SideData.BernoulliBladderPressure;            data.LoaderABernoulliN2Pressure = _loaderSideA.SideData.BernoulliPressure;            data.LoaderACRSVacuum = _loaderSideA.SideData.CRSVacuum;            data.LoaderACRSVacuumAnlg = _loaderSideA.SideData.CRSVacuumValue;            data.LoaderAWHPressure = _loaderSideA.SideData.WHBladderPressure;            data.LoaderATranslatePressure = _loaderSideA.SideData.TransPressure;            data.LoaderBBernoulliBladderEnable = _loaderSideB.SideData.BernoulliBladder;            data.LoaderBBernoulliExtended = _loaderSideB.SideData.BernoulliExtended;            data.LoaderBBernoulliBladderPressure = _loaderSideB.SideData.BernoulliBladderPressure;            data.LoaderBBernoulliN2Pressure = _loaderSideB.SideData.BernoulliPressure;            data.LoaderBCRSVacuum = _loaderSideB.SideData.CRSVacuum;            data.LoaderBCRSVacuumAnlg = _loaderSideB.SideData.CRSVacuumValue;            data.LoaderBWHPressure = _loaderSideB.SideData.WHBladderPressure;            data.LoaderBTranslatePressure = _loaderSideB.SideData.TransPressure;            data.LoaderWHClamped = _loaderCommon.CommonData.WaferHolderClamp;            _datas.Add(data);        }            }}
 |