| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537 | 
							- using Aitex.Core.RT.Device;
 
- using Aitex.Core.RT.Log;
 
- using Aitex.Core.RT.Routine;
 
- using Aitex.Core.RT.SCCore;
 
- using Aitex.Core.Util;
 
- using CyberX8_Core;
 
- using CyberX8_RT.Devices.AXIS;
 
- using CyberX8_RT.Devices.Facilities;
 
- using CyberX8_RT.Devices.SRD;
 
- using MECF.Framework.Common.Beckhoff.AxisProvider;
 
- using MECF.Framework.Common.RecipeCenter;
 
- using MECF.Framework.Common.Routine;
 
- using MECF.Framework.Common.Utilities;
 
- using System;
 
- namespace CyberX8_RT.Modules.SRD
 
- {
 
-     public class SRDRunRecipeRoutine : RoutineBase, IRoutine
 
-     {
 
-         private enum SRDRunRecipeStep
 
-         {
 
-             RunRecipe_CloseDoor,
 
-             RunRecipe_CheckOtherSRD,
 
-             RunRecipe_CheckWaterPressure,
 
-             RunRecipe_WaterOn,
 
-             RunRecipe_CheckWaterFlow,
 
-             RunRecipe_StartRotation,
 
-             RunRecipe_MonitorWaterFlow,
 
-             RunRecipe_WashingFinished,
 
-             RunRecipe_ChangeDrySpeed,
 
-             RunRecipe_Drying,
 
-             RunRecipe_StopRotation,
 
-             RunRecipe_CheckRotationStopped,
 
-             RunRecipe_CheckRotationHomed,
 
-             End
 
-         }
 
-         #region 常量 
 
-         /// <summary>
 
-         /// 旋转增加时长
 
-         /// </summary>
 
-         private const int ROTATION_PLUS_TIME = 10;
 
-         /// <summary>
 
-         /// ROTATION电机转速比例
 
-         /// </summary>
 
-         private const int SPEED_RATIO = 1;
 
-         #endregion
 
-         #region 内部变量
 
-         /// <summary>
 
-         /// Rotation Axis
 
-         /// </summary>
 
-         private JetAxisBase _rotationAxis;
 
-         /// <summary>
 
-         /// SRD Common
 
-         /// </summary>
 
-         private SrdCommonDevice _srdCommon;
 
-         /// <summary>
 
-         /// Total SRD
 
-         /// </summary>
 
-         private TotalSRDDevice _totalSRDDevice;
 
-         /// <summary>
 
-         /// 另外SRD实例 
 
-         /// </summary>
 
-         private SRDEntity _otherSrdEntity;
 
-         /// <summary>
 
-         /// Loader Common
 
-         /// </summary>
 
-         private SystemFacilities _systemFacilities;
 
-         /// <summary>
 
-         /// 是否正在用水
 
-         /// </summary>
 
-         private bool _isUsingWater;
 
-         /// <summary>
 
-         /// Recipe
 
-         /// </summary>
 
-         private SrdRecipe _srdRecipe;
 
-         /// <summary>
 
-         /// SRD rotation Provider对象
 
-         /// </summary>
 
-         private BeckhoffProviderAxis _rotationProviderAxis;
 
-         /// <summary>
 
-         /// enterTime
 
-         /// </summary>
 
-         private int _enterTime;
 
-         /// <summary>
 
-         /// 转换增加的时间
 
-         /// </summary>
 
-         private int _rotationPlusSecond = ROTATION_PLUS_TIME;
 
-         /// <summary>
 
-         /// Dry速度
 
-         /// </summary>
 
-         private int _drySpeed;
 
-         #endregion
 
-         #region 属性
 
-         /// <summary>
 
-         /// 是否正在用水
 
-         /// </summary>
 
-         public bool IsUsingWater { get { return _isUsingWater; } }
 
-         #endregion
 
-         /// <summary>
 
-         /// 构造函数
 
-         /// </summary>
 
-         /// <param name="module"></param>
 
-         public SRDRunRecipeRoutine(string module) : base(module)
 
-         {
 
-         }
 
-         /// <summary>
 
-         /// 中止
 
-         /// </summary>
 
-         public void Abort()
 
-         {
 
-             Runner.Stop("SRD Run Recipe Abort");
 
-         }
 
-         /// <summary>
 
-         /// 监控
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public RState Monitor()
 
-         {
 
-             Runner.Run(SRDRunRecipeStep.RunRecipe_CloseDoor, CloseDoor, CheckDoorClosedEndStatus, CheckDoorClosedStopStatus)
 
-                 .Wait(SRDRunRecipeStep.RunRecipe_CheckOtherSRD, CheckOtherSRD, _delay_60s)
 
-                 .Run(SRDRunRecipeStep.RunRecipe_CheckWaterPressure, CheckWaterPressure, _delay_1ms)
 
-                 .Run(SRDRunRecipeStep.RunRecipe_WaterOn, WaterOn, _delay_1ms)
 
-                 .WaitWithStopCondition(SRDRunRecipeStep.RunRecipe_CheckWaterFlow, CheckFlowEndStatus, CheckFlowStopStatus)
 
-                 .Run(SRDRunRecipeStep.RunRecipe_StartRotation, StartRotation, _delay_1ms)
 
-                 .WaitWithStopCondition(SRDRunRecipeStep.RunRecipe_MonitorWaterFlow, MonitorWaterFlowEndStatus, MonitorWaterFlowStopStatus)
 
-                 .Run(SRDRunRecipeStep.RunRecipe_WashingFinished, WashingFinished, _delay_1ms)
 
-                 .Run(SRDRunRecipeStep.RunRecipe_ChangeDrySpeed, ChangeSpeed, _delay_1ms)
 
-                 .Delay(SRDRunRecipeStep.RunRecipe_Drying, _srdRecipe.DryTime * 1000)
 
-                 .Run(SRDRunRecipeStep.RunRecipe_StopRotation, StopRotation, _delay_1ms)
 
-                 .Wait(SRDRunRecipeStep.RunRecipe_CheckRotationStopped, CheckRotationStopEndStatus, _delay_5s)
 
-                 .WaitWithStopCondition(SRDRunRecipeStep.RunRecipe_CheckRotationHomed, CheckRotationHomeEndStatus, CheckRotationHomedStopStatus)
 
-                 .End(SRDRunRecipeStep.End, NullFun, _delay_1ms);
 
-             return Runner.Status;
 
-         }
 
-         /// <summary>
 
-         /// 启动
 
-         /// </summary>
 
-         /// <param name="objs"></param>
 
-         /// <returns></returns>
 
-         public RState Start(params object[] objs)
 
-         {
 
-             _srdRecipe = (SrdRecipe)objs[0];
 
-             if (_srdRecipe == null)
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, "srd recipe is null", 0);
 
-                 return RState.Failed;
 
-             }
 
-             _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");           
 
-             _srdCommon = DEVICE.GetDevice<SrdCommonDevice>($"{Module}.Common");
 
-             _totalSRDDevice = DEVICE.GetDevice<TotalSRDDevice>("SRD");
 
-             _systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
 
-             string otherSRD = Module == "SRD1" ? "SRD2" : "SRD1";
 
-             _otherSrdEntity = Singleton<RouteManager>.Instance.GetModule<SRDEntity>(otherSRD);
 
-             SRDEntity srdEntity = Singleton<RouteManager>.Instance.GetModule<SRDEntity>(Module);
 
-             if (srdEntity.IsManual && !srdEntity.IsLoaded)
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, $"{Module} is not Loaded, can't run recipe", 0);
 
-                 return RState.Failed;
 
-             }
 
-             _rotationProviderAxis = BeckhoffAxisProviderManager.Instance.GetAxisProvider($"{Module}.Rotation");
 
-             if (_rotationProviderAxis == null)
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, $"{Module}.Rotation Provider is not exist", 0);
 
-                 return RState.Failed;
 
-             }
 
-             if (!CheckPreCondition())
 
-             {
 
-                 return RState.Failed;
 
-             }
 
-             return Runner.Start(Module, "SRD Run Recipe Start");
 
-         }
 
-         /// <summary>
 
-         /// Check Pre Condition
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool CheckPreCondition()
 
-         {
 
-             //Check Rotation Home
 
-             //if (!_rotationAxis.IsHomed)
 
-             //{
 
-             //    NotifyError(eEvent.ERR_SRD, "Rotation is not homed", 0);
 
-             //    return false;
 
-             //}
 
-             //Check LiftUp
 
-             if (_srdCommon.CommonData.LiftUp)
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, "LiftUp is on", 0);
 
-                 return false;
 
-             }
 
-             //Check LiftUp Status
 
-             if (_srdCommon.CommonData.LiftUpStatus)
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, "LiftUp sensor is on", 0);
 
-                 return false;
 
-             }
 
-             //Check Wafer Present
 
-             if (!_srdCommon.CommonData.WaferPresent)
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, "WaferPresent sensor is off", 0);
 
-                 return false;
 
-             }
 
-             //Check LoaderDI
 
-             if (!_systemFacilities.LoaderDiEnable)
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, "Load DI Is Disable", 0);
 
-                 return false;
 
-             }
 
-             //Check Vacuum
 
-             int vacuumOnLimit = SC.GetValue<int>("SRD.ChuckVacuumOnLimit");
 
-             if (!_srdCommon.CommonData.ChuckVacuum)
 
-             {
 
-                 if (_srdCommon.CommonData.VacuumValue >= vacuumOnLimit)
 
-                 {
 
-                     LOG.WriteLog(eEvent.ERR_SRD, Module, $"VacuumValue:{_srdCommon.CommonData.VacuumValue}, VacuumOn Limit:{vacuumOnLimit}");
 
-                     return false;
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 LOG.WriteLog(eEvent.ERR_SRD, Module, $"Chuck Vacuum is off");
 
-                 return false;
 
-             }
 
-             //Check Flippers
 
-             if (_srdCommon.CommonData.FlippersIn150 || _srdCommon.CommonData.FlippersIn200) //|| _srdCommon.CommonData.FlippersIn100
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, "FlippersIn is on", 0);
 
-                 return false;
 
-             }
 
-             if (!_srdCommon.CommonData.Flipper1Out150Status || !_srdCommon.CommonData.Flipper2Out150Status || !_srdCommon.CommonData.Flipper3Out150Status
 
-                 || !_srdCommon.CommonData.Flipper1Out200Status || !_srdCommon.CommonData.Flipper2Out200Status || !_srdCommon.CommonData.Flipper3Out200Status)
 
-             //|| !_srdCommon.CommonData.Flipper1Out100Status || !_srdCommon.CommonData.Flipper2Out100Status || !_srdCommon.CommonData.Flipper3Out100Status
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, "Flippers are at In position", 0);
 
-                 return false;
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// Close Door
 
-         /// </summary>
 
-         /// <param name="param"></param>
 
-         /// <returns></returns>
 
-         private bool CloseDoor()
 
-         {
 
-             if (_srdCommon.CommonData.DoorOpened)
 
-             {
 
-                 bool result = _srdCommon.DoorCloseAction("", null);
 
-                 if (!result)
 
-                 {
 
-                     NotifyError(eEvent.ERR_SRD, "Door Close Action is failed", 0);
 
-                     return result;
 
-                 }
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 检验DoorClosed结束状态
 
-         /// </summary>
 
-         /// <param name="param"></param>
 
-         /// <returns></returns>
 
-         private bool CheckDoorClosedEndStatus()
 
-         {
 
-             return _srdCommon.Status == RState.End && _srdCommon.CommonData.DoorClosed;
 
-         }
 
-         /// <summary>
 
-         /// 检验DoorClosed结束状态
 
-         /// </summary>
 
-         /// <param name="param"></param>
 
-         /// <returns></returns>
 
-         private bool CheckDoorClosedStopStatus()
 
-         {
 
-             if (_srdCommon.Status == RState.Failed || _srdCommon.Status == RState.Timeout)
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, "Check Door Closed is failed", 0);
 
-                 return true;
 
-             }
 
-             return false;
 
-         }
 
-         /// <summary>
 
-         /// 检验另外一个SRD是否在用水
 
-         /// </summary>
 
-         /// <param name="param"></param>
 
-         /// <returns></returns>
 
-         private bool CheckOtherSRD()
 
-         {
 
-             return (_otherSrdEntity == null || !_otherSrdEntity.IsUsingWater);
 
-         }
 
-         /// <summary>
 
-         /// CheckWaterPressure
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool CheckWaterPressure()
 
-         {
 
-             if (_srdCommon.CommonData.WaterPressure < _srdRecipe.MinWaterPressure)
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, $"Water Pressure {_srdCommon.CommonData.WaterPressure} is less than recipe's MinWaterPressure {_srdRecipe.MinWaterPressure}", 0);
 
-                 return false;
 
-             }
 
-             else if(_srdCommon.CommonData.WaterPressure > _srdRecipe.MaxWaterPressure)
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, $"Water Pressure {_srdCommon.CommonData.WaterPressure} is over recipe's MaxWaterPressure {_srdRecipe.MaxWaterPressure}", 0);
 
-                 return false;
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// Water On
 
-         /// </summary>
 
-         /// <param name="param"></param>
 
-         /// <returns></returns>
 
-         private bool WaterOn()
 
-         {
 
-             if (_srdRecipe.RinseTime > 0)
 
-             {
 
-                 if (!_srdCommon.CommonData.WaterOn)
 
-                 {
 
-                     bool result = _srdCommon.WaterOn();
 
-                     if (result)
 
-                     {
 
-                         LOG.WriteLog(eEvent.INFO_SRD, Module, "Water On");
 
-                         _isUsingWater = true;
 
-                         _enterTime = Environment.TickCount;
 
-                     }
 
-                     else
 
-                     {
 
-                         NotifyError(eEvent.ERR_SRD, "Water On is failed", 0);
 
-                     }
 
-                     return result;
 
-                 }
 
-                 return true;
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// Check Flow End
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool CheckFlowEndStatus()
 
-         {
 
-             if (_srdRecipe.FlowCheckDelay == 0)
 
-             {
 
-                 return true;
 
-             }
 
-             int ticks = Environment.TickCount - _enterTime;
 
-             if (ticks >= _srdRecipe.FlowCheckDelay * 1000)
 
-             {
 
-                 if (WaterFlowCheck()) return true;
 
-             }
 
-             return false;
 
-         }
 
-         /// <summary>
 
-         /// Check Flow Stop
 
-         /// </summary>
 
-         /// <param name="param"></param>
 
-         /// <returns></returns>
 
-         private bool CheckFlowStopStatus()
 
-         {
 
-             int ticks = Environment.TickCount - _enterTime;
 
-             if (ticks >= _srdRecipe.FlowCheckDelay * 1000)
 
-             {
 
-                 if (!WaterFlowCheck()) return true;
 
-             }
 
-             return false;
 
-         }
 
-         /// <summary>
 
-         /// WaterFlow检测
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool WaterFlowCheck()
 
-         {
 
-             if (_srdCommon.CommonData.WaterFlow > _srdRecipe.MaxSRDWaterFlow)
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, $"{Module} Water Flow:{_srdCommon.CommonData.WaterFlow} is over recipe's MaxSRDWaterFlow:{_srdRecipe.MaxSRDWaterFlow}", 0);
 
-                 return false;
 
-             }
 
-             else if (_srdCommon.CommonData.WaterFlow < _srdRecipe.MinSRDWaterFlow)
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, $"{Module} Water Flow:{_srdCommon.CommonData.WaterFlow} is less than recipe's MinSRDWaterFlow:{_srdRecipe.MinSRDWaterFlow}", 0);
 
-                 return false;
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 开始旋转
 
-         /// </summary>
 
-         /// <param name="param"></param>
 
-         /// <returns></returns>
 
-         private bool StartRotation()
 
-         {
 
-             if (!_srdCommon.RotationInterLock())
 
-             {
 
-                 return false;
 
-             }
 
-             double _scale = _rotationProviderAxis.ScaleFactor;
 
-             //rinse 目标位置 
 
-             double rinsePosition = _srdRecipe.RinseTime * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_srdRecipe.RinseSpeed);
 
-             //dry目标位置
 
-             double dryPosition = BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_srdRecipe.DrySpeed) * _srdRecipe.DryTime;
 
-             //为了让 rotation 不停止,增加了旋转时间(覆盖Arm运动时间)
 
-             double plusPosition = BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_srdRecipe.DrySpeed) * _rotationPlusSecond;
 
-             int targetPosition = (int)Math.Round((rinsePosition + dryPosition + plusPosition) * _scale, 0);
 
-             int rotationSpeed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_srdRecipe.RinseSpeed), 0);
 
-             _drySpeed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_srdRecipe.DrySpeed * SPEED_RATIO), 0);
 
-             bool result = _rotationAxis.ProfilePosition(targetPosition, rotationSpeed * SPEED_RATIO, 0, 0);
 
-             if (!result)
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, "Start Rotation is failed", 0);
 
-                 return false;
 
-             }
 
-             LOG.WriteLog(eEvent.INFO_SRD, Module, "Start Rotation");
 
-             //Rinse开始时间
 
-             _enterTime = Environment.TickCount;
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// WaterFlow End Monitor
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool MonitorWaterFlowEndStatus()
 
-         {
 
-             int ticks = Environment.TickCount - _enterTime;
 
-             if (ticks >= _srdRecipe.RinseTime * 1000)
 
-             {
 
-                 return true;
 
-             }
 
-             return false;
 
-         }
 
-         /// <summary>
 
-         /// WaterFlow Stop Monitor
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool MonitorWaterFlowStopStatus()
 
-         {
 
-             int ticks = Environment.TickCount - _enterTime;
 
-             if (ticks < _srdRecipe.RinseTime * 1000)
 
-             {
 
-                 if (!WaterFlowCheck()) return true;
 
-             }
 
-             return false;
 
-         }
 
-         /// <summary>
 
-         /// Washing Finished
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool WashingFinished()
 
-         {
 
-             if (_srdCommon.CommonData.WaterOn)
 
-             {
 
-                 if (!_srdCommon.WaterOff())
 
-                 {
 
-                     NotifyError(eEvent.ERR_SRD, "Water Off is failed", 0);
 
-                     return false;
 
-                 }
 
-             }
 
-             _isUsingWater = false;
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// change Dry speed
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool ChangeSpeed()
 
-         {
 
-             //调整速度为 drySpeed
 
-             bool result = _rotationAxis.WriteSpeed(_drySpeed);
 
-             if (!result)
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, "Change Speed to Dry Speed is failed", 0);
 
-                 return false;
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 停止旋转
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool StopRotation()
 
-         {
 
-             bool result = _rotationAxis.StopPositionOperation();
 
-             LOG.WriteLog(eEvent.INFO_SRD, Module, "Stop Rotation is done");
 
-             return result;
 
-         }
 
-         /// <summary>
 
-         /// 检验Rotation是否停止
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool CheckRotationStopEndStatus()
 
-         {
 
-             if (!_rotationAxis.IsRun && _rotationAxis.Status == RState.End)
 
-             {
 
-                 bool homeResult = _rotationAxis.Home(false);
 
-                 if (!homeResult)
 
-                 {
 
-                     NotifyError(eEvent.ERR_SRD, $"{Module}.Rotation home action is failed", 0);
 
-                     return false;
 
-                 }
 
-                 return true;
 
-             }
 
-             return false;
 
-         }
 
-         /// <summary>
 
-         /// 检验RotationHome是否完成
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool CheckRotationHomeEndStatus()
 
-         {
 
-             if (_rotationAxis.IsHomed && _rotationAxis.Status == RState.End)
 
-             {                
 
-                 return true;
 
-             }
 
-             return false;
 
-         }
 
-         /// <summary>
 
-         /// 检验Rotation Home 停止状态
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool CheckRotationHomedStopStatus()
 
-         {
 
-             if(_rotationAxis.Status == RState.Failed || _rotationAxis.Status == RState.Timeout)
 
-             {
 
-                 NotifyError(eEvent.ERR_SRD, $"{Module}.Rotation home is failed", 0);
 
-                 return true;
 
-             }
 
-             return false;
 
-         }
 
-         
 
-     }
 
-     
 
- }
 
 
  |