123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618 |
- using System;
- using Aitex.Core.RT.Event;
- 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.Common.SubstrateTrackings;
- 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
- {
- public class EfemPickAndPlaceRoutine : ModuleRoutine, IRoutine
- {
- enum RoutineStep
- {
- CheckBeforePick,
- PickWafer,
- CheckBeforePlace,
- PlaceWafer,
- PostTransfer,
- PickExtend,
- PickRetract,
- PlaceExtend,
- PlaceRetract,
- PickLiftUp,
- PickLiftDown,
- PlaceLiftUp,
- PlaceLiftDown,
- }
- private EfemModule _robotModule;
- private ITransferTarget _target;
- private Hand _pickBlade;
- private Hand _placeBlade;
- private ModuleName _targetModule;
- private int _pickSlot;
- private int _placeSlot;
- private int _pickTimeout;
- private int _placeTimeout;
- private int _postTransferTimeout;
- public EfemPickAndPlaceRoutine(EfemModule robotModule)
- {
- Module = "EfemRobot";
- Name = "Pick";
- _robotModule = robotModule;
- }
- public Result Start(params object[] objs)
- {
- _pickTimeout = SC.GetValue<int>("EFEM.EfemRobot.PickTimeout");
- _placeTimeout = SC.GetValue<int>("EFEM.EfemRobot.PlaceTimeout");
- if (ModuleHelper.IsPm(_targetModule))
- {
- _postTransferTimeout = SC.GetValue<int>($"PM.PostTransferTimeout");
- }
- Reset();
- if (!WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_pickBlade))
- {
- EV.PostWarningLog(Module, $"Can not pick by {_pickBlade}, found wafer on");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_placeBlade))
- {
- EV.PostWarningLog(Module, $"Can not place by {_placeBlade}, no wafer on");
- return Result.FAIL;
- }
- if (_pickSlot != _placeSlot)
- {
- if (!WaferManager.Instance.CheckHasWafer(_targetModule, _pickSlot))
- {
- EV.PostWarningLog(Module, $"Can not pick from {_targetModule} slot {_pickSlot + 1}, no wafer on");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckNoWafer(_targetModule, _placeSlot))
- {
- EV.PostWarningLog(Module, $"Can not place to {_targetModule} slot {_placeSlot + 1}, found wafer on");
- return Result.FAIL;
- }
- }
- else
- {
- if (!WaferManager.Instance.CheckHasWafer(_targetModule, _placeSlot))
- {
- {
- EV.PostWarningLog(Module, $"Can not pick&place from {_targetModule} slot {_placeSlot + 1}, no wafer on");
- return Result.FAIL;
- }
- }
- }
- Notify($"Start, swap wafer,pick: {_pickBlade} slot {_pickSlot + 1}, place: {_placeBlade} slot {_placeSlot+1}");
- return Result.RUN;
- }
- public void Init(ModuleName targetModule, Hand pickBlade, int pickSlot, Hand placeBlade, int placeSlot)
- {
- _pickBlade = pickBlade;
- _placeBlade = placeBlade;
- _targetModule = targetModule;
- _pickSlot = pickSlot;
- _placeSlot = placeSlot;
- //_target = Singleton<EquipmentManager>.Instance.Modules[targetModule] as ITransferTarget;
- }
- public void Abort()
- {
- if (_target != null)
- {
- _target.NoteTransferStop(ModuleName.EfemRobot, Hand.Blade1, 0, EnumTransferType.Pick);
- }
- _target = null;
- Notify("Abort");
- }
- public Result Monitor()
- {
- try
- {
- CheckBeforePick((int)RoutineStep.CheckBeforePick, _targetModule, _pickSlot, _pickBlade);
- if (ModuleHelper.IsPm(_targetModule))
- {
- RobotExtend((int)RoutineStep.PickExtend, _targetModule, _pickSlot, _pickBlade, RobotPostionEnum.PickExtendLow, _pickTimeout);
- MovePinDown((int)RoutineStep.PickLiftDown, _target as PMModuleBase, EnumTransferType.Extend, _pickTimeout);
- RobotRetract((int)RoutineStep.PickRetract, _targetModule, _pickSlot, _pickBlade, RobotPostionEnum.PickRetracted, _pickTimeout);
- //MovePinDown((int)RoutineStep.PickLiftDown, _target as PMModuleBase, EnumTransferType.Retract, _pickTimeout);
- RobotExtend((int)RoutineStep.PlaceExtend, _targetModule, _placeSlot, _placeBlade, RobotPostionEnum.PlaceExtendUp, _pickTimeout);
- MovePinUp((int)RoutineStep.PlaceLiftUp, _target as PMModuleBase, EnumTransferType.Extend, _pickTimeout);
- RobotRetract((int)RoutineStep.PlaceRetract, _targetModule, _placeSlot, _placeBlade, RobotPostionEnum.PlaceRetract, _pickTimeout);
- //LiftPinDown((int)RoutineStep.PlaceLiftDown, _target as PMModuleBase, EnumTransferType.Retract, _pickTimeout);
- }
- else
- {
- PickWafer((int)RoutineStep.PickWafer, _targetModule, _pickSlot, _pickBlade, _pickTimeout);
- CheckBeforePlace((int)RoutineStep.CheckBeforePlace, _targetModule, _placeSlot, _placeBlade);
- PlaceWafer((int)RoutineStep.PlaceWafer, _targetModule, _placeSlot, _placeBlade, _pickTimeout);
- }
- if (ModuleHelper.IsPm(_targetModule))
- {
- PostTransfer((int)RoutineStep.PostTransfer, _target as PMModuleBase, EnumTransferType.Place, _postTransferTimeout);
- }
- }
- catch (RoutineBreakException)
- {
- return Result.RUN;
- }
- catch (RoutineFaildException)
- {
- return Result.FAIL;
- }
- _target.NoteTransferStop(ModuleName.EfemRobot, Hand.Blade1, 0, EnumTransferType.Pick);
- Notify($"complete, swap wafer,pick: {_pickBlade} slot {_pickSlot + 1}, place: {_placeBlade} slot {_placeSlot + 1}");
- return Result.DONE;
- }
- public void CheckBeforePick(int id, ModuleName source, int slot, Hand blade)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- Notify("Check pick is enabled");
- string reason = string.Empty;
- if (!_target.CheckReadyForTransfer(ModuleName.EfemRobot, blade, slot, EnumTransferType.Pick, out reason))
- {
- Stop(reason);
- return false;
- }
- if (blade == Hand.Blade1)
- {
- if (!WaferManager.Instance.CheckHasWafer(source, slot))
- {
- Stop("Source no wafer");
- return false;
- }
- if (!WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0))
- {
- Stop("Blade has wafer");
- return false;
- }
- }
- else if (blade == Hand.Blade2)
- {
- if (!WaferManager.Instance.CheckHasWafer(source, slot))
- {
- Stop("Source no wafer");
- return false;
- }
- if (!WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1))
- {
- Stop("Blade has wafer");
- return false;
- }
- }
- else
- {
- for (int i = 0; i < 2; i++)
- {
- if (!WaferManager.Instance.CheckHasWafer(source, slot + i))
- {
- Stop("Source no wafer");
- return false;
- }
- if (!WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, i))
- {
- Stop("Blade has wafer");
- return false;
- }
- }
- }
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
- }
- public void PickWafer(int id, ModuleName chamber, int slot, Hand hand, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify("robot execute pick command");
- _target.NoteTransferStart(ModuleName.EfemRobot, hand, slot, EnumTransferType.Pick);
- string reason;
- if (!_robotModule.RobotDevice.Pick(chamber, hand, slot, 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 CheckBeforePlace(int id, ModuleName source, int slot, Hand blade)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- Notify("Check place condition");
- string reason = string.Empty;
- if (!_target.CheckReadyForTransfer(ModuleName.EfemRobot, blade, slot, EnumTransferType.Place, out reason))
- {
- Stop(reason);
- return false;
- }
- if (blade == Hand.Blade1)
- {
- if (!WaferManager.Instance.CheckNoWafer(source, slot))
- {
- Stop("Source has wafer");
- return false;
- }
- if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
- {
- Stop("Blade 1 no wafer");
- return false;
- }
- }
- else if (blade == Hand.Blade2)
- {
- if (!WaferManager.Instance.CheckNoWafer(source, slot))
- {
- Stop("Source has wafer");
- return false;
- }
- if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1))
- {
- Stop("Blade no wafer");
- return false;
- }
- }
- else
- {
- for (int i = 0; i < 2; i++)
- {
- if (!WaferManager.Instance.CheckNoWafer(source, slot + i))
- {
- Stop("Source has wafer");
- return false;
- }
- if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, i))
- {
- Stop("Blade no wafer");
- return false;
- }
- }
- }
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
- }
- public void PlaceWafer(int id, ModuleName chamber, int slot, Hand hand, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify("robot start execute place command");
- string reason;
- _target.NoteTransferStart(ModuleName.EfemRobot, hand, slot, EnumTransferType.Place);
- if (!_robotModule.RobotDevice.Place(chamber, hand, slot, 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)
- {
- 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());
- }
- }
- public void RobotExtend(int id, ModuleName chamber, int slot, Hand hand, RobotPostionEnum robotPostion, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify("robot execute goto command");
- //string reason;
- //if (!_robotModule.RobotDevice.GotoRE(chamber, hand, slot, robotPostion, 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 RobotRetract(int id, ModuleName chamber, int slot, Hand hand, RobotPostionEnum robotPostion, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify("robot execute goto command");
- //string reason;
- //if (!_robotModule.RobotDevice.GotoRE(chamber, hand, slot, robotPostion, 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 MovePinUp(int id, PMModuleBase pm, EnumTransferType type, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"{pm.Name} lift pin up ");
- //if (!pm.ChamberLiftPin.MoveUp(out string reason))
- //{
- // Stop(reason);
- // return false;
- //}
- return true;
- }, () =>
- {
- //if (pm.ChamberLiftPin.IsUp)
- // return true;
- return false;
- }, timeout * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop($"{pm.Name} move lift pin up timeout, over {timeout} seconds");
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void MovePinDown(int id, PMModuleBase pm, EnumTransferType type, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"{pm.Name} lift pin down");
- //if (!pm.ChamberLiftPin.MoveDown(out string reason))
- //{
- // Stop(reason);
- // return false;
- //}
- return true;
- }, () =>
- {
- //if (pm.ChamberLiftPin.IsDown)
- // return true;
- return false;
- }, timeout * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop($"{pm.Name} move down lift pin timeout, over {timeout} seconds");
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- }
- }
|