123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- using System;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using Aitex.Sorter.Common;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.Schedulers;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
- using MECF.Framework.RT.EquipmentLibrary.LogicUnits;
- using MECF.Framework.RT.ModuleLibrary.PMModules;
- using MECF.Framework.RT.ModuleLibrary.SystemModules;
- namespace FutureEfemLib.Efems
- {
- class EfemRetractRoutine : ModuleRoutine, IRoutine
- {
- enum RoutineStep
- {
- CheckBeforeRetract,
- Retract,
- WaitCloseSlitValveInterlock,
- CloseSlitValve,
- PostTransfer
- }
- private ModuleName _source;
- private int _sourceSlot;
- private Hand _blade;
- private int _timeout;
- // private TMSlitValveRoutine _closeSlitValveRoutine = new TMSlitValveRoutine();
- private EfemModule _robotModule;
- //private RobotPostionEnum postiontype;
- private ITransferTarget _target;
- public EfemRetractRoutine(EfemModule robotModule)
- {
- Module = "EfemRobot";
- Name = "Retract";
- _robotModule = robotModule;
- }
- private string _type;
- public void Init(ModuleName source, int sourceSlot, string blade,string type)
- {
- _source = source;
- _sourceSlot = sourceSlot;
- _blade = (Hand)Enum.Parse(typeof(Hand), blade);
- _type = type;
- //_closeSlitValveRoutine.Init(source.ToString(), false);
- }
- public void Init(ModuleName source, int sourceSlot, int blade)
- {
- Init(source, sourceSlot, blade);
- }
- public Result Start(params object[] objs)
- {
- Reset();
- _timeout = SC.GetValue<int>("EFEM.EfemRobot.PickTimeout");
- //if (ModuleHelper.IsLoadLock(_source))
- //{
- // LoadLock ll = DEVICE.GetDevice<LoadLock>(_source.ToString());
- // if (!ll.CheckEnableTransfer(EnumTransferType.Extend))
- // {
- // EV.PostWarningLog(Module, $"can not retract, {_source} not ready for transfer");
- // return Result.FAIL;
- // }
- //}
- if (ModuleHelper.IsPm(_source))
- {
- if (_type=="Pick")
- {
- //postiontype = RobotPostionEnum.PickRetracted;// _blade == Hand.Blade1 ?RobotPostionEnum.PickRetractLow: RobotPostionEnum.PickRetractUp;
- }
- else
- {
- //postiontype = RobotPostionEnum.PlaceRetract;//_blade == Hand.Blade1 ? RobotPostionEnum.PlaceRetractLow : RobotPostionEnum.PlaceRetractUp;
- }
- // PMModuleBase pm = DEVICE.GetDevice<PMModule>(_source.ToString()+"."+ _source.ToString());
- _target = EquipmentManager.Modules[_source] as ITransferTarget;
- //if (!pm.CheckReadyForTransfer(ModuleName.EfemRobot, _blade, _sourceSlot, EnumTransferType.Retract, out _))
- //{
- // EV.PostWarningLog(Module, $"can not retract, {_source} not ready for transfer");
- // return Result.FAIL;
- //}
- }
- Notify($"Start, retract from {_source} slot {_sourceSlot + 1} with {_blade}");
- return Result.RUN;
- }
- public void Abort()
- {
- Notify("Abort");
- }
- public Result Monitor()
- {
- try
- {
- RobotRetract((int)RoutineStep.Retract,_source, _sourceSlot, _blade, _timeout);
- //WaitSlitValveCloseInterlock((int)RoutineStep.WaitCloseSlitValveInterlock, TMDevice.GetSlitValve(_source), _timeout);
- //ExecuteRoutine((int)RoutineStep.CloseSlitValve, _closeSlitValveRoutine);
- if (ModuleHelper.IsPm(_source))
- {
- PostTransfer((int)RoutineStep.PostTransfer, _target as PMModuleBase, EnumTransferType.Retract, _timeout);
- }
- }
- catch (RoutineBreakException)
- {
- return Result.RUN;
- }
- catch (RoutineFaildException)
- {
- return Result.FAIL;
- }
- Notify($"Finish, retract from {_source} slot {_sourceSlot + 1} with {_blade}");
- return Result.DONE;
- }
-
- public void RobotRetract(int id, ModuleName chamber, int slot, Hand hand, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify("robot execute goto command");
- //string reason;
-
- //if (!_robotModule.RobotDevice.GotoRE(chamber, hand, slot, postiontype, out reason))
- //{
- // Stop(reason);
- // return false;
- //}
- return true;
- }, () =>
- {
- if (_robotModule.RobotDevice.IsError)
- return null;
- if (_robotModule.RobotDevice.IsIdle)
- return true;
- return false;
- }, timeout * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop(string.Format("failed."));
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void PostTransfer(int id, PMModuleBase pm, EnumTransferType type, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"{pm.Name} post transfer ");
- if (!pm.PostTransfer(ModuleName.EfemRobot, Hand.Blade1, 0, type, out string reason))
- {
- Stop(reason);
- return false;
- }
- return true;
- }, () =>
- {
- if (pm.IsError)
- {
- return null;
- }
- return pm.IsReady;
- }, timeout * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop($"{pm.Name} error");
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop($"{pm.Name} post transfer timeout, over {timeout} seconds");
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- }
- }
|