| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.Util;
- using MECF.Framework.Common.Beckhoff.AxisProvider;
- using MECF.Framework.Common.Beckhoff.Station;
- using MECF.Framework.Common.CommonData.PowerSupplier;
- using MECF.Framework.Common.RecipeCenter;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.Common.ToolLayout;
- using MECF.Framework.Common.Utilities;
- using PunkHPX8_Core;
- using PunkHPX8_RT.Devices.AXIS;
- using PunkHPX8_RT.Devices.Facilities;
- using PunkHPX8_RT.Devices.PlatingCell;
- using PunkHPX8_RT.Devices.PowerSupplier;
- using PunkHPX8_RT.Modules.Reservoir;
- using SecsGem.Core.ItemModel;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using static Mono.Security.X509.X520;
- namespace PunkHPX8_RT.Modules.PlatingCell
- {
- public class PlatingCellRunRecipeRoutine : RoutineBase, IRoutine
- {
- private enum RunRecipeStep
- {
- LoopStart,
- InterRinse,
- CheckInterRinse,
- Entry,
- CheckEntry,
- Deposition,
- CheckDeposition,
- Reclaim,
- CheckReclaim,
- Rinse,
- CheckRinse,
- Dry,
- CheckDry,
- LoopEnd,
- End
- }
- #region 常量
- private const int ALL_DAY_MILLOSECONDS = 24 * 60 * 60 * 1000;
- /// <summary>
- /// ROTATION电机转速比例
- /// </summary>
- private const int SPEED_RATIO = 1;
- /// <summary>
- /// 电机以500rmp 运行12个小时的位置
- /// </summary>
- private const int LARGETARGETPOSITION = 12 * 60 * 60 * 500 * 6;
- #endregion
- #region 内部变量
- /// <summary>
- /// recipe
- /// </summary>
- private DepRecipe _recipe;
- /// <summary>
- /// Platingcell device
- /// </summary>
- private PlatingCellDevice _device;
- /// <summary>
- /// Rotation axis
- /// </summary>
- private JetAxisBase _rotationAxis;
- /// <summary>
- ///rotation Provider对象
- /// </summary>
- private BeckhoffProviderAxis _rotationProviderAxis;
- ///是否选中dummy load
- /// </summary>
- private bool _isDummyLoad;
- /// cycle次数
- /// </summary>
- private int _cycle;
- /// <summary>
- /// 当前完成的Cycle次数
- /// </summary>
- private int _currentCycle;
- /// <summary>
- /// platingcell entity
- /// </summary>
- private PlatingCellEntity _platingCellEntity;
- /// <summary>
- /// 对应reservoir entity
- /// </summary>
- private ReservoirEntity _reservoirEntity;
- /// <summary>
- /// vertical axis entity
- /// </summary>
- private PlatingCellVerticalEntity _verticalEntity;
- /// <summary>
- /// vertical 轴的位置数据
- /// </summary>
- private BeckhoffStationAxis _verticalBeckhoffStation;
- /// <summary>
- /// recipe中是否存在电机反转
- /// </summary>
- private bool _isRecipeContainsRevserseRotation = false;
- /// <summary>
- /// run recipe 过程中电机会停的位置(需要根据recipe计算出来)
- /// </summary>
- #region 电镀通电相关
- /// <summary>
- /// 不通电
- /// </summary>
- private bool _isZeroCurrent = false;
- /// <summary>
- /// Power step集合
- /// </summary>
- List<PowerSupplierStepPeriodData> _powerSupplierStepPeriodDatas = new List<PowerSupplierStepPeriodData>();
- /// <summary>
- /// 记录dep recipe中出现的最大电流,用于启动电源前切换挡位
- /// </summary>
- private double _maxCurrent = 0;
- /// <summary>
- /// 通电总时长
- /// </summary>
- private int _totalMicrosecond = 0;
- /// <summary>
- /// Plating启动时间
- /// </summary>
- private DateTime _platingStartTime;
- #endregion
- #region routine
- /// <summary>
- /// interbal rinse routien
- /// </summary>
- private PlatingCellInterRinseRoutine _interRinseRoutine;
- /// <summary>
- /// entry routien
- /// </summary>
- private PlatingCellEntryRoutine _entryRoutine;
- /// <summary>
- /// entry routien
- /// </summary>
- private PlatingCellDepositionRoutine _depositionRoutine;
- /// <summary>
- /// reclaim routien
- /// </summary>
- private PlatingCellReclaimRoutine _reclaimRoutine;
- /// <summary>
- /// Rinse routien
- /// </summary>
- private PlatingCellRinseRoutine _rinseRoutine;
- /// <summary>
- /// Dry routien
- /// </summary>
- private PlatingCellDryRoutine _dryRoutine;
- #endregion
- #region 属性
- #endregion
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public PlatingCellRunRecipeRoutine(string module) : base(module)
- {
- _interRinseRoutine = new PlatingCellInterRinseRoutine(module);
- _entryRoutine = new PlatingCellEntryRoutine(module);
- _depositionRoutine = new PlatingCellDepositionRoutine(module);
- _reclaimRoutine = new PlatingCellReclaimRoutine(module);
- _rinseRoutine = new PlatingCellRinseRoutine(module);
- _dryRoutine = new PlatingCellDryRoutine(module);
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- Runner.Stop("Manual Abort");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- {
-
- Runner.LoopStart(RunRecipeStep.LoopStart, "Loop Start Cycle Run Platingcell Recipe Routine", _cycle, NullFun, _delay_1ms)
- //interval rinse
- .LoopRunIf(RunRecipeStep.InterRinse, _recipe.RinseBeforeEntryEnable, () => { return _interRinseRoutine.Start(_recipe, LARGETARGETPOSITION) == RState.Running; })
- .LoopRunIfWithStopStatus(RunRecipeStep.CheckInterRinse, _recipe.RinseBeforeEntryEnable, CheckInterRinseEndStatus,
- () => CommonFunction.CheckRoutineStopState(_interRinseRoutine))
- //entry
- .LoopRun(RunRecipeStep.Entry, () => { return _entryRoutine.Start(_recipe, LARGETARGETPOSITION, _powerSupplierStepPeriodDatas) == RState.Running; })
- .LoopRunWithStopStatus(RunRecipeStep.CheckEntry, CheckEntryEndStatus,
- () => CommonFunction.CheckRoutineStopState(_entryRoutine))
- //Deposition
- .LoopRun(RunRecipeStep.Deposition, () => { return _depositionRoutine.Start(_recipe, _isZeroCurrent,_powerSupplierStepPeriodDatas) == RState.Running; })
- .LoopRunWithStopStatus(RunRecipeStep.CheckDeposition, CheckDepositionEndStatus,
- () => CommonFunction.CheckRoutineStopState(_depositionRoutine))
- //Reclaim
- .LoopRun(RunRecipeStep.Reclaim, () => { return _reclaimRoutine.Start(_recipe, _isZeroCurrent,_device.PowerSupplier) == RState.Running; })
- .LoopRunWithStopStatus(RunRecipeStep.CheckReclaim, CheckReclaimEndStatus,
- () => CommonFunction.CheckRoutineStopState(_reclaimRoutine))
- //Rinse
- .LoopRun(RunRecipeStep.Rinse, () => { return _rinseRoutine.Start(_recipe) == RState.Running; })
- .LoopRunWithStopStatus(RunRecipeStep.CheckRinse, CheckRinseEndStatus,
- () => CommonFunction.CheckRoutineStopState(_rinseRoutine))
- //Dry
- .LoopRun(RunRecipeStep.Dry, () => { return _dryRoutine.Start(_recipe) == RState.Running; })
- .LoopRunWithStopStatus(RunRecipeStep.CheckDry, CheckDryEndStatus,
- () => CommonFunction.CheckRoutineStopState(_dryRoutine))
- .LoopEnd(RunRecipeStep.LoopEnd, UpdateCycleCount, _delay_1ms)
- .End(RunRecipeStep.End, NullFun);
- return Runner.Status;
- }
- /// 统计完成的Cycle次数
- /// </summary>
- /// <returns></returns>
- private bool UpdateCycleCount()
- {
- _currentCycle += 1;
- return true;
- }
- /// <summary>
- /// 获取当前Cycle次数
- /// </summary>
- /// <returns></returns>
- public int GetCurrentCycle()
- {
- return _currentCycle;
- }
- /// <summary>
- /// 检查interval rinse是否完成
- /// </summary>
- /// <returns></returns>
- private bool CheckInterRinseEndStatus()
- {
- bool result = CommonFunction.CheckRoutineEndState(_interRinseRoutine);
- SubRoutineStep = _interRinseRoutine.CurrentStep;
- return result;
- }
- /// <summary>
- /// 检查entry是否完成
- /// </summary>
- /// <returns></returns>
- private bool CheckEntryEndStatus()
- {
- bool result = CommonFunction.CheckRoutineEndState(_entryRoutine);
- SubRoutineStep = _entryRoutine.CurrentStep;
- return result;
- }
- /// <summary>
- /// 检查Deposition是否完成
- /// </summary>
- /// <returns></returns>
- private bool CheckDepositionEndStatus()
- {
- bool result = CommonFunction.CheckRoutineEndState(_depositionRoutine);
- SubRoutineStep = _depositionRoutine.CurrentStep;
- return result;
- }
- /// <summary>
- /// 检查Reclaim是否完成
- /// </summary>
- /// <returns></returns>
- private bool CheckReclaimEndStatus()
- {
- bool result = CommonFunction.CheckRoutineEndState(_reclaimRoutine);
- SubRoutineStep = _reclaimRoutine.CurrentStep;
- return result;
- }
- /// <summary>
- /// 检查Rinse是否完成
- /// </summary>
- /// <returns></returns>
- private bool CheckRinseEndStatus()
- {
- bool result = CommonFunction.CheckRoutineEndState(_rinseRoutine);
- SubRoutineStep = _rinseRoutine.CurrentStep;
- return result;
- }
- /// <summary>
- /// 检查Dry是否完成
- /// </summary>
- /// <returns></returns>
- private bool CheckDryEndStatus()
- {
- bool result = CommonFunction.CheckRoutineEndState(_dryRoutine);
- SubRoutineStep = _dryRoutine.CurrentStep;
- return result;
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- public RState Start(params object[] objs)
- {
- _recipe = objs[0] as DepRecipe;
- if (_recipe == null)
- {
- LOG.WriteLog(eEvent.ERR_METAL, Module, "recipe is null");
- return RState.Failed;
- }
- if (objs.Length > 1)
- {
- _isDummyLoad = (bool)objs[1];
- }
- if (objs.Length > 2)
- {
- _cycle = (int)objs[2];
- }
- _device = DEVICE.GetDevice<PlatingCellDevice>(Module);
- _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
- _rotationProviderAxis = BeckhoffAxisProviderManager.Instance.GetAxisProvider($"{Module}.Rotation");
- if (_rotationProviderAxis == null)
- {
- NotifyError(eEvent.ERR_PLATINGCELL, $"{Module}.Rotation Provider is not exist", 0);
- return RState.Failed;
- }
- //获取vertical entity
- string vertical = ModuleMatcherManager.Instance.GetPlatingVerticalByCell(Module);
- _verticalEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellVerticalEntity>(vertical);
- //获取platingcell eneity
- _platingCellEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(Module);
- //获取对应reservoir eneity
- string reservoir = ReservoirItemManager.Instance.GetReservoirByPlatingCell(Module);
- _reservoirEntity = Singleton<RouteManager>.Instance.GetModule<ReservoirEntity>(reservoir);
- //获取vertical station信息对象
- _verticalBeckhoffStation = BeckhoffStationLocationManager.Instance.GetStationAxis($"{_verticalEntity.Module}", "Vertical");
- if (!CheckPreCondition())
- {
- return RState.Failed;
- }
- CalculatVerticalPosition(_recipe);
- if (!UpdatePowerStepDatas())
- {
- NotifyError(eEvent.ERR_PLATINGCELL, $"Update Power StepDatas Failed!", 0);
- return RState.Failed;
- }
- _currentCycle = 0;
- return Runner.Start(Module, "PlatingCell Run Recipe");
- }
- /// <summary>
- /// 初始化Power step步骤
- /// </summary>
- private bool UpdatePowerStepDatas()
- {
- _isZeroCurrent = false;
- _isRecipeContainsRevserseRotation = false;
- double current = 0;
- _totalMicrosecond = 0;
- _powerSupplierStepPeriodDatas.Clear();
- if (!_recipe.IsEntryTypeCold)//如果entry带上电保护,那么把上电保护的部分加到步阶电流的第一步
- {
- PowerSupplierStepPeriodData step = new PowerSupplierStepPeriodData(); //上电保护时间(提前上电时间+延迟时间)
- step.Hour = 0;
- step.Minute = (ushort)((_recipe.PlatingDelay) / 60);
- step.Second = (ushort)(_recipe.PlatingDelay % 60);
- step.Microsecond = 110; //到达entry位置提前100ms上电,提前一丢丢
- step.Voltage = _recipe.DepMaxVoltageWarning;
- step.Current = _recipe.EntryCurrent * 0.001; //recipe的entry current单位是毫安
- _powerSupplierStepPeriodDatas.Add(step);
- }
- foreach (var item in _recipe.DepSteps)
- {
- PowerSupplierStepPeriodData step = new PowerSupplierStepPeriodData();
- step.Current = item.CurrentValue;
- if(item.CurrentValue > _maxCurrent)
- {
- _maxCurrent = item.CurrentValue;
- }
- step.Hour = (ushort)(item.DurartionSeconds / 3600);
- step.Minute = (ushort)((item.DurartionSeconds - step.Hour * 3600) / 60);
- step.Second = (ushort)(item.DurartionSeconds % 60);
- step.Microsecond = 0;
- step.Voltage = _recipe.DepMaxVoltageWarning;
- _powerSupplierStepPeriodDatas.Add(step);
- current += step.Current;
- _totalMicrosecond += item.DurartionSeconds * 1000;
- }
- if (current == 0)
- {
- _isZeroCurrent = true;
- }
- if(_maxCurrent < _recipe.EntryCurrent)//最大电流要考虑entry current
- {
- _maxCurrent = _recipe.EntryCurrent;
- }
- if(_maxCurrent > 0.6) //设置电源挡位,有超过0.6A的电流则用高档,否则用中挡
- {
- return _device.PowerSupplier.SetPowerGrade("set power grade high", new object[] { (byte)2 });
- }
- else
- {
- return _device.PowerSupplier.SetPowerGrade("set power grade middle", new object[] { (byte)1 });
- }
- }
- /// <summary>
- /// 根据dep recipe计算出整个电镀过程中Rotation profile position可能去到的位置
- /// </summary>
- private void CalculatVerticalPosition(DepRecipe recipe)
- {
- foreach(var item in recipe.DepSteps)
- {
- if (item.BiDireaction)
- {
- _isRecipeContainsRevserseRotation = true;
- }
- else
- {
- continue;
- }
- }
- }
- /// <summary>
- /// 检验前置条件
- /// </summary>
- /// <returns></returns>
- private bool CheckPreCondition()
- {
- if (_recipe == null)
- {
- LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Recipe is null");
- return false;
- }
- //if (_recipe.DepSteps.Count == 0)
- //{
- // LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Recipe DepSteps count is 0");
- // return false;
- //}
- if (!CheckAxisHome())
- {
- NotifyError(eEvent.ERR_PLATINGCELL, "Check Axis home error",0);
- return false;
- }
- if (!CheckFacility())
- {
- NotifyError(eEvent.ERR_PLATINGCELL, "Check facility error", 0);
- return false;
- }
- if (!CheckModuleAndReservoir())
- {
- NotifyError(eEvent.ERR_PLATINGCELL, "Check ModuleAndReservoir error", 0);
- return false;
- }
- return true;
- }
- private bool CheckModuleAndReservoir()
- {
- if (!_platingCellEntity.IsIdle)
- {
- LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"{Module} is not initialized");
- return false;
- }
- if (!_reservoirEntity.IsIdle)
- {
- LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Releated reseroivr is not initialized");
- return false;
- }
- if (!_reservoirEntity.TemperatureReached)
- {
- LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Releated reseroivr temperature is not reached");
- return false;
- }
- if ("Manual".Equals(_reservoirEntity.PersistentValue.OperatingMode) && !WaferManager.Instance.CheckHasWafer(Module, 0))
- {
- LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, $"Run recipe in manual must has wafer!");
- return false;
- }
- return true;
- }
- /// <summary>
- /// 检查马达是否上电且home
- /// </summary>
- /// <returns></returns>
- private bool CheckAxisHome()
- {
- if (!_rotationAxis.IsSwitchOn)
- {
- LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation Axis is off");
- return false;
- }
- if (!_rotationAxis.IsHomed)
- {
- LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Rotation Axis is not home");
- return false;
- }
- if (!_verticalEntity.AxisIsHome)
- {
- LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Vertical Axis is not home");
- return false;
- }
- return true;
- }
- /// <summary>
- /// 检查facility
- /// </summary>
- /// <returns></returns>
- private bool CheckFacility()
- {
- SystemFacilities systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
- if (systemFacilities == null)
- {
- LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility is null");
- return false;
- }
- if (!systemFacilities.CDAEnable)
- {
- LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility CDA is off");
- return false;
- }
- if (!systemFacilities.N2Enable)
- {
- LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility N2 is off");
- return false;
- }
- if (!systemFacilities.DIFillEnable)
- {
- LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility DIW is off");
- return false;
- }
- if (systemFacilities.FacilitiesDataDic["CDA1Pressure"].IsError || systemFacilities.FacilitiesDataDic["CDA2Pressure"].IsError)
- {
- LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility CDA Data is in error range");
- return false;
- }
- if (systemFacilities.FacilitiesDataDic["Nitrogen1APressure"].IsError ||
- systemFacilities.FacilitiesDataDic["Nitrogen1BPressure"].IsError ||
- systemFacilities.FacilitiesDataDic["Nitrogen2APressure"].IsError ||
- systemFacilities.FacilitiesDataDic["Nitrogen2BPressure"].IsError)
- {
- LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility N2 Data is in error range");
- return false;
- }
- if (systemFacilities.FacilitiesDataDic["DiWaterPressure"].IsError)
- {
- LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Facility Diw Pressure value is in error range");
- return false;
- }
- return true;
- }
- }
- }
|