using Aitex.Core.RT.Device;
using Aitex.Core.RT.Log;
using Aitex.Core.RT.Routine;
using MECF.Framework.Common.Routine;
using MECF.Framework.Common.WaferHolder;
using CyberX8_Core;
using CyberX8_RT.Devices.AXIS;
using CyberX8_RT.Devices.TransPorter;
using CyberX8_RT.Modules.Loader;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CyberX8_RT.Modules.Transporter
{
public class TransporterElevatorLowRoutine : RoutineBase, IRoutine
{
private enum ElevatorLowStep
{
CheckStatus,
ElevatorLow,
ElevatorLowWait,
End
}
#region 内部变量
private JetAxisBase _elevatorAxis;
private JetAxisBase _gantryAxis;
private TransporterCommon _transporterCommon;
#endregion
///
/// 构造函数
///
///
public TransporterElevatorLowRoutine(string module) : base(module)
{
}
///
/// 中止
///
public void Abort()
{
Runner.Stop("Manual Abort");
}
///
/// 监控
///
///
public RState Monitor()
{
Runner.Run(ElevatorLowStep.CheckStatus, CheckPreCondition, NullFun,_delay_1ms)
//1.1 Elevator
.Run(ElevatorLowStep.ElevatorLow, ElevatorPosition, _delay_1ms)
.WaitWithStopCondition(ElevatorLowStep.ElevatorLowWait, CheckVerticalPositionStatus, CheckVerticalPositionRunStop)
.End(ElevatorLowStep.End,NullFun,100);
return Runner.Status;
}
///
/// 检验前置条件
///
///
private bool CheckPreCondition()
{
if (!_elevatorAxis.IsSwitchOn)
{
LOG.WriteLog(eEvent.ERR_TRANSPORTER, Module, $"{Module} elevator axis is not switch on ");
return false;
}
if (!_elevatorAxis.IsHomed)
{
LOG.WriteLog(eEvent.ERR_TRANSPORTER, Module, $"{Module} elevator axis is not homed ");
return false;
}
return true;
}
///
/// Elevator Position
///
///
private bool ElevatorPosition()
{
return _elevatorAxis.PositionStation("LOW");
}
///
/// 检验Vertical移动状态
///
///
private bool CheckVerticalPositionStatus()
{
return _elevatorAxis.Status == RState.End;
}
///
/// 检验Vertical是否还在运动
///
///
private bool CheckVerticalPositionRunStop()
{
return _elevatorAxis.Status == RState.Failed;
}
///
/// 启动
///
///
///
public RState Start(params object[] objs)
{
_elevatorAxis = DEVICE.GetDevice($"{Module}.Elevator");
_gantryAxis = DEVICE.GetDevice($"{Module}.Gantry");
_transporterCommon = DEVICE.GetDevice($"{Module}.Common");
if (!CheckStartPreConfition())
{
return RState.Failed;
}
return Runner.Start(Module, "ElevatorLow");
}
///
/// 启动校验条件
///
///
private bool CheckStartPreConfition()
{
if (WaferHolderManager.Instance.HasWaferHolder(Module))
{
LOG.WriteLog(eEvent.ERR_TRANSPORTER, Module, $"{Module} already has wafer Shuttle");
return false;
}
return true;
}
}
}