123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560 |
- using System;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Device.Unit;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.IOCore;
- 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 TMPlaceRoutine : ModuleRoutine, IRoutine
- {
- enum RoutineStep
- {
- PrepareTransfer,
- QuerySourceState,
- CheckBeforePlace,
- PlaceWafer,
- CheckBeforePlace2,
- PlaceWafer2,
- PlaceDelay,
- TransferHandoff,
- PlaceRetract,
- PostTransfer,
- }
- private int _timeout;
- 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 TMPlaceRoutine(TMModule robotModule)
- {
- Module = "TM";
- Name = "Place";
- _robotModule = robotModule;
- }
- public Result Start(params object[] objs)
- {
- _timeout = SC.GetValue<int>("TM.TMRobot.PlaceTimeout");
- Reset();
- if (!DEVICE.GetDevice<IoSensor>($"System.SensorTMInSafety").Value)
- {
- EV.PostAlarmLog(Module, $"Can not place, Sensor TMInSafety is false");
- return Result.FAIL;
- }
- if (_source == ModuleName.LLA && DEVICE.GetDevice<IoSensor>($"System.SensorBufferABigWaferProtrusion").Value)
- {
- EV.PostAlarmLog(Module, $"Can not place, Sensor BufferABigWaferProtrusion is false");
- return Result.FAIL;
- }
- if (_source == ModuleName.LLB && DEVICE.GetDevice<IoSensor>($"System.SensorBufferBBigWaferProtrusion").Value)
- {
- EV.PostAlarmLog(Module, $"Can not place, Sensor BufferBBigWaferProtrusion is false");
- return Result.FAIL;
- }
- if (_autoHand)
- {
- if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0))
- {
- _hand = Hand.Blade1;
- }
- else if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 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>("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 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.TMRobot, (int)Hand.Blade1))
- {
- EV.PostWarningLog(Module, $"Can not place, Robot arm 1 no wafer");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (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>("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.CheckNoWafer(_source, _sourceSlot))
- {
- EV.PostWarningLog(Module, $"Can not place, should no wafer at {_source}, {_sourceSlot + 1}");
- return Result.FAIL;
- }
- if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand))
- {
- EV.PostWarningLog(Module, $"Can not place, Robot arm {(int)_hand + 1} no wafer");
- 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, double temp1, double temp2, bool enableCheckTemp=true)
- {
- _autoHand = false;
- _TargetTemp1 = temp1;
- _TargetTemp2 = temp2;
- _enableCheck = enableCheckTemp;
- _source = source;
- _sourceSlot = slot;
- _hand = hand;
- _target = EquipmentManager.Modules[source] as ITransferTarget;
- if (ModuleHelper.IsPm(source))
- _postTransferTimeout = SC.GetValue<int>($"{source}.PostTransferTimeout");
- }
- public void Init(ModuleName source, int slot, double temp1, double temp2, bool enableCheckTemp = true)
- {
- _autoHand = true;
- _TargetTemp1 = temp1;
- _TargetTemp2 = temp2;
- _enableCheck = enableCheckTemp;
- _source = source;
- _sourceSlot = slot;
- _target = EquipmentManager.Modules[source] as ITransferTarget;
- if (ModuleHelper.IsPm(source))
- _postTransferTimeout = SC.GetValue<int>($"{source}.PostTransferTimeout");
- }
- public void Abort()
- {
- if (_target != null)
- {
- _target.NoteTransferStop(ModuleName.TMRobot, Hand.Blade1, 0, EnumTransferType.Place);
- }
- _target = null;
- Notify("Abort");
- }
- public Result Monitor()
- {
- try
- {
- if (ModuleHelper.IsPm(_source))
- {
- PrepareTransfer((int)RoutineStep.PrepareTransfer, _target as PMModuleBase, _hand, _sourceSlot, EnumTransferType.Place, _postTransferTimeout, _TargetTemp1, _TargetTemp2, _enableCheck);
- }
- CheckBeforePlace((int)RoutineStep.CheckBeforePlace, _source, _sourceSlot, _hand, _postTransferTimeout);
- PlaceWafer((int)RoutineStep.PlaceWafer, _source, _sourceSlot, _hand, _timeout);
- if (ModuleHelper.IsPm(_source))
- {
- TransferHandoff((int)RoutineStep.TransferHandoff, _target as PMModuleBase, _hand, _sourceSlot, EnumTransferType.Place, _postTransferTimeout);
- PlaceRetract((int)RoutineStep.PlaceRetract, _source, _sourceSlot, _hand, _timeout);
- PostTransfer((int)RoutineStep.PostTransfer, _target as PMModuleBase, _hand, _sourceSlot, EnumTransferType.Place, _postTransferTimeout);
- }
- }
- catch (RoutineBreakException)
- {
- return Result.RUN;
- }
- catch (RoutineFaildException)
- {
- return Result.FAIL;
- }
- _target.NoteTransferStop(ModuleName.TMRobot, Hand.Blade1, 0, EnumTransferType.Place);
- //WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _source, _sourceSlot);
- Notify($"Finish, Place to {_source} slot {_sourceSlot + 1}, by {_hand}");
- return Result.DONE;
- }
- public void PrepareTransfer(int id, PMModuleBase pm, Hand hand, int slot, EnumTransferType type, int timeout, double temp1, double temp2, bool enableCheckTemp = true)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"{pm.Name}{slot + 1} 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}{slot} error");
- throw new RoutineFaildException();
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop($"{pm.Name}{slot} prepare transfer timeout, over {timeout} seconds");
- throw new RoutineFaildException();
- }
- else
- throw new RoutineBreakException();
- }
- }
- public void CheckBeforePlace(int id, ModuleName source, int slot, Hand blade, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify("Check place condition");
- string reason = string.Empty;
- if (blade == Hand.Blade1)
- {
- if (!WaferManager.Instance.CheckNoWafer(source, slot))
- {
- Stop("Source has wafer");
- return false;
- }
- if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)blade))
- {
- Stop("Blade 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.TMRobot, (int)blade))
- {
- 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.TMRobot, i))
- {
- Stop("Blade no wafer");
- return false;
- }
- }
- }
- return true;
- }, () =>
- {
- if (_robotModule.RobotDevice.IsError)
- return null;
- if (_target.CheckReadyForTransfer(ModuleName.TMRobot, _hand, _sourceSlot, EnumTransferType.Place, 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 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.TMRobot, hand, slot, EnumTransferType.Place);
- if (!_robotModule.RobotDevice.Place((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)
- {
- 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 PlaceRetract(int id, ModuleName chamber, int slot, Hand hand, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify("robot execute place retract command");
- _target.NoteTransferStart(ModuleName.TMRobot, hand, slot, EnumTransferType.Pick);
- if (!_robotModule.RobotDevice.PlaceRetract((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 TransferHandoff(int id, PMModuleBase pm, Hand hand, int slot, EnumTransferType type, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"{pm.Name}{slot} 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}{slot} error");
- throw new RoutineFaildException();
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop($"{pm.Name}{slot} 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());
- }
- }
- }
- }
|