| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 | using Aitex.Core.RT.Log;using Aitex.Core.RT.Routine;using Aitex.Core.RT.SCCore;using Aitex.Core.Util;using Aitex.Sorter.Common;using MECF.Framework.Common.Equipment;using MECF.Framework.Common.Schedulers;using MECF.Framework.Common.SubstrateTrackings;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using Venus_Core;using Venus_RT.Devices;using Venus_RT.Modules.VCE;namespace Venus_RT.Modules.TM.VenusEntity{    public class SEMFSwapRoutine : ModuleRoutineBase, IRoutine    {        private enum SwapStep        {            WaitModuleReady,            //PreRotation,            SEDoorOpen,            ModulePrepare,            OpenSlitDoor,            MoveWafer,            VCEGoto,            CloseSlitDoor,            NotifyDone,        }        private readonly HongHuTM _TM;        private readonly ITransferRobot _robot;        private int _swapTimeout = 120 * 1000;        private ModuleName _targetModule;        private VceEntity _vceModule;        Queue<MoveItem> _actionList = new Queue<MoveItem>();        MoveItem _currentAction;        public SEMFSwapRoutine(HongHuTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)        {            _TM = tm;            _robot = robot;            Name = "Swap";        }        public RState Start(params object[] objs)        {            if (!_robot.IsHomed)            {                LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");                return RState.Failed;            }            _actionList.Clear();            foreach (var item in (Queue<MoveItem>)objs[0])            {                _actionList.Enqueue(new MoveItem(item.SourceModule, item.SourceSlot, item.DestinationModule, item.DestinationSlot, item.RobotHand));            }            var firtItem = _actionList.Peek();            if (ModuleHelper.IsVCE(firtItem.SourceModule))            {                //if (_TM.VCESlitDoorClosed)                //{                //    LOG.Write(eEvent.ERR_TM, Module, $"VCE is not open, cannot do it.");                //    return RState.Failed;                //}                _targetModule = firtItem.SourceModule;            }            else if (ModuleHelper.IsVCE(firtItem.DestinationModule))            {                //if (_TM.VCESlitDoorClosed)                //{                //    LOG.Write(eEvent.ERR_TM, Module, $"VCE is not open, cannot do it.");                //    return RState.Failed;                //}                _targetModule = firtItem.DestinationModule;            }            else            {                LOG.Write(eEvent.ERR_TM, Module, $"Invalid move parameter: {firtItem.SourceModule},{firtItem.SourceSlot + 1} => {firtItem.DestinationModule},{firtItem.DestinationSlot + 1} ");                return RState.Failed;            }            _vceModule = Singleton<RouteManager>.Instance.GetVCE(_targetModule);            if (_vceModule == null)            {                LOG.Write(eEvent.ERR_TM, Module, $"Invalid vce: {_targetModule}, maybe not installed");                return RState.Failed;            }            Reset();            _swapTimeout = SC.GetValue<int>($"SETM.SwapTimeout") * 1000;            return Runner.Start(Module, $"Swap with {_targetModule}");        }        public RState Monitor()        {            Runner.Wait(SwapStep.WaitModuleReady,               () => _vceModule.IsIdle,            _delay_60s)                .RunIf(SwapStep.SEDoorOpen, _targetModule == ModuleName.VCE1, VCEDoorOpen, CheckVCEDoorOpen)                .LoopStart(SwapStep.VCEGoto,                    loopName(),                         _actionList.Count,      VCEGoto,         VCEGoReady)                .LoopEnd(SwapStep.MoveWafer,                    MoveWafer,                          WaitWaferMoved)                .End(SwapStep.NotifyDone,                       NullFun,                            _delay_50ms);            return Runner.Status;        }        private bool VCEDoorOpen()        {            return _TM.TurnSlitDoor(_targetModule, true);        }        private bool CheckVCEDoorOpen()        {            return _TM.CheckSlitValveOpen(_targetModule);        }        private string loopName()        {            return "VCE Swap";        }        private bool VCEGoto()        {            _currentAction = _actionList.Peek();            if (ModuleHelper.IsVCE(_currentAction.SourceModule) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))            {                return _vceModule.CheckToPostMessage((int)VceMSG.Goto, _currentAction.SourceSlot);            }            else if (ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsVCE(_currentAction.DestinationModule))            {                return _vceModule.CheckToPostMessage((int)VceMSG.Goto, _currentAction.DestinationSlot);            }            else            {                LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.VCE1, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");                return false;            }        }        private bool VCEGoReady()        {            _currentAction = _actionList.Peek();            if (ModuleHelper.IsVCE(_currentAction.SourceModule) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))            {                return _vceModule.IsIdle && _vceModule.CurrentSlot == _currentAction.SourceSlot;            }            if (ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsVCE(_currentAction.DestinationModule))            {                return _vceModule.IsIdle && _vceModule.CurrentSlot == _currentAction.DestinationSlot;            }            return false;        }        private bool VerifyWaferExistence(MoveItem item)        {            if (WaferManager.Instance.CheckHasWafer(item.DestinationModule, item.DestinationSlot))            {                LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as desitination {_currentAction.DestinationModule},{_currentAction.DestinationSlot + 1} already has a wafer: ");                return false;            }            if (WaferManager.Instance.CheckNoWafer(_currentAction.SourceModule, _currentAction.SourceSlot))            {                LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as source {_currentAction.SourceModule}, {_currentAction.SourceSlot + 1} has no wafer");                return false;            }            return true;        }        private bool MoveWafer()        {            _currentAction = _actionList.Dequeue();            if (!VerifyWaferExistence(_currentAction))                return false;            var wafer = WaferManager.Instance.GetWafer(_currentAction.SourceModule, _currentAction.SourceSlot);            LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from {_currentAction.SourceModule} {_currentAction.SourceSlot + 1}  to {_currentAction.DestinationModule} {_currentAction.DestinationSlot + 1}");            if (ModuleHelper.IsVCE(_currentAction.SourceModule) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))            {                return _robot.Pick(_currentAction.SourceModule, _currentAction.SourceSlot, (Hand)_currentAction.DestinationSlot);            }            else if (ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsVCE(_currentAction.DestinationModule))            {                return _robot.Place(_currentAction.DestinationModule, _currentAction.DestinationSlot, (Hand)_currentAction.SourceSlot);            }            else            {                LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TMRobot, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");                return false;            }        }        private bool WaitWaferMoved()        {            if (_robot.Status == RState.Running)            {                return false;            }            else if (_robot.Status == RState.End)            {                WaferManager.Instance.WaferMoved(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);                return true;            }            else            {                Runner.Stop($"TM Robot moving wafer failed, {_robot.Status}");                return true;            }        }                public void Abort()        {            _robot.Halt();        }    }}
 |