123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519 |
- using System;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Device.Unit;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- 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 JetMainframe.TMs
- {
- public class TMPickRoutine : ModuleRoutine, IRoutine
- {
- enum RoutineStep
- {
- PrepareTransfer,
- CheckBeforePick,
- PickWafer,
- CheckBeforePick2,
- PickWafer2,
- TransferHandoff,
- PickRetract,
- PostTransfer,
- }
- private int _pickTimeout;
- private ModuleName _source;
- private int _sourceSlot;
- private Hand _hand;
- private bool _autoHand;
- private double _TargetTemp1 = 0.0f;
- private double _TargetTemp2 = 0.0f;
- private bool _enableCheck = false;
- private TMModule _robotModule;
- private ITransferTarget _target;
- private int _postTransferTimeout;
- public TMPickRoutine(TMModule robotModule)
- {
- Module = "TM";
- Name = "Pick";
- _robotModule = robotModule;
- }
- public Result Start(params object[] objs)
- {
- _pickTimeout = SC.GetValue<int>("TM.TMRobot.PickTimeout");
- Reset();
- if (!DEVICE.GetDevice<IoSensor>($"System.SensorTMInSafety").Value)
- {
- EV.PostAlarmLog(Module, $"Can not pick, Sensor TMInSafety is false");
- return Result.FAIL;
- }
- if (_source == ModuleName.LLA && DEVICE.GetDevice<IoSensor>($"System.SensorBufferABigWaferProtrusion").Value)
- {
- EV.PostAlarmLog(Module, $"Can not pick, Sensor BufferABigWaferProtrusion is false");
- return Result.FAIL;
- }
- if (_source == ModuleName.LLB && DEVICE.GetDevice<IoSensor>($"System.SensorBufferBBigWaferProtrusion").Value)
- {
- EV.PostAlarmLog(Module, $"Can not pick, Sensor BufferBBigWaferProtrusion is false");
- return Result.FAIL;
- }
- if (_autoHand)
- {
- if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0))
- {
- _hand = Hand.Blade1;
- }
- else if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
- {
- _hand = Hand.Blade2;
- }
- else
- {
- EV.PostWarningLog(Module, $"Can not pick, Robot both arm has wafer");
- return Result.FAIL;
- }
- }
- if (_hand == Hand.Both)
- {
- if (!SC.GetValueOrDefault<bool>("TM.TMRobot.LowerBladeEnable"))
- {
- EV.PostAlarmLog(Module, $"Can not pick, Lower Blade is Disabled");
- return Result.FAIL;
- }
- if (!SC.GetValueOrDefault<bool>("TM.TMRobot.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 pick use both arm, Only one slot at {_source}");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckHasWafer(_source, _sourceSlot))
- {
- EV.PostWarningLog(Module, $"Can not pick, No wafer at {_source}, {_sourceSlot + 1}");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckHasWafer(_source, _sourceSlot + 1))
- {
- EV.PostWarningLog(Module, $"Can not pick, No wafer at {_source}, {_sourceSlot + 1 + 1}");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckNoWafer(Module, (int)Hand.Blade1))
- {
- EV.PostWarningLog(Module, $"Can not pick, Robot arm 1 has wafer");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckNoWafer(Module, (int)Hand.Blade2))
- {
- EV.PostWarningLog(Module, $"Can not pick, Robot arm 2 has wafer");
- return Result.FAIL;
- }
- }
- else
- {
- if (_hand == Hand.Blade1 && !SC.GetValueOrDefault<bool>("TM.TMRobot.LowerBladeEnable"))
- {
- EV.PostAlarmLog(Module, $"Can not pick, Lower Blade is Disabled");
- return Result.FAIL;
- }
- if (_hand == Hand.Blade2 && !SC.GetValueOrDefault<bool>("TM.TMRobot.UpperBladeEnable"))
- {
- EV.PostAlarmLog(Module, $"Can not pick, Upper Blade is Disabled");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckHasWafer(_source, _sourceSlot))
- {
- EV.PostWarningLog(Module, $"Can not pick, No wafer at {_source}, {_sourceSlot + 1}");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckNoWafer(Module, (int)_hand))
- {
- EV.PostWarningLog(Module, $"Can not pick, Robot arm {(int)_hand + 1} has wafer");
- return Result.FAIL;
- }
- }
- Notify($"Start, Pick from {_source} slot {_sourceSlot + 1}, by {_hand}");
- return Result.RUN;
- }
- public void Init(ModuleName source, int slot, Hand hand, double temp1, double temp2, bool enableCheckTemp)
- {
- _autoHand = false;
- _TargetTemp1 = temp1;
- _TargetTemp2 = temp2;
- _enableCheck = enableCheckTemp;
- _source = source;
- _sourceSlot = slot;
- _hand = hand;
- if (ModuleHelper.IsPm(source))
- _postTransferTimeout = SC.GetValue<int>($"{source}.PostTransferTimeout");
- _target = EquipmentManager.Modules[source] as ITransferTarget;
- }
- public void Init(ModuleName source, int slot, double temp1, double temp2, bool enableCheckTemp)
- {
- _autoHand = true;
- _TargetTemp1 = temp1;
- _TargetTemp2 = temp2;
- _enableCheck = enableCheckTemp;
- _source = source;
- _sourceSlot = slot;
- if (ModuleHelper.IsPm(source))
- _postTransferTimeout = SC.GetValue<int>($"{source}.PostTransferTimeout");
- _target = EquipmentManager.Modules[source] as ITransferTarget;
- }
- public void Abort()
- {
- if (_target != null)
- {
- _target.NoteTransferStop(ModuleName.TMRobot, Hand.Blade1, 0, EnumTransferType.Pick);
- }
- _target = null;
- Notify("Abort");
- }
- public Result Monitor()
- {
- try
- {
- if (ModuleHelper.IsPm(_source))
- {
- PrepareTransfer((int)RoutineStep.PrepareTransfer, _target as PMModuleBase, _hand, _sourceSlot, EnumTransferType.Pick, _postTransferTimeout, _TargetTemp1, _TargetTemp2, _enableCheck);
- }
- CheckBeforePick((int)RoutineStep.CheckBeforePick, _source, _sourceSlot, _hand, _postTransferTimeout);
- PickWafer((int)RoutineStep.PickWafer, _source, _sourceSlot, _hand, _pickTimeout);
- if (ModuleHelper.IsPm(_source))
- {
- TransferHandoff((int)RoutineStep.TransferHandoff, _target as PMModuleBase, _hand, _sourceSlot, EnumTransferType.Pick, _postTransferTimeout);
- PickRetract((int)RoutineStep.PickRetract, _source, _sourceSlot, _hand, _pickTimeout);
- PostTransfer((int)RoutineStep.PostTransfer, _target as PMModuleBase, _hand, _sourceSlot, EnumTransferType.Pick, _postTransferTimeout);
- }
- }
- catch (RoutineBreakException)
- {
- return Result.RUN;
- }
- catch (RoutineFaildException)
- {
- return Result.FAIL;
- }
- _target.NoteTransferStop(ModuleName.TMRobot, Hand.Blade1, 0, EnumTransferType.Pick);
- //WaferManager.Instance.WaferMoved(_source, _sourceSlot, ModuleName.TMRobot, (int)_hand);
- Notify($"Finish, Pick from {_source} slot {_sourceSlot + 1}, by {_hand}");
- return Result.DONE;
- }
- public void CheckBeforePick(int id, ModuleName source, int slot, Hand blade, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify("Check pick is enabled");
- string reason = string.Empty;
- if (!WaferManager.Instance.CheckHasWafer(source, slot))
- {
- Stop("Source no wafer");
- return false;
- }
- if (!WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)blade))
- {
- Stop("Blade has wafer");
- return false;
- }
- return true;
- }, () =>
- {
- if (_robotModule.RobotDevice.IsError)
- return null;
- if (_target.CheckReadyForTransfer(ModuleName.TMRobot, _hand, _sourceSlot, EnumTransferType.Pick, out _))
- {
- 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 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.TMRobot, hand, slot, EnumTransferType.Pick);
- if (!_robotModule.RobotDevice.Pick((RobotArmEnum)(int)hand, chamber.ToString(), slot))
- {
- 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 PickRetract(int id, ModuleName chamber, int slot, Hand hand, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify("robot execute pick retract command");
- _target.NoteTransferStart(ModuleName.TMRobot, hand, slot, EnumTransferType.Pick);
- if (!_robotModule.RobotDevice.PickRetract((RobotArmEnum)(int)hand, chamber.ToString(), slot))
- {
- 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, Hand hand, int slot, EnumTransferType type, int timeout, double temp1, double temp2, bool enableCheckTemp)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"{pm.Name} prepare transfer ");
- if (!pm.PrepareTransfer(ModuleName.TMRobot, hand, slot, type, temp1, temp2, enableCheckTemp, 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 TransferHandoff(int id, PMModuleBase pm, Hand hand, int slot, EnumTransferType type, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"{pm.Name} transfer handoff");
- if (!pm.TransferHandoff(ModuleName.TMRobot, hand, slot, 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} transfer handoff timeout, over {timeout} seconds");
- throw new RoutineFaildException();
- }
- else
- throw new RoutineBreakException();
- }
- }
- public void PostTransfer(int id, PMModuleBase pm, Hand hand, int slot, EnumTransferType type, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"{pm.Name} post transfer ");
- if (!pm.PostTransfer(ModuleName.TMRobot, hand, slot, 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();
- }
- }
- }
- }
|