Sfoglia il codice sorgente

TMCycle not finished.

sangwq 1 anno fa
parent
commit
66557b65bb

+ 1 - 0
Venus/Venus_Core/RtState.cs

@@ -37,6 +37,7 @@ namespace Venus_Core
         //Maintenance,
         //WaferMapping,
         //Cycling,
+        TMCycle,
 
         ReturnWafer,
     }

+ 2 - 0
Venus/Venus_RT/Config/System.sccfg

@@ -168,6 +168,7 @@
 		<config default="180" name="LeakCheckPumpTime" description="Leak Check Pump Time" max="7200" min="0" paramter="" tag="" unit="second" type="Integer" />
 		<config default="300" name="LeakCheckWaitTime" description="Leak Check Wait Time" max="7200" min="0" paramter="" tag="" unit="second" type="Integer" />
 		<config default="30" name="LeakRate" description="Leak Rate" max="756000" min="0" paramter="" tag="" unit="mTorrPerMin" type="Double" />
+		<config default="4" name="SlotNumber" nameView="Slot number"  description="槽位个数" max="60" min="1" paramter="" tag="" unit="" type="Integer" />
 	</configs>
 
 	<!--LLB-->
@@ -183,6 +184,7 @@
 		<config default="180" name="LeakCheckPumpTime" description="Leak Check Pump Time" max="7200" min="0" paramter="" tag="" unit="second" type="Integer" />
 		<config default="300" name="LeakCheckWaitTime" description="Leak Check Wait Time" max="7200" min="0" paramter="" tag="" unit="second" type="Integer" />
 		<config default="30" name="LeakRate" description="Leak Rate" max="756000" min="0" paramter="" tag="" unit="mTorrPerMin" type="Double" />
+		<config default="4" name="SlotNumber" nameView="Slot number"  description="槽位个数" max="60" min="1" paramter="" tag="" unit="" type="Integer" />
 	</configs>
 
 	<!--PMA-->

+ 79 - 14
Venus/Venus_RT/Modules/RouteManager.cs

@@ -56,6 +56,7 @@ namespace Venus_RT.Modules
 
             Map,
             ReturnAllWafer,
+            TMCycle,
         }
 
         public PMEntity PMA { get; private set; }
@@ -73,6 +74,8 @@ namespace Venus_RT.Modules
 
         public string Name { get; set; }
 
+        private TMCycle _TMCycle;
+
         public RouteManager()
         {
             Name = "System";
@@ -123,16 +126,6 @@ namespace Venus_RT.Modules
 
             return true;
         }
-
-        protected override bool Init()
-        {
-            PMA?.Initialize();
-            PMB?.Initialize();
-            TM?.Initialize();
-            LLA?.Initialize();
-            LLB?.Initialize();
-            return true;
-        }
         void SubscribeOperation()
         {
             OP.Subscribe("CreateWafer", InvokeCreateWafer);
@@ -192,9 +185,9 @@ namespace Venus_RT.Modules
 
         public PMEntity GetPM(ModuleName mod)
         {
-            if(ModuleHelper.IsInstalled(mod))
+            if (ModuleHelper.IsInstalled(mod))
             {
-                switch(mod)
+                switch (mod)
                 {
                     case ModuleName.PMA:
                         return PMA;
@@ -212,9 +205,9 @@ namespace Venus_RT.Modules
 
         public LLEntity GetLL(ModuleName mod)
         {
-            if(ModuleHelper.IsInstalled(mod))
+            if (ModuleHelper.IsInstalled(mod))
             {
-                switch(mod)
+                switch (mod)
                 {
                     case ModuleName.LLA:
                         return LLA;
@@ -225,5 +218,77 @@ namespace Venus_RT.Modules
 
             return null;
         }
+    
+
+        protected override bool Init()
+        {
+            PMA?.Initialize();
+            PMB?.Initialize();
+            TM?.Initialize();
+            LLA?.Initialize();
+            LLB?.Initialize();
+
+            _TMCycle = new TMCycle();
+            return true;
+        }
+
+        private void BuildTransitionTable()
+        {
+            //Init sequence
+            Transition(RtState.Init, MSG.HOME, FsmStartHome, RtState.Initializing);
+            Transition(RtState.Idle, MSG.HOME, FsmStartHome, RtState.Initializing);
+            Transition(RtState.Error, MSG.HOME, FsmStartHome, RtState.Initializing);
+
+            ////  EnterExitTransition<RtState, FSM_MSG>(RtState.Initializing, fStartInit, FSM_MSG.NONE, null);
+
+            Transition(RtState.Initializing, FSM_MSG.TIMER, FsmMonitorHome, RtState.Idle);
+            Transition(RtState.Initializing, MSG.ERROR, FsmError, RtState.Error);
+            Transition(RtState.Initializing, MSG.ABORT, FsmAbort, RtState.Init);
+
+
+            // TM  Cycle
+            Transition(RtState.Idle,        MSG.TMCycle,        FsmStartTMCycle,        RtState.TMCycle);
+            Transition(RtState.TMCycle,     FSM_MSG.TIMER,      FsmMonitorTMCycle,      RtState.Idle);
+            Transition(RtState.TMCycle,     MSG.ABORT,          FsmAbort,               RtState.Idle);
+
+        }
+
+        private bool FsmStartHome(object[] objs)
+        {
+            return true;
+        }
+
+        private bool FsmMonitorHome(object[] objs)
+        {
+            return true;
+        }
+
+        private bool FsmError(object[] objs)
+        {
+            return true;
+        }
+
+        private bool FsmAbort(object[] objs)
+        {
+            return true;
+        }
+
+        private bool FsmStartTMCycle(object[] objs)
+        {
+            return _TMCycle.Start() == RState.Running;
+        }
+
+        private bool FsmMonitorTMCycle(object[] objs)
+        {
+            RState ret = _TMCycle.Monitor();
+            if (ret == RState.Failed || ret == RState.Timeout)
+            {
+                PostMsg(MSG.ERROR);
+                return false;
+            }
+
+            return ret == RState.End;
+        }
+
     }
 }

+ 1 - 1
Venus/Venus_RT/Modules/Schedulers/SchedulerTMRobot.cs

@@ -87,7 +87,7 @@ namespace Venus_RT.Modules.Schedulers
             return ret;
         }
 
-        private bool PostMoveItems(MoveItem[] items)
+        public bool PostMoveItems(MoveItem[] items)
         {
             void PackSwapCmds(MoveItem[] swapItems, TMEntity.MSG swapType, int swapIndex)
             {

+ 186 - 10
Venus/Venus_RT/Modules/TMCycle.cs

@@ -13,6 +13,7 @@ using System.Linq;
 using Venus_RT.Modules.Schedulers;
 using Venus_RT.Scheduler;
 using System;
+using MECF.Framework.Common.Schedulers;
 
 namespace Venus_RT.Modules
 {
@@ -32,9 +33,16 @@ namespace Venus_RT.Modules
         int cycleCount = 1;
         ModuleName _sourceModule = ModuleName.LLA;
         ModuleName _destinationModule = ModuleName.LLB;
+        int _sourceSlotNumber = 4;
+        int _destinationSlotNumber = 4;
         SchedulerTMRobot _TMRobot = new SchedulerTMRobot();
+        private readonly int INVALID_SLOT = -1;
 
         Dictionary<ModuleName, SchedulerModule> dictSchedulers = new Dictionary<ModuleName, SchedulerModule>();
+
+        Queue<MoveItem> _ReturnWafers = new Queue<MoveItem>();
+        Queue<MoveItem> _runningItems = new Queue<MoveItem>();
+        Queue<MoveItem> _CycleWafers = new Queue<MoveItem>();
         public TMCycle() : base(ModuleName.System)
         {
             Name = "TM Cycle";
@@ -85,41 +93,209 @@ namespace Venus_RT.Modules
         public RState Monitor()
         {
             Runner.Run((int)TMCycleStep.Start,                      NullFun)
-                .LoopStart((int)TMCycleStep.ReturnBack, "Cycle",    cycleCount,     ReturnBack,     IsReturnDone)
-                .LoopEnd((int)TMCycleStep.Cycling,      Cycling,    IsCycleDone)
+                .LoopStart((int)TMCycleStep.ReturnBack, "Cycle",    cycleCount, StartReturn, ReturnBack)
+                .LoopEnd((int)TMCycleStep.Cycling,      StartCycle, Cycling)
                 .End((int)TMCycleStep.End,              NullFun,    _delay_50ms);
 
             return Runner.Status;
         }
 
-        private bool ReturnBack()
+        private bool StartReturn()
+        {
+            _destinationModule = tmCycleRoutine.Last();
+            _destinationSlotNumber = SC.GetValue<int>($"{_destinationModule}.SlotNumber");
+            _sourceModule = tmCycleRoutine.First();
+            _sourceSlotNumber = SC.GetValue<int>($"{_sourceModule}.SlotNumber");
+            _ReturnWafers.Clear();
+            for(int i = 0; i < _destinationSlotNumber; i++)
+            {
+                if(WaferManager.Instance.CheckHasWafer(_destinationModule, i))
+                {
+                    _ReturnWafers.Enqueue(new MoveItem(_destinationModule, i, _sourceModule, INVALID_SLOT, Hand.None));
+                }
+            }
+
+            return true;
+        }
+
+
+        List<int> GetReadyInSlot(ModuleName module, int slotCount)
+        {
+            List<int> slots = new List<int>();
+            for (int i = 0; i < slotCount; i++)
+            {
+                if (WaferManager.Instance.CheckNoWafer(module, i))
+                    slots.Add(i);
+
+                if (slots.Count >= 2)
+                    return slots;
+            }
+
+            return slots;
+        }
+
+        List<ModuleName> GetReadyOutPMs()
+        {
+            List<ModuleName> outpm = new List<ModuleName>();
+            foreach(var module in tmCycleRoutine)
+            {
+                if(ModuleHelper.IsPm(module))
+                {
+                    if(IsModuleAvailable(module) && WaferManager.Instance.CheckHasWafer(module, 0))
+                    {
+                        outpm.Add(module);
+                        if (outpm.Count >= 2)
+                            break;
+                    }
+                }
+            }
+
+            return outpm;
+        }
+
+        List<ModuleName> GetReadyInPMs()
         {
-            if(_TMRobot.IsAvailable)
+            List<ModuleName> inpm = new List<ModuleName>();
+            foreach (var module in tmCycleRoutine)
             {
-                for(int i = 0; i < tmCycleRoutine.Count - 1; i++)
+                if (ModuleHelper.IsPm(module))
                 {
-                    if(IsModuleAvailable(tmCycleRoutine[i]) && IsModuleAvailable(tmCycleRoutine[i+1]))
+                    if (IsModuleAvailable(module) && WaferManager.Instance.CheckNoWafer(module, 0))
                     {
+                        inpm.Add(module);
+                        if (inpm.Count >= 2)
+                            break;
+                    }
+                }
+            }
 
+            return inpm;
+        }
+
+        private bool ReturnBack()
+        {
+            if (IsModuleAvailable(_sourceModule) && IsModuleAvailable(_destinationModule))
+            {
+                if (_ReturnWafers.Count == 0)
+                    return IsModuleAvailable(ModuleName.TM);
+
+
+                var InSlots = GetReadyInSlot(_sourceModule, _sourceSlotNumber);
+                foreach (var slot in InSlots)
+                {
+                    if(_ReturnWafers.Count > 0)
+                    {
+                        var move = _ReturnWafers.Dequeue();
+                        move.DestinationSlot = slot;
+                        _runningItems.Enqueue(move);
                     }
                 }
             }
 
-            return true;
+
+            if (_TMRobot.IsAvailable && _runningItems.Count > 0)
+            {
+                if(_TMRobot.PostMoveItems(_runningItems.ToArray()))
+                    _runningItems.Clear();
+            }
+
+            return false;
         }
 
-        private bool IsReturnDone()
+        private bool ModuleHasWafer(ModuleName mod, int nSlots)
         {
+            for(int i= 0; i< nSlots; i++)
+            {
+                if (WaferManager.Instance.CheckHasWafer(mod, i))
+                    return true;
+            }
+
+            return false;
+        }
+
+        private bool PMsHasWafers()
+        {
+            foreach (var module in tmCycleRoutine)
+            {
+                if (ModuleHelper.IsPm(module))
+                {
+                    if (WaferManager.Instance.CheckHasWafer(module, 0))
+                        return true;
+
+                }
+            }
+
+            return false;
+
+        }
+
+        private bool IsPMsAvailabe()
+        {
+            foreach (var module in tmCycleRoutine)
+            {
+                if (ModuleHelper.IsPm(module))
+                {
+                    if (!IsModuleAvailable(module))
+                        return false;
+
+                }
+            }
+
             return true;
         }
 
         private bool Cycling()
         {
-            return true;
+            if(IsPMsAvailabe() && IsModuleAvailable(_destinationModule) && IsModuleAvailable(_sourceModule) && _TMRobot.IsAvailable)
+            {
+                if (!PMsHasWafers() && IsModuleAvailable(ModuleName.TM) && _CycleWafers.Count == 0)
+                    return true;
+
+                if(PMsHasWafers())
+                {
+                    var pmSlots = GetReadyOutPMs();
+                    var inSlots = GetReadyInSlot(_destinationModule, _destinationSlotNumber);
+                    for(int i = 0; i < Math.Min(pmSlots.Count, inSlots.Count); i++)
+                    {
+                        _runningItems.Enqueue(new MoveItem(pmSlots[i], 0, _destinationModule, inSlots[i], Hand.Both));
+                    }
+                }
+                else
+                {
+                    var InPMs = GetReadyInPMs();
+                    if(_CycleWafers.Count > 0 && InPMs.Count >= 1)
+                    {
+                        var item = _CycleWafers.Dequeue();
+                        _runningItems.Enqueue(new MoveItem(item.SourceModule, item.SourceSlot, InPMs[0], 0, Hand.Both));
+                    }
+
+                    if(_CycleWafers.Count > 0 && InPMs.Count >= 2)
+                    {
+                        var item = _CycleWafers.Dequeue();
+                        _runningItems.Enqueue(new MoveItem(item.SourceModule, item.SourceSlot, InPMs[1], 0, Hand.Both));
+                    }
+
+                }
+
+                if (_runningItems.Count > 0)
+                {
+                    if (_TMRobot.PostMoveItems(_runningItems.ToArray()))
+                        _runningItems.Clear();
+                }
+            }
+
+            return false;
         }
 
-        private bool IsCycleDone()
+        private bool StartCycle()
         {
+            _CycleWafers.Clear();
+            for(int i = 0; i< _sourceSlotNumber; i++)
+            {
+                if (WaferManager.Instance.CheckHasWafer(_sourceModule, i))
+                    _CycleWafers.Enqueue(new MoveItem(_sourceModule, i, _destinationModule, INVALID_SLOT, Hand.None));
+            }
+
             return true;
         }