using Aitex.Core.RT.Device;
using Aitex.Core.RT.Log;
using Aitex.Core.RT.Routine;
using Aitex.Core.Util;
using MECF.Framework.Common.Equipment;
using MECF.Framework.Common.Routine;
using MECF.Framework.Common.Utilities;
using CyberX8_Core;
using CyberX8_RT.Devices.AXIS;
using CyberX8_RT.Devices.AXIS.CANOpen;
using CyberX8_RT.Modules.PUF;
using CyberX8_RT.Modules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MECF.Framework.Common.CommonData.Loader;
using CyberX8_RT.Modules.Transporter;
namespace CyberX8_RT.Devices.Loader
{
public class LoaderUnloadRoutine : RoutineBase, IRoutine
{
private enum UnloadStep
{
CheckPreCondition,
WSClampOn,
WSSideClampOn,
WSSideClampOnCheck,
TranslateBladderOff,
TranslateBladderOffCheck,
CRSGotoSetUp,
CRSGotoSetUpWait,
BernoulliBladderOn,
BernoulliBladderOnCheck,
BernoulliN2On,
TransBladderOn,
TransBladderOnCheck,
TranslateHighOff,
TranslateHighOffCheck,
CRSVacuumOn,
CRSVacuumOnCheck,
WSBladderOn,
WSBladderOnCheck,
ConditionCRSVacuumLevel,
ConditionCRSVacuumLevelCheck,
CRSGotoUnlock,
CRSGotoUnlockWait,
ReTranslateBladderOff,
ReTranslateBladderOffCheck,
ReTranslateHighOff,
ReTranslateHighOffCheck,
DoorUnlock,
DoorUnlockCheck,
ShuttleGotoOpen,
ShuttleGotoOpenWait,
VacuumLevel,
VacuumLevelCheck,
TiltGotoHori,
TiltGotoHoriCheck,
BernoulliBladderOff,
BernoulliBladderOffCheck,
ReBernoulliBladderOn,
ReBernoulliBladderOnCheck,
BernoulliN2Off,
End
}
#region 内部变量
private string _side = "";
private LoaderCommonWaferHolderSideClampRoutine _waferHolderSideClampRoutine;
private LoaderSideTransBladderRoutine _transBladderRoutine;
private JetAxisBase _crsAxis;
private LoaderSideBernoulliBladderRoutine _bernoulliBladderRoutine;
private LoaderSideTransHighRoutine _transHightRoutine;
private LoaderSideVacuumRoutine _vacuumRoutine;
private LoaderSideVacuumLevelCheckRoutine _vacuumLevelCheckRoutine;
private LoaderSideWhBladderRoutine _whBladderRoutine;
private LoaderSideUnloadVacuumLevelCheckRoutine _unloadVacuumLevelCheckRoutine;
private LoaderSideDoorLockRoutine _doorLockRoutine;
private JetAxisBase _shuttleAxis;
private JetAxisBase _tiltAxis;
private JetAxisBase _rotationAxis;
private LoaderSideDevice _sideDevice;
private LoaderCommonDevice _loaderCommonDevice;
#endregion
///
/// 构造函数
///
///
public LoaderUnloadRoutine(string module,string side) : base(module)
{
_side = side;
}
///
/// 中止
///
public void Abort()
{
Runner.Stop("Manual Abort");
}
///
/// 监控
///
///
public RState Monitor()
{
Runner.Run(UnloadStep.CheckPreCondition,CheckPreCondition,_delay_1ms)
//1.0 WS Clamp On
.Run(UnloadStep.WSClampOn, WaferHolderClampOn, _delay_1ms)
//1.1 WSSideClampOn
.Run(UnloadStep.WSSideClampOn, () => { return _waferHolderSideClampRoutine.Start(true) == RState.Running; }, _delay_1ms)
.WaitWithStopCondition(UnloadStep.WSSideClampOnCheck, () => { return CommonFunction.CheckRoutineEndState(_waferHolderSideClampRoutine); },
()=>CheckRoutineStopStatus(_waferHolderSideClampRoutine,"Wafer Shuttle Side Clamp on failed"))
//1.2 TranslateBladderOff
.Run(UnloadStep.TranslateBladderOff, () => { return _transBladderRoutine.Start(false) == RState.Running; }, _delay_1ms)
.WaitWithStopCondition(UnloadStep.TranslateBladderOffCheck, () => { return CommonFunction.CheckRoutineEndState(_transBladderRoutine); },
()=>CheckRoutineStopStatus(_transBladderRoutine,"TransBladder off failed"))
//1.3 CRS Goto Setup
.Run(UnloadStep.CRSGotoSetUp, () => { return AxisPosition(_crsAxis,"Setup"); }, NullFun, _delay_1ms)
.WaitWithStopCondition(UnloadStep.CRSGotoSetUpWait, () => { return _crsAxis.Status == RState.End; },
()=>CheckAxisMotionStopStatus(_crsAxis))
//1.4 BernoulliBladderOn
.Run(UnloadStep.BernoulliBladderOn, () => { return _bernoulliBladderRoutine.Start(true) == RState.Running; }, _delay_1ms)
.WaitWithStopCondition(UnloadStep.BernoulliBladderOnCheck, () => { return CommonFunction.CheckRoutineEndState(_bernoulliBladderRoutine); },
() => CheckRoutineStopStatus(_bernoulliBladderRoutine, "BernoulliBladder On failed"))
//1.5 BernoulliN2 On
.Run(UnloadStep.BernoulliN2On, BernoulliN2On, _delay_1ms)
//1.6 Trans Bladder On
.Run(UnloadStep.TransBladderOn, () => { return _transBladderRoutine.Start(true) == RState.Running; }, _delay_1ms)
.WaitWithStopCondition(UnloadStep.TransBladderOnCheck, () => { return CommonFunction.CheckRoutineEndState(_transBladderRoutine); },
() => CheckRoutineStopStatus(_transBladderRoutine,"TransBladder On failed"))
//1.6 Trans High Off
.Run(UnloadStep.TranslateHighOff, () => { return _transHightRoutine.Start(false) == RState.Running; }, _delay_1ms)
.WaitWithStopCondition(UnloadStep.TranslateHighOffCheck, () => { return CommonFunction.CheckRoutineEndState(_transHightRoutine); },
() => CheckRoutineStopStatus(_transHightRoutine,"TransHigh off failed"))
//1.7 CRS Vacuum On
.Run(UnloadStep.CRSVacuumOn, () => { return _vacuumRoutine.Start(true) == RState.Running; }, _delay_1ms)
.WaitWithStopCondition(UnloadStep.CRSVacuumOnCheck, () => { return CommonFunction.CheckRoutineEndState(_vacuumRoutine); },
() => CheckRoutineStopStatus(_vacuumRoutine,"Vaccum On failed"))
//1.8 WS Bladder On
.Run(UnloadStep.WSBladderOn, () => { return _whBladderRoutine.Start(true) == RState.Running; }, _delay_1ms)
.WaitWithStopCondition(UnloadStep.WSBladderOnCheck, () => { return CommonFunction.CheckRoutineEndState(_whBladderRoutine); },
() => CheckRoutineStopStatus(_whBladderRoutine,"WSBladder On failed"))
//1.9 condition vacuum level check
.Run(UnloadStep.ConditionCRSVacuumLevel, () => { return _unloadVacuumLevelCheckRoutine.Start(true) == RState.Running; }, _delay_1ms)
.WaitWithStopCondition(UnloadStep.ConditionCRSVacuumLevelCheck, () => { return CommonFunction.CheckRoutineEndState(_unloadVacuumLevelCheckRoutine); },
() => CheckRoutineStopStatus(_unloadVacuumLevelCheckRoutine," Vacuum Level Check failed"))
//2.0 CRS Goto Unlock
.Run(UnloadStep.CRSGotoUnlock, () => { return AxisPosition(_crsAxis,"Unlock"); }, NullFun, _delay_1ms)
.WaitWithStopCondition(UnloadStep.CRSGotoUnlockWait, () => { return _crsAxis.Status == RState.End; },
() => CheckAxisMotionStopStatus(_crsAxis))
//2.1 Trans Bladder Off
.Run(UnloadStep.ReTranslateBladderOff, () => { return _transBladderRoutine.Start(false) == RState.Running; }, _delay_1ms)
.WaitWithStopCondition(UnloadStep.ReTranslateBladderOffCheck, () => { return CommonFunction.CheckRoutineEndState(_transBladderRoutine); },
() => CheckRoutineStopStatus(_transBladderRoutine,"ReTransBladder Off failed"))
//2.2 Trans High Off
.Run(UnloadStep.ReTranslateHighOff, () => { return _transHightRoutine.Start(false) == RState.Running; }, _delay_1ms)
.WaitWithStopCondition(UnloadStep.ReTranslateHighOffCheck, () => { return CommonFunction.CheckRoutineEndState(_transHightRoutine); },
() => CheckRoutineStopStatus(_transHightRoutine,"ReTransHigh Off failed"))
//2.3 Dor Lock On
.Run(UnloadStep.DoorUnlock, () => { return _doorLockRoutine.Start(false) == RState.Running; }, _delay_1ms)
.WaitWithStopCondition(UnloadStep.DoorUnlockCheck, () => { return CommonFunction.CheckRoutineEndState(_doorLockRoutine); },
() => CheckRoutineStopStatus(_doorLockRoutine,"door unlock failed"))
//2.4 Shuttle Goto OPEN
.Run(UnloadStep.ShuttleGotoOpen, () => { return AxisPosition(_shuttleAxis,"OPEN"); }, NullFun, _delay_1ms)
.WaitWithStopCondition(UnloadStep.ShuttleGotoOpenWait, () => { return _shuttleAxis.Status == RState.End; },
() => CheckAxisMotionStopStatus(_shuttleAxis))
//2.5 CRS Vacuum Check
.Run(UnloadStep.VacuumLevel, () => { return _vacuumLevelCheckRoutine.Start(true) == RState.Running; }, _delay_1ms)
.WaitWithStopCondition(UnloadStep.VacuumLevelCheck, () => { return CommonFunction.CheckRoutineEndState(_vacuumLevelCheckRoutine); },
() => CheckRoutineStopStatus(_vacuumLevelCheckRoutine,"Vacuum Level check failed"))
//2.6 Tilt Goto HORI
.Run(UnloadStep.TiltGotoHori, () => { return AxisPosition(_tiltAxis,"HORI"); }, NullFun, _delay_1ms)
.WaitWithStopCondition(UnloadStep.TiltGotoHoriCheck, () => { return _tiltAxis.Status == RState.End; },
() => CheckAxisMotionStopStatus(_tiltAxis))
//2.7 BernoulliBladderOff
.Run(UnloadStep.BernoulliBladderOff, () => { return _bernoulliBladderRoutine.Start(false) == RState.Running; }, _delay_1ms)
.WaitWithStopCondition(UnloadStep.BernoulliBladderOffCheck, () => { return CommonFunction.CheckRoutineEndState(_bernoulliBladderRoutine); },
() => CheckRoutineStopStatus(_bernoulliBladderRoutine,"BernoulliBladder Off failed"))
//2.8 Re BernoulliBladderOn
.Run(UnloadStep.ReBernoulliBladderOn, () => { return _bernoulliBladderRoutine.Start(true) == RState.Running; }, _delay_1ms)
.WaitWithStopCondition(UnloadStep.ReBernoulliBladderOnCheck, () => { return CommonFunction.CheckRoutineEndState(_bernoulliBladderRoutine); },
() => CheckRoutineStopStatus(_bernoulliBladderRoutine, "BernoulliBladder On failed"))
//2.9 Bernoulli N2 Off
.Run(UnloadStep.BernoulliN2Off, BernoulliN2Off, _delay_1ms)
.End(UnloadStep.End, NullFun, 10);
return Runner.Status;
}
///
/// Wafer Holder Clamp On
///
///
private bool WaferHolderClampOn()
{
bool result = _loaderCommonDevice.WaferHolderClampOnAction();
if(!result)
{
NotifyError(eEvent.ERR_LOADER, "Wafer Shuttle Clamp on faied", 0);
}
return result;
}
///
/// 检验TranslateBladderOff异常状态
///
///
private bool CheckRoutineStopStatus(IRoutine routine,string error)
{
bool result = CommonFunction.CheckRoutineStopState(routine);
if (result)
{
NotifyError(eEvent.ERR_LOADER, $"{error}", 0);
}
return result;
}
///
/// Axis goto position
///
///
///
///
private bool AxisPosition(JetAxisBase axis,string station)
{
bool result = axis.PositionStation(station);
if (!result)
{
NotifyError(eEvent.ERR_LOADER, $"{axis.Module} goto {station} failed", 0);
}
return result;
}
///
/// 检验电机运动异常状态
///
///
///
private bool CheckAxisMotionStopStatus(JetAxisBase axis)
{
bool result = axis.Status == RState.Failed || axis.Status == RState.Timeout;
if (result)
{
NotifyError(eEvent.ERR_LOADER, $"{axis.Module} motion failed", 0);
}
return result;
}
///
/// BerolliN2 On
///
///
private bool BernoulliN2On()
{
bool result= _sideDevice.BernoulliN2OnAction("", null);
if (!result)
{
NotifyError(eEvent.ERR_LOADER, $"BernoulliN2 On failed", 0);
}
return result;
}
///
/// BernoulliN2Off
///
///
private bool BernoulliN2Off()
{
bool result = _sideDevice.BernoulliN2OffAction("", null);
if (!result)
{
NotifyError(eEvent.ERR_LOADER, "BernoulliN2 Off failed", 0);
}
return result;
}
///
/// 启动
///
///
///
///
public RState Start(params object[] objs)
{
_shuttleAxis = GetShuttleAxis();
_crsAxis = GetCrsAxis();
_tiltAxis = GetTiltAxis();
_loaderCommonDevice = DEVICE.GetDevice($"Loader1.Common");
_rotationAxis = DEVICE.GetDevice($"{ModuleName.Loader1}.Rotation");
_sideDevice = DEVICE.GetDevice($"{Module}.{_side}");
_waferHolderSideClampRoutine = new LoaderCommonWaferHolderSideClampRoutine($"{Module}");
_vacuumRoutine = new LoaderSideVacuumRoutine($"{Module}.{_side}");
_vacuumLevelCheckRoutine = new LoaderSideVacuumLevelCheckRoutine($"{Module}.{_side}");
_unloadVacuumLevelCheckRoutine = new LoaderSideUnloadVacuumLevelCheckRoutine($"{Module}.{_side}");
_doorLockRoutine = new LoaderSideDoorLockRoutine($"{Module}.{_side}");
_whBladderRoutine = new LoaderSideWhBladderRoutine($"{Module}.{_side}");
_transHightRoutine = new LoaderSideTransHighRoutine($"{Module}.{_side}");
_bernoulliBladderRoutine = new LoaderSideBernoulliBladderRoutine($"{Module}.{_side}");
_transBladderRoutine = new LoaderSideTransBladderRoutine($"{Module}.{_side}");
Runner.Start(Module, $"Unload {_side}");
return RState.Running;
}
///
/// 获取Shuttle轴对象
///
///
private JetAxisBase GetShuttleAxis()
{
switch (_side)
{
case "SideA":
return DEVICE.GetDevice($"{Module}.ShuttleA");
default:
return DEVICE.GetDevice($"{Module}.ShuttleB");
}
}
///
/// 获取CRS轴对象
///
///
private JetAxisBase GetCrsAxis()
{
switch (_side)
{
case "SideA":
return DEVICE.GetDevice($"{Module}.LSA");
default:
return DEVICE.GetDevice($"{Module}.LSB");
}
}
///
/// 获取Tilt轴对象
///
///
private JetAxisBase GetTiltAxis()
{
switch (_side)
{
case "SideA":
return DEVICE.GetDevice($"{Module}.TiltA");
default:
return DEVICE.GetDevice($"{Module}.TiltB");
}
}
///
/// 检验前置条件
///
///
private bool CheckPreCondition()
{
if (!CheckHomeCondition())
{
return false;
}
if (!CheckUnloadAxisCondition())
{
return false;
}
if (!UnloadStatusCheck())
{
return false;
}
if (!UnloadCRSVacuumCheck())
{
return false;
}
return true;
}
///
/// 检验Home条件
///
///
private bool CheckHomeCondition()
{
//检验PUF、Loader Transporter,Robot均Homed
if (ModuleHelper.IsInstalled(ModuleName.PUF1))
{
PUFEntity puf1Entity = Singleton.Instance.GetModule(ModuleName.PUF1.ToString());
if (!puf1Entity.IsHomed)
{
NotifyError(eEvent.ERR_LOADER, "PUF1 is not homed",-1);
return false;
}
}
if (ModuleHelper.IsInstalled(ModuleName.PUF2))
{
PUFEntity puf2Entity = Singleton.Instance.GetModule(ModuleName.PUF2.ToString());
if (!puf2Entity.IsHomed)
{
NotifyError(eEvent.ERR_LOADER,"PUF2 is not homed",-1);
return false;
}
}
if (ModuleHelper.IsInstalled(ModuleName.Transporter2))
{
TransporterEntity loaderTransportEntity = Singleton.Instance.GetModule(ModuleName.Transporter2.ToString());
if (!loaderTransportEntity.IsHomed)
{
NotifyError(eEvent.ERR_LOADER, "Loader Transporter is not homed",-1);
return false;
}
}
return true;
}
///
/// 检验Axis我们的
///
///
///
private bool CheckUnloadAxisCondition()
{
if (!_rotationAxis.IsHomed)
{
NotifyError(eEvent.ERR_LOADER, $"rotation is not homed",-1);
return false;
}
if (!_shuttleAxis.IsHomed)
{
NotifyError(eEvent.ERR_LOADER, $"{_shuttleAxis.Name} is not homed", -1);
return false;
}
if (!_tiltAxis.IsHomed)
{
NotifyError(eEvent.ERR_LOADER, $"{_tiltAxis.Name} is not homed",-1);
return false;
}
if (!_crsAxis.IsHomed)
{
NotifyError(eEvent.ERR_LOADER, $"{_crsAxis.Name} is not homed", -1);
return false;
}
double rotationPosition = _rotationAxis.MotionData.MotorPosition;
if (!_rotationAxis.CheckPositionIsInStation(rotationPosition, "LOAD") &&
!_rotationAxis.CheckPositionIsInStation(rotationPosition, "SERVICEB"))
{
NotifyError(eEvent.ERR_LOADER, $"rotation {rotationPosition} not in LOAD and SERVICEB",-1);
return false;
}
double shuttlePosition=_shuttleAxis.MotionData.MotorPosition;
if (!_shuttleAxis.CheckPositionIsInStation(shuttlePosition, "CLOSED"))
{
NotifyError(eEvent.ERR_LOADER, $"shuttle {shuttlePosition} not in CLOSE", -1);
return false;
}
double tiltPosition = _tiltAxis.MotionData.MotorPosition;
if (!_tiltAxis.CheckPositionIsInStation(tiltPosition, "VERT"))
{
NotifyError(eEvent.ERR_LOADER, $"tilt {tiltPosition} not in VERT", -1);
return false;
}
double crsPosition = _crsAxis.MotionData.MotorPosition;
if (_crsAxis.CheckPositionIsEmpty(crsPosition))
{
NotifyError(eEvent.ERR_LOADER, $"crs {crsPosition} not at station", -1);
return false;
}
return true;
}
///
/// Unload Status Check
///
///
///
private bool UnloadStatusCheck()
{
//Facility:CDA,N2,Vaccum均Enable且在正常范围
//Side WaferPresent
LoaderSideData sideData = _sideDevice.SideData;
//if (sideData.WaferPresent)
//{
// NotifyError(eEvent.ERR_LOADER, "side wafer is not present");
// return false;
//}
if (sideData.DoorLowerUnlocked || sideData.DoorUpperUnlocked)
{
NotifyError(eEvent.ERR_LOADER, "Door Lock is off", -1);
return false;
}
return true;
}
///
/// CRS Vacuum Check
///
///
///
private bool UnloadCRSVacuumCheck()
{
//CRS Vacuum检验
LoaderSideData sideData = _sideDevice.SideData;
if (sideData.CRSVacuum)
{
NotifyError(eEvent.ERR_LOADER, "LS Vacuum is on",-1);
return false;
}
//WS Bladder
if (sideData.WHBladder)
{
NotifyError(eEvent.ERR_LOADER, "WS Bladder is on", -1);
return false;
}
//Translate Bladder/High Pres,且Sensor处于Retracted
if (sideData.TransBladder)
{
NotifyError(eEvent.ERR_LOADER, "TransBladder is on",-1);
return false;
}
if (sideData.TransHigh)
{
NotifyError(eEvent.ERR_LOADER, "Trans High is on", -1);
return false;
}
//Bernoulli N2
if (sideData.BernoulliN2)
{
NotifyError(eEvent.ERR_LOADER, "Bernoulli N2 is on",-1);
return false;
}
//Wafer Shuttle Present
LoaderCommonData commonData = _loaderCommonDevice.CommonData;
if (!commonData.WaferHolderPresent)
{
NotifyError(eEvent.ERR_LOADER, "Wafer Shuttle is absent", -1);
return false;
}
//Drip Tray Fluid
if (commonData.DripTrayFluid)
{
NotifyError(eEvent.ERR_LOADER, "Drip Tray Fluid is on",-1);
return false;
}
return true;
}
}
}