using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using Aitex.Sorter.Common; using Venus_RT.Devices; 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 Venus_RT.Devices.EFEM; namespace Venus_RT.Modules.EFEM { class EfemPlaceRoutine : ModuleRoutineBase, IRoutine { private enum PlaceStep { WaitModuleReady, Placing1, Placing2, End, } private int _moveTimeout = 20 * 1000; private ModuleName _targetModule = ModuleName.System; private ModuleName _targetModule2 = ModuleName.System; int _targetSlot; int _targetSlot2; Hand _hand; Hand _hand2; EfemBase _efem; bool _bDoublePlace = false; public EfemPlaceRoutine(EfemBase efem) : base(ModuleName.EfemRobot) { _efem = efem; } public RState Start(params object[] objs) { if (!_efem.IsHomed) { LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"EFEM is not homed, please home it first"); return RState.Failed; } _bDoublePlace = false; var placeItem = (Queue)objs[0]; if (!WaferManager.Instance.CheckDuplicatedWafersBeforeMove(placeItem)) return RState.Failed; _targetModule = placeItem.Peek().DestinationModule; _targetSlot = placeItem.Peek().DestinationSlot; _hand = placeItem.Peek().RobotHand; if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand)) { LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Efem robot arm{_hand} already has no wafer, cannot do the place action"); return RState.Failed; } if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot)) { LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"The target: {_targetModule}{_targetSlot} has a wafer, cannot do the place action"); return RState.Failed; } if (placeItem.Count >= 2) { placeItem.Dequeue(); _targetModule2 = placeItem.Peek().DestinationModule; if (!ModuleHelper.IsLoadPort(_targetModule2)) { LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Wrong double place command, target is not loadport"); return RState.Failed; } _hand2 = _hand != Hand.Blade1 ? Hand.Blade1 : Hand.Blade2; if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand2)) { LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Efem robot arm{_hand2} has no wafer, cannot do the double place action"); return RState.Failed; } _targetSlot2 = placeItem.ToArray()[0].DestinationSlot; if (WaferManager.Instance.CheckHasWafer(_targetModule2, _targetSlot2)) { LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"The target: {_targetModule2} {_targetSlot2} has a wafer, cannot do the double place action"); return RState.Failed; } _bDoublePlace = true; } _moveTimeout = SC.GetValue($"EFEM.MotionTimeout") * 1000; string targetModule2 = ""; if (_targetModule2 != ModuleName.System) { targetModule2 = _targetModule2.ToString(); } return Runner.Start(Module, $"Place to {_targetModule} {targetModule2}"); } public RState Monitor() { if (_bDoublePlace) { Runner.Wait(PlaceStep.WaitModuleReady, WaitModuleReady) .Run(PlaceStep.Placing1, Place1, Place1Done, _moveTimeout + _delay_1s) .Run(PlaceStep.Placing2, Place2, Place2Done, _moveTimeout + _delay_1s) .End(PlaceStep.End, ActionDone); } else { Runner.Wait(PlaceStep.WaitModuleReady, WaitModuleReady) .Run(PlaceStep.Placing1, Place1, Place1Done, _moveTimeout + _delay_1s) .End(PlaceStep.End, ActionDone); } return Runner.Status; } public void Abort() { _efem.Halt(); } private bool WaitModuleReady() { return true; } private bool Place1() { return _efem.Place(_targetModule, _targetSlot, _hand); } private bool Place1Done() { if (_efem.Status == RState.End) { WaferManager.Instance.WaferMoved(ModuleName.EfemRobot, (int)_hand, _targetModule, _targetSlot); return true; } else if (_efem.Status != RState.Running) { WaferManager.Instance.CreateDuplicatedWafer(ModuleName.EfemRobot, (int)_hand, _targetModule, _targetSlot); Runner.Stop($"EFEM Robot place wafer to {_targetModule}.{_targetSlot + 1} failed, {_efem.Status}"); return true; } if (Runner.StepElapsedMS > _moveTimeout) { WaferManager.Instance.CreateDuplicatedWafer(ModuleName.EfemRobot, (int)_hand, _targetModule, _targetSlot); Runner.Stop($"EFEM Robot place wafer to {_targetModule}.{_targetSlot + 1} timeout, {_moveTimeout}ms"); return true; } return false; } private bool Place2() { return _efem.Place(_targetModule2, _targetSlot2, _hand2); } private bool Place2Done() { if (_efem.Status == RState.End) { WaferManager.Instance.WaferMoved(ModuleName.EfemRobot, (int)_hand2, _targetModule2, _targetSlot2); return true; } else if (_efem.Status != RState.Running) { WaferManager.Instance.CreateDuplicatedWafer(ModuleName.EfemRobot, (int)_hand2, _targetModule2, _targetSlot2); LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Efem robot place failed: {_efem.Status}"); return true; } if (Runner.StepElapsedMS > _moveTimeout) { WaferManager.Instance.CreateDuplicatedWafer(ModuleName.EfemRobot, (int)_hand2, _targetModule2, _targetSlot2); Runner.Stop($"EFEM Robot place wafer to {_targetModule}.{_targetSlot2 + 1} timeout, {_moveTimeout}ms"); LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"EFEM Robot place wafer to {_targetModule}.{_targetSlot2 + 1} timeout, {_moveTimeout}ms"); return true; } return false; } private bool ActionDone() { return true; } } }