| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 | using Aitex.Core.RT.Routine;using Aitex.Core.RT.SCCore;using Aitex.Sorter.Common;using Venus_RT.Devices;using MECF.Framework.Common.Jobs;using MECF.Framework.Common.Routine;using MECF.Framework.Common.Equipment;using MECF.Framework.Common.SubstrateTrackings;using Venus_Core;using Aitex.Core.RT.Log;using Aitex.Core.Util;using MECF.Framework.Common.Schedulers;using System.Collections.Generic;using System;using MECF.Framework.Common.DBCore;using MECF.Framework.RT.Core.Equipments;namespace Venus_RT.Modules.TM{    class MFPickRoutine : ModuleRoutineBase, IRoutine    {        private enum PickStep        {            WaitModuleReady,            ModulePrepare,            WaitPressreStable,            OpenSlitDoor,            Picking,            QueryAwc,            CloseSlitDoor,            CheckAwc,            NotifyDone,        }        private readonly JetTM _JetTM;        private readonly ITransferRobot _robot;        private int _pickingTimeout = 20 * 1000;        private ModuleName _targetModule;        private LLEntity _llModule;        int _targetSlot;        Hand _hand;        private DateTime _starttime;        private bool _queryAwc;        private int _autoVentOptInWafer = 0;        private int _autoVentOptOutWafer = 4;        private SequenceLLInOutPath _sequencePattern = SequenceLLInOutPath.DInDOut;        private bool _bAutoMode = true;        double maxPressureDifference;        int awcAlarmRange;        public MFPickRoutine(JetTM tm, ITransferRobot robot) :base(ModuleName.TMRobot)        {            _JetTM = tm;            _robot = robot;            Name = "Pick";            if (SC.GetValue<int>($"TM.QueryAWCOption") == 1 || SC.GetValue<int>($"TM.QueryAWCOption") == 3)                _queryAwc = true;            else                _queryAwc = false;        }        public RState Start(params object[] objs)        {            _starttime = DateTime.Now;            if (!_robot.IsHomed)            {                LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");                return RState.Failed;            }            var pickItem = (Queue<MoveItem>)objs[0];            if (!WaferManager.Instance.CheckDuplicatedWafersBeforeMove(pickItem))                return RState.Failed;            _targetModule = pickItem.Peek().SourceModule;            _targetSlot = pickItem.Peek().SourceSlot;            _hand = pickItem.Peek().RobotHand;            if (ModuleHelper.IsLoadLock(_targetModule) && ModuleHelper.IsInstalled(_targetModule))            {                _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);            }            else            {                LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for picking action");                return RState.Failed;            }            if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand))            {                LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as TM Robot Arm: {_hand} already has a wafer");                return RState.Failed;            }                        if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))            {                LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as {_targetModule} Slot {_targetSlot + 1} has no wafer");                return RState.Failed;            }            Reset();            _pickingTimeout = SC.GetValue<int>("TM.PickTimeout") * 1000;            _autoVentOptInWafer = SC.GetValue<int>("TM.LLAutoVentInWaferOpt");            _autoVentOptOutWafer = SC.GetValue<int>("TM.LLAutoVentOutWaferOpt");            _sequencePattern = Singleton<RouteManager>.Instance.LLInOutPath;            _bAutoMode = Singleton<RouteManager>.Instance.IsAutoMode;            awcAlarmRange = SC.GetValue<int>($"TM.EnterLLAWCAlarmLimit");            maxPressureDifference = SC.GetValue<double>("System.TMLLMaxPressureDifference");            return Runner.Start(Module, $"Pick from {_targetModule}");        }        public RState Monitor()        {            Runner.Wait(PickStep.WaitModuleReady,     () => _llModule.IsIdle,       _delay_60s)                .Run(PickStep.ModulePrepare,          ModulePrepare,                IsModulePrepareReady)                .Wait(PickStep.WaitPressreStable,     TMLLPressureIsOK,             _delay_60s)                .Run(PickStep.OpenSlitDoor,           OpenSlitDoor,                 IsSlitDoorOpen,         _delay_30s)                .Run(PickStep.Picking,                Picking,                      WaitPickDone,           _delay_30s)                .RunIf(PickStep.QueryAwc,             _queryAwc,                    QueryAwc,               WaitQueryDoneAndRecord,     _delay_30s)                .Run(PickStep.CloseSlitDoor,          CloseSlitDoor,                IsSlitDoorClosed,       _delay_30s)                .RunIf(PickStep.CheckAwc,             _queryAwc,                    CheckAwc)                .End(PickStep.NotifyDone,             NotifyLLDone,                 _delay_50ms);                     return Runner.Status;        }        private bool ModulePrepare()        {            _llModule.PostMsg(LLEntity.MSG.Prepare_TM);            return true;        }        private bool TMLLPressureIsOK()        {            if (RouteManager.IsATMMode)            {                return _JetTM.IsTMATM && _JetTM.IsModuleATM(_targetModule);            }            else            {                double llPressure = 0;                if (_targetModule == ModuleName.LLA)                {                    llPressure = _JetTM.LLAPressure;                }                else if (_targetModule == ModuleName.LLB)                {                    llPressure = _JetTM.LLBPressure;                }                if (Math.Abs((llPressure - _JetTM.ChamberPressure)) < (maxPressureDifference-2))                {                    return true;                }                else                {                    return false;                }            }                    }        private bool IsModulePrepareReady()        {            return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;        }        private bool OpenSlitDoor()        {            return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);        }        private bool CloseSlitDoor()        {            return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);        }        private bool IsSlitDoorOpen()        {            if (_targetModule == ModuleName.LLA)            {                if (_JetTM.IsLLASlitDoorOpen)                {                    //_llModule.IsDoorsAllClosed = false;                    return true;                }                return false;            }            else            {                if (_JetTM.IsLLBSlitDoorOpen)                {                    //_llModule.IsDoorsAllClosed = false;                    return true;                }                return false;            }        }        private bool IsSlitDoorClosed()        {            if (_targetModule == ModuleName.LLA)                return _JetTM.IsLLASlitDoorClosed;            else                return _JetTM.IsLLBSlitDoorClosed;        }        private bool Picking()        {            return _robot.Pick(_targetModule, _targetSlot, _hand);        }        private bool WaitPickDone()        {            if (_robot.Status == RState.Running)            {                if (Runner.StepElapsedMS > _pickingTimeout)                {                    WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);                    Runner.Stop($"TM Robot Picking {_targetModule}.{_targetSlot + 1} wafer timeout, {_pickingTimeout}");                    return true;                }                return false;            }            else if (_robot.Status == RState.End)            {                WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);                return true;            }            else            {                WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);                Runner.Stop($"TM Robot Picking failed, {_robot.Status}");                return true;            }        }        private bool QueryAwc()        {            if (!_queryAwc)                return true;            if (_robot.QueryAwc())                return true;            else                return false;        }        private bool CheckAwc()        {            if (Math.Abs(_robot.Offset_X) > awcAlarmRange)            {                Stop($"Check  AWC 失败, 当前 X AWC [{_robot.Offset_X}]um, 高于Alarm最大值: [{awcAlarmRange}]um");                return false;            }            if (Math.Abs(_robot.Offset_Y) > awcAlarmRange)            {                Stop($"Check  AWC 失败, 当前 Y AWC [{_robot.Offset_Y}]um, 高于Alarm最大值: [{awcAlarmRange}]um");                return false;            }            return true;        }        private bool WaitQueryDoneAndRecord()        {            if (!_queryAwc)                return true;            if (_robot.Status == RState.Running)            {                return false;            }            else if (_robot.Status == RState.End)            {                //已经move后的数据                string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";                int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;                //查询完毕 插入数据                OffsetDataRecorder.RecordOffsetData(                    Guid.NewGuid().ToString(),                    _targetModule, _targetSlot,                    ModuleName.TMRobot, 0,                    _origin_module, _origin_slot,                    _hand, RobotArmPan.None,                    _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,                    _starttime, DateTime.Now);                return true;            }            else            {                Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");                return true;            }        }        private bool NotifyLLDone()        {            _llModule.PostMsg(LLEntity.MSG.TM_Exchange_Ready, false);            return true;        }        public void Abort()        {            //_robot.Halt();        }    }}
 |