123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- 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 EfemExtendRoutine : ModuleRoutine, IRoutine
- {
- enum RoutineStep
- {
- WaitOpenSlitValveInterlock,
- OpenSlitValve,
- CheckBeforeExtend,
- Extend,
- PrepareTransfer,
- }
- private ModuleName _source;
- private int _sourceSlot;
- private Hand _hand;
- private int _timeout;
- //private TMSlitValveRoutine _openSlitValveRoutine = new TMSlitValveRoutine();
- private ITransferTarget _target;
- private EfemModule _robotModule;
- //private RobotPostionEnum postiontype;
- public EfemExtendRoutine(EfemModule robotModule)
- {
- Module = "Efem";
- Name = "Extend";
- _robotModule = robotModule;
- }
- private string _type;
- public void Init(ModuleName source, int sourceSlot, string blade,string type)
- {
- _source = source;
- _sourceSlot = sourceSlot;
- _hand = (Hand)Enum.Parse(typeof(Hand), blade);
- _type = type;
- // _openSlitValveRoutine.Init(source.ToString(), true);
- }
- 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 extend, {_source} not ready for transfer");
- // return Result.FAIL;
- // }
- //}
- if (ModuleHelper.IsPm(_source))
- {
- if (_type=="Place")
- {
- //postiontype = RobotPostionEnum.PlaceExtendUp;//_hand == Hand.Blade1 ? RobotPostionEnum.PlaceExtendDown : RobotPostionEnum.PlaceExtendUp;
- }
- else
- {
- //postiontype = RobotPostionEnum.PickExtendLow;//_hand == Hand.Blade1 ? RobotPostionEnum.PickExtendLow : RobotPostionEnum.PickExtendUp;
- }
- _target = EquipmentManager.Modules[_source] as ITransferTarget;
- //if (!pm.CheckReadyForTransfer(ModuleName.EfemRobot,_hand, _sourceSlot, EnumTransferType.Extend, out _))
- //{
- // EV.PostWarningLog(Module, $"can not extend, {_source} not ready for transfer");
- // return Result.FAIL;
- //}
- }
- Notify($"Start, extend to {_source} slot {_sourceSlot + 1} with {_hand}");
- return Result.RUN;
- }
- public void Abort()
- {
- Notify("Abort");
- }
- public Result Monitor()
- {
- try
- {
- //if (!_target.CheckReadyForTransfer(ModuleName.EfemRobot, _hand, _sourceSlot, EnumTransferType.Pick, out _))
- //{
- // PrepareTransfer((int)RoutineStep.PrepareTransfer, _target as PMModuleBase, EnumTransferType.Extend, _timeout);
- //}
- //WaitSlitValveOpenInterlock((int)RoutineStep.WaitOpenSlitValveInterlock, TMDevice.GetSlitValve(_source), _timeout);
- //ExecuteRoutine((int)RoutineStep.OpenSlitValve, _openSlitValveRoutine);
- // CheckBeforeExtend((int)RoutineStep.CheckBeforeExtend, _source, _sourceSlot, _hand);
- RobotExtend((int)RoutineStep.Extend, _source, _sourceSlot, _hand, _timeout);
- }
- catch (RoutineBreakException)
- {
- return Result.RUN;
- }
- catch (RoutineFaildException)
- {
- return Result.FAIL;
- }
- Notify($"Finish, extend to {_source} slot {_sourceSlot + 1} with {_hand}");
- return Result.DONE;
- }
- public void RobotExtend(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 PrepareTransfer(int id, PMModuleBase pm, EnumTransferType type, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"{pm.Name} Prepare transfer ");
- if (!pm.PrepareTransfer(ModuleName.EfemRobot, Hand.Blade1, 0, type, 0, 0, false, 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} Prepare transfer timeout, over {timeout} seconds");
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- }
- }
|