123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621 |
- 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 EfemPlaceRoutine : ModuleRoutine, IRoutine
- {
- enum RoutineStep
- {
- QuerySourceState,
- CheckBeforePlace,
- PlaceWafer,
- CheckBeforePlace2,
- PlaceWafer2,
- PlaceDelay,
- PostTransfer,
- PrepareTransfer,
- PlaceRetract,
- PlaceExtend,
- LiftUp,
- LiftDown,
- }
- private int _timeout;
- private ModuleName _source;
- private int _sourceSlot;
- private Hand _hand;
- private bool _autoHand;
- private EfemModule _robotModule;
-
- private ITransferTarget _target;
- private int _postTransferTimeout;
- public EfemPlaceRoutine(EfemModule robotModule)
- {
- Module = "EfemRobot";
- Name = "Place";
- _robotModule = robotModule;
- }
- public Result Start(params object[] objs)
- {
- _timeout = SC.GetValue<int>("EFEM.EfemRobot.PlaceTimeout");
- Reset();
- if (_autoHand)
- {
- if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
- {
- _hand = Hand.Blade1;
- }
- else if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1))
- {
- _hand = Hand.Blade2;
- }
- else
- {
- EV.PostWarningLog(Module, $"Can not place, Robot both arm no wafer");
- return Result.FAIL;
- }
- }
- if (_hand == Hand.Both)
- {
- if (!SC.GetValueOrDefault<bool>("EFEM.EfemRobot.LowerBladeEnable"))
- {
- EV.PostAlarmLog(Module, $"Can not pick, Lower Blade is Disabled");
- return Result.FAIL;
- }
- if (!SC.GetValueOrDefault<bool>("EFEM.EfemRobot.UpperBladeEnable"))
- {
- EV.PostAlarmLog(Module, $"Can not pick, Upper Blade is Disabled");
- return Result.FAIL;
- }
- if (WaferManager.Instance.GetWafers(_source).Length < 2)
- {
- EV.PostWarningLog(Module, $"Can not place use both arm, Only one slot at {_source}");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckNoWafer(_source, _sourceSlot))
- {
- EV.PostWarningLog(Module, $"Can not place, should no wafer at {_source}, {_sourceSlot + 1}");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckNoWafer(_source, _sourceSlot + 1))
- {
- EV.PostWarningLog(Module, $"Can not place, should no wafer at {_source}, {_sourceSlot + 1 + 1}");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)Hand.Blade1))
- {
- EV.PostWarningLog(Module, $"Can not place, Robot arm 1 no wafer");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)Hand.Blade2))
- {
- EV.PostWarningLog(Module, $"Can not place, Robot arm 2 no wafer");
- return Result.FAIL;
- }
- }
- else
- {
- if (_hand == Hand.Blade1 && !SC.GetValueOrDefault<bool>("EFEM.EfemRobot.LowerBladeEnable"))
- {
- EV.PostAlarmLog(Module, $"Can not pick, Lower Blade is Disabled");
- return Result.FAIL;
- }
- if (_hand == Hand.Blade2 && !SC.GetValueOrDefault<bool>("EFEM.EfemRobot.UpperBladeEnable"))
- {
- EV.PostAlarmLog(Module, $"Can not pick, Upper Blade is Disabled");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckNoWafer(_source, _sourceSlot))
- {
- EV.PostWarningLog(Module, $"Can not place, should no wafer at {_source}, {_sourceSlot + 1}");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand))
- {
- EV.PostWarningLog(Module, $"Can not place, Robot arm {(int)_hand + 1} no wafer");
- return Result.FAIL;
- }
- }
- if (ModuleHelper.IsLoadPort(_source))
- {
- if (WaferManager.Instance.GetWafer(ModuleName.EfemRobot, (int)_hand).Size != CarrierManager.Instance.GetCarrier(_source).CarrierWaferSize)
- {
- EV.PostWarningLog(Module, $"Can not place, Carrier Size and Wafer Size not matched");
- return Result.FAIL;
- }
- }
- Notify($"Start, Place to {_source} slot {_sourceSlot + 1}, by {_hand}");
- return Result.RUN;
- }
- //public Result Start(params object[] objs)
- //{
- // return Start((ModuleName)objs[0], (int)objs[1], (Hand)objs[2]);
- //}
- public void Init(ModuleName source, int slot, Hand hand)
- {
- _autoHand = false;
- _source = source;
- _sourceSlot = slot;
- _hand = hand;
- _target = EquipmentManager.Modules[source] as ITransferTarget;
- if (ModuleHelper.IsPm(source))
- _postTransferTimeout = SC.GetValue<int>($"PM.PostTransferTimeout");
- }
- public void Init(ModuleName source, int slot)
- {
- _autoHand = true;
- _source = source;
- _sourceSlot = slot;
- _target = EquipmentManager.Modules[source] as ITransferTarget;
- if (ModuleHelper.IsPm(source))
- _postTransferTimeout = SC.GetValue<int>($"PM.PostTransferTimeout");
- }
- public void Abort()
- {
- if (_target != null)
- {
- _target.NoteTransferStop(ModuleName.EfemRobot, Hand.Blade1, 0, EnumTransferType.Place);
- }
- _target = null;
- Notify("Abort");
- }
- public Result Monitor()
- {
- try
- {
- if (ModuleHelper.IsPm(_source))
- {
- if (!_target.CheckReadyForTransfer(ModuleName.EfemRobot, _hand, _sourceSlot, EnumTransferType.Pick, out _))
- {
- PrepareTransfer((int)RoutineStep.PrepareTransfer, _target as PMModuleBase, EnumTransferType.Place, _postTransferTimeout);
- }
- }
- if (_hand == Hand.Both)
- {
- CheckBeforePlace((int)RoutineStep.CheckBeforePlace, _source, _sourceSlot, Hand.Blade1);
- PlaceWafer((int)RoutineStep.PlaceWafer, _source, _sourceSlot, Hand.Blade1, _timeout);
- CheckBeforePlace((int)RoutineStep.CheckBeforePlace2, _source, _sourceSlot + 1, Hand.Blade2);
- PlaceWafer((int)RoutineStep.PlaceWafer2, _source, _sourceSlot + 1, Hand.Blade2, _timeout);
- }
- else
- {
- CheckBeforePlace((int)RoutineStep.CheckBeforePlace, _source, _sourceSlot, _hand);
- if (ModuleHelper.IsPm(_source))
- {
- RobotExtend((int)RoutineStep.PlaceExtend, _source, _sourceSlot, _hand, RobotPostionEnum.PlaceExtendUp, _timeout);
- MovePinUp((int)RoutineStep.LiftUp, _target as PMModuleBase, EnumTransferType.Extend, _timeout);
- RobotRetract((int)RoutineStep.PlaceRetract, _source, _sourceSlot, _hand, RobotPostionEnum.PlaceRetract, _timeout);
- //提高产能,放到process
- //LiftPinDown((int)RoutineStep.LiftDown, _target as PMModuleBase, EnumTransferType.Retract, _timeout);
- }
- else
- {
- PlaceWafer((int)RoutineStep.PlaceWafer, _source, _sourceSlot, _hand, _timeout);
- }
- }
- if (ModuleHelper.IsPm(_source))
- {
- 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.Place);
- Notify($"Finish, Place to {_source} slot {_sourceSlot + 1}, by {_hand}");
- return Result.DONE;
- }
- 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, _hand, _sourceSlot, 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.Blade1, 0, 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 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());
- }
- }
- 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 LiftPinDown(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());
- }
- }
- }
- }
|