123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- using Aitex.Core.RT.Fsm;
- using Aitex.Core.RT.Log;
- using Aitex.Core.Util;
- using MECF.Framework.Common.CommonData;
- using MECF.Framework.Common.Equipment;
- using CyberX8_Core;
- using CyberX8_RT.Modules;
- using CyberX8_RT.Modules.Loader;
- using CyberX8_RT.Modules.PUF;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using MECF.Framework.Common.SubstrateTrackings;
- using CyberX8_RT.Modules.Metal;
- using CyberX8_RT.Devices.AXIS;
- using Aitex.Core.RT.Device;
- using MECF.Framework.Common.WaferHolder;
- using Aitex.Core.Common;
- using CyberX8_RT.Dispatch;
- namespace CyberX8_RT.Schedulers.Loader
- {
- public class SchedulerLoader : SchedulerModule
- {
- private enum SchedulerStep
- {
- None,
- WaitUnload,
- WaitLoad,
- LoadingFirst,
- ReadyForPuf,
- LoadingSecond
- }
- #region 内部变量
- private LoaderEntity _loaderEntity;
- private PUFEntity _puf1Entity;
- private SchedulerStep _currentStep;
- private int _currentWaferIndex = 1;
- #endregion
- #region 属性
- public override bool IsIdle
- {
- get { return _state == RState.End; }
- }
- public override bool IsError
- {
- get { return _state == RState.Failed || _state == RState.Timeout; }
- }
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public SchedulerLoader(ModuleName module) : base(module.ToString())
- {
- _loaderEntity = Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(module.ToString());
- _puf1Entity = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(ModuleName.PUF1.ToString());
- }
- /// <summary>
- /// 执行
- /// </summary>
- /// <param name="parameter"></param>
- /// <returns></returns>
- public override bool RunProcess(object recipe, object parameter, List<SchedulerSyncModuleMessage> syncModuleMessages)
- {
- _state = RState.Running;
- _currentStep = SchedulerStep.WaitUnload;
- _currentWaferIndex = 1;
- return true;
- }
- /// <summary>
- /// 监控执行
- /// </summary>
- /// <returns></returns>
- public override bool MonitorProcess(SchedulerSequence schedulerSequence, bool hasMatchWafer)
- {
- if (_currentStep == SchedulerStep.WaitUnload)
- {
- if (_loaderEntity.State == (int)LOADERSTATE.WaitForUnload && WaferHolderManager.Instance.HasWaferHolder("Loader"))
- {
- JetAxisBase _loadTransporterGantryAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Transporter2}.Gantry");
- if (_loadTransporterGantryAxis != null && _loadTransporterGantryAxis.JudgeCompareTargetStation("Loader", "Right"))
- {
- WaferInfo preLoaderWaferInfo = WaferHolderTaskManager.Instance.GetPreLoaderHasWafer();
- //触发loaderEntity UnloadAll
- if (preLoaderWaferInfo != null && !string.IsNullOrEmpty(preLoaderWaferInfo.LoaderSide))
- {
- _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, ModuleName.Loader1.ToString(),
- (int)LoaderMSG.UnloadSide, preLoaderWaferInfo.LoaderSide);
- }
- }
- }
- else if(_loaderEntity.State==(int)LOADERSTATE.Unloading)
- {
- _currentStep = SchedulerStep.WaitLoad;
- }
- else if (_loaderEntity.State == (int)LOADERSTATE.WaitForLoad)
- {
- _currentStep = SchedulerStep.WaitLoad;
- }
- return true;
- }
- LoaderParameter loaderParameter =(LoaderParameter)schedulerSequence.Parameters;
- bool loadComplete = loaderParameter.WaferCount == _currentWaferIndex;
- bool needFlip = loaderParameter.NeedWaitFlip;
- if (_currentStep == SchedulerStep.WaitLoad)
- {
- if (_loaderEntity.State != (int)LOADERSTATE.WaitForLoad)
- {
- return false;
- }
- if (_puf1Entity.State == (int)PUFSTATE.AferSwapParkStation)
- {
- bool result = ExecuteLoadSide(loadComplete, loaderParameter.LoadCompleteToTransporterSide);
- if (result)
- {
- _currentStep = SchedulerStep.LoadingFirst;
- }
- }
- }
- else if (_currentStep == SchedulerStep.LoadingFirst)
- {
- if (_loaderEntity.IsIdle)
- {
- if (loaderParameter.WaferCount == 1)
- {
- if (needFlip)
- {
- bool loaderResult= _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, Module.ToString(),
- (int)LoaderMSG.WaitFlip);
- if (loaderResult)
- {
- _state = RState.End;
- _currentStep = SchedulerStep.None;
- }
- }
- else
- {
- _state = RState.End;
- _currentStep = SchedulerStep.None;
- }
- }
- else
- {
- EnterReadyForPuf();
- }
- }
- else if (_loaderEntity.State == (int)LOADERSTATE.WaitForUnload)
- {
- ExecuteForSecondUnload();
- }
- else if (_loaderEntity.State == (int)LOADERSTATE.Unloading)
- {
- _currentStep = SchedulerStep.ReadyForPuf;
- _currentWaferIndex = 2;
- }
- }
- else if (_currentStep == SchedulerStep.ReadyForPuf)
- {
- if (_loaderEntity.State == (int)LOADERSTATE.WaitForLoad)
- {
- if (_puf1Entity.State == (int)PUFSTATE.AferSwapParkStation)
- {
- bool result = ExecuteLoadSide(true, loaderParameter.LoadCompleteToTransporterSide);
- if (result)
- {
- _currentStep = SchedulerStep.LoadingSecond;
- }
- }
- }
- }
- else if (_currentStep == SchedulerStep.LoadingSecond)
- {
- if (_loaderEntity.IsIdle)
- {
- _state = RState.End;
- _currentStep = SchedulerStep.None;
- }
- }
- return true;
- }
- /// <summary>
- /// 执行Loader Load动作
- /// </summary>
- /// <param name="loadComplete"></param>
- /// <param name="completeSide"></param>
- /// <returns></returns>
- private bool ExecuteLoadSide(bool loadComplete,string completeSide)
- {
- if (_puf1Entity.State == (int)PUFSTATE.AferSwapParkStation || (_puf1Entity.IsIdle && _puf1Entity.IsBackToParkStation))
- {
- JetAxisBase tiltAAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.TiltA");
- JetAxisBase tiltBAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.TiltB");
- double tiltAPosition = tiltAAxis.MotionData.MotorPosition;
- double tiltBPosition = tiltBAxis.MotionData.MotorPosition;
- bool tiltAHori = tiltAAxis.CheckPositionIsInStation(tiltAPosition, "HORI");
- bool tiltBHori = tiltBAxis.CheckPositionIsInStation(tiltBPosition, "HORI");
- string side = tiltAHori ? "SideA" : (tiltBHori ? "SideB" : "");
- if (string.IsNullOrEmpty(side))
- {
- return false;
- }
- return _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, Module.ToString(),
- (int)LoaderMSG.LoadSide, side, loadComplete,completeSide);
- }
- return false;
- }
- /// <summary>
- /// 第二次进入WaitForUnload
- /// </summary>
- /// <returns></returns>
- private void EnterReadyForPuf()
- {
- _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, ModuleName.Loader1.ToString(),
- (int)LoaderMSG.ReadyForPuf);
- }
- /// <summary>
- /// 执行第二次unload
- /// </summary>
- /// <returns></returns>
- private void ExecuteForSecondUnload()
- {
- if (_loaderEntity.State == (int)LOADERSTATE.WaitForUnload)
- {
- if (!WaferHolderManager.Instance.HasWaferHolder("Loader"))
- {
- return;
- }
- JetAxisBase _loadTransporterGantryAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Transporter2}.Gantry");
- if (_loadTransporterGantryAxis != null && _loadTransporterGantryAxis.JudgeCompareTargetStation("Loader", "Right"))
- {
- WaferInfo preLoaderWaferInfo = WaferHolderTaskManager.Instance.GetPreLoaderHasWafer();
- //触发loaderEntity UnloadAll
- if (preLoaderWaferInfo != null && !string.IsNullOrEmpty(preLoaderWaferInfo.LoaderSide))
- {
- bool result = _loaderEntity.CheckToPostMessage<LOADERSTATE, LoaderMSG>(eEvent.WARN_LOADER, ModuleName.Loader1.ToString(),
- (int)LoaderMSG.UnloadSide, preLoaderWaferInfo.LoaderSide);
- }
- }
- }
- }
- /// <summary>
- /// 检验前置条件
- /// </summary>
- /// <param name="sequenceIndex"></param>
- /// <param name="parameter"></param>
- /// <returns></returns>
- public override bool CheckPrecondition(List<SchedulerSequence> schedulerSequences, int sequenceIndex, object parameter, string materialId,ref string reason)
- {
- if (_state == RState.Running)
- {
- reason = "scheduler module is already running";
- return false;
- }
- if (_loaderEntity.IsIdle)
- {
- reason = "loader is idle";
- return false;
- }
- if (_loaderEntity.WaferHolderInfo == null)
- {
- reason = "loader has no wafer shuttle";
- return false;
- }
- if (_loaderEntity.WaferHolderInfo.Id != materialId)
- {
- reason = $"{_loaderEntity.Module} wafer shuttle {_loaderEntity.WaferHolderInfo.Id} is not matched with {materialId}";
- return false;
- }
- return true;
- }
- }
- }
|