using Aitex.Core.Common; using Aitex.Core.RT.Device; using Aitex.Core.RT.Event; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using Aitex.Sorter.Common; using MECF.Framework.Common.Device.Bases; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.SubstrateTrackings; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using FurnaceRT.Equipments.Systems; namespace FurnaceRT.Equipments.WaferRobots { public class WaferRobotHome : ModuleRoutine, IRoutine { enum RoutineStep { SetCommunication, RobotReset, RobotSetServoOn, SetLoadArm1, SetLoadArm2, Home, CheckLoad1, CheckLoad2, SetSpeed, RobotRequestWaferPresent1, RobotRequestWaferPresent2, UpdateWaferInfoByRobotSensor, } private WaferRobotModule _waferRobotModule; private int _timeout = 0; private int _speed = 1; public WaferRobotHome(WaferRobotModule waferRobotModule) { _waferRobotModule = waferRobotModule; Module = waferRobotModule.Module; Name = "Home"; } public Result Start(params object[] objs) { Reset(); _timeout = SC.GetValue($"{Module}.HomeTimeout"); _speed = SC.GetValue($"{Module}.RobotSpeed"); _waferRobotModule.RobotHomeFailAlarm.RetryMessage = (int)WaferRobotModule.MSG.Home; _waferRobotModule.RobotHomeTimeoutAlarm.RetryMessage = (int)WaferRobotModule.MSG.Home; _waferRobotModule.SetServoOnTimeoutAlarm.RetryMessage = (int)WaferRobotModule.MSG.Home; _waferRobotModule.CheckLoadTimeoutAlarm.RetryMessage = (int)WaferRobotModule.MSG.Home; _waferRobotModule.SetSpeedTimeoutAlarm.RetryMessage = (int)WaferRobotModule.MSG.Home; _waferRobotModule.RequestWaferPresentTimeoutAlarm.RetryMessage = (int)WaferRobotModule.MSG.Home; Notify($"Start"); return Result.RUN; } public void Abort() { _waferRobotModule.Stop(); } public override Result Monitor() { try { PauseRountine(_waferRobotModule.WaferRobotDevice.IsPause); if (_waferRobotModule.WaferRobotDevice.IsPause) return Result.RUN; //RobotReset((int)RoutineStep.RobotReset, _timeout); //RobotSetServoOn((int)RoutineStep.RobotSetServoOn, _waferRobot, true, _timeout); RobotHome((int)RoutineStep.Home, _timeout); //RobotCheckLoad((int)RoutineStep.CheckLoad1, _waferRobot, Hand.Blade1, _timeout); //RobotCheckLoad((int)RoutineStep.CheckLoad2, _waferRobot, Hand.Blade2, _timeout); RobotSetSpeed((int)RoutineStep.SetSpeed, _speed, _timeout); RobotRequestWaferPresent((int)RoutineStep.RobotRequestWaferPresent1, Hand.Blade1, _timeout); //RobotRequestWaferPresent((int)RoutineStep.RobotRequestWaferPresent2, Hand.Blade2, _timeout); UpdateWaferInfoByRobotSensor((int)RoutineStep.UpdateWaferInfoByRobotSensor); } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException ex) { return Result.FAIL; } _waferRobotModule.ResetRobotActionCommand(); Notify("Finished"); return Result.DONE; } private void RobotReset(int id, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Set robot reset"); _waferRobotModule.SetCassetteRobotReset(); return true; }, () => { if (_waferRobotModule.WaferRobotDevice.IsReady()) { return true; } return false; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { _waferRobotModule.RobotHomeTimeoutAlarm.Set($"timeout over {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } private void RobotSetServoOn(int id, Robot robot, bool isOn, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Set servo {(isOn ? "on":"off")}"); if (!robot.SetServoOnOff(isOn, out string reason)) { _waferRobotModule.SetServoOnFailAlarm.Description = reason; _waferRobotModule.SetServoOnFailAlarm.Set(); return false; } return true; }, () => { if (!robot.Busy) { return true; } return false; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { _waferRobotModule.SetServoOnTimeoutAlarm.Description = $"timeout over {timeout} seconds"; _waferRobotModule.SetServoOnTimeoutAlarm.Set(); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void RobotSetLoad(int id, Robot robot, Hand hand, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Set default load {hand}"); if (!robot.SetLoad(hand, out string reason)) { Stop(reason); return false; } return true; }, () => { if (!robot.Busy) { 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($"timeout over {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void RobotHome(int id, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify("Execute home"); if (!_waferRobotModule.SetWaferRobotHome(out string reason)) { //_waferRobotModule.RobotHomeFailAlarm.Description = reason; _waferRobotModule.RobotHomeFailAlarm.Set(reason); return false; } return true; }, () => { if (_waferRobotModule.WaferRobotDevice.IsReady() && !_waferRobotModule.WaferRobotDevice.IsError) { return true; } return false; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { _waferRobotModule.RobotHomeTimeoutAlarm.Description = $"timeout over {timeout} seconds"; _waferRobotModule.RobotHomeTimeoutAlarm.Set(); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void RobotCheckLoad(int id, Robot robot, Hand hand, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify("Check load"); if (!robot.CheckLoad(hand, out string reason)) { _waferRobotModule.CheckLoadFailAlarm.Description = reason; _waferRobotModule.CheckLoadFailAlarm.Set(); return false; } return true; }, () => { if (!robot.Busy) { return true; } return false; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { _waferRobotModule.CheckLoadTimeoutAlarm.Description = $"timeout over {timeout} seconds"; _waferRobotModule.CheckLoadTimeoutAlarm.Set(); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void RobotSetSpeed(int id, int speed, int timeout) { Tuple ret = ExecuteAndWait(id, () => { if (speed > 3 || speed < 1) speed = 1; Notify($"set speed to {speed}"); if (!_waferRobotModule.SetSpeed(speed, out string reason)) { //_waferRobotModule.SetSpeedFailAlarm.Description = reason; _waferRobotModule.SetSpeedFailAlarm.Set(reason); return false; } return true; }, () => { if (_waferRobotModule.WaferRobotDevice.IsReady() && !_waferRobotModule.WaferRobotDevice.IsError) { return true; } return false; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { //_waferRobotModule.SetSpeedTimeoutAlarm.Description = $"timeout over {timeout} seconds"; _waferRobotModule.SetSpeedTimeoutAlarm.Set($"timeout over {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } private void RobotRequestWaferPresent(int id, Hand hand, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify("request wafer present"); if (!_waferRobotModule.RequestWaferPresent(hand, out string reason)) { _waferRobotModule.RequestWaferPresentFailAlarm.Description = reason; _waferRobotModule.RequestWaferPresentFailAlarm.Set(); return false; } return true; }, () => { if (_waferRobotModule.WaferRobotDevice.IsReady() && !_waferRobotModule.WaferRobotDevice.IsError) { return true; } return false; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { //_waferRobotModule.RequestWaferPresentTimeoutAlarm.Description = $"timeout over {timeout} seconds"; _waferRobotModule.RequestWaferPresentTimeoutAlarm.Set($"timeout over {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } protected void UpdateWaferInfoByRobotSensor(int id) { Tuple ret = Execute(id, () => { Notify($"Update wafer info by robot wafer present"); if (SC.GetValue("System.IsSimulatorMode")) return true; if (_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade1 && WaferManager.Instance.CheckNoWafer(_waferRobotModule.Module, 0)) { EV.PostInfoLog(Module, "Wafer Robot sensor found wafer on blade 1"); WaferManager.Instance.CreateWafer(ModuleHelper.Converter(_waferRobotModule.Module), 0, WaferStatus.Normal); } if (!_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade1 && WaferManager.Instance.CheckHasWafer(_waferRobotModule.Module, 0)) { EV.PostInfoLog(Module, "Wafer Robot sensor no wafer on blade 1"); WaferManager.Instance.DeleteWafer(ModuleHelper.Converter(_waferRobotModule.Module), 0); } if (_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade2 && WaferManager.Instance.CheckNoWafer(_waferRobotModule.Module, 1)) { EV.PostInfoLog(Module, "Wafer Robot sensor found wafer on blade 2"); WaferManager.Instance.CreateWafer(ModuleHelper.Converter(_waferRobotModule.Module), 1, WaferStatus.Normal); } if (!_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade2 && WaferManager.Instance.CheckHasWafer(_waferRobotModule.Module, 1)) { EV.PostInfoLog(Module, "Wafer Robot sensor no wafer on blade 2"); WaferManager.Instance.DeleteWafer(ModuleHelper.Converter(_waferRobotModule.Module), 1); } if (_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade3 && WaferManager.Instance.CheckNoWafer(_waferRobotModule.Module, 2)) { EV.PostInfoLog(Module, "Wafer Robot sensor found wafer on blade 3"); WaferManager.Instance.CreateWafer(ModuleHelper.Converter(_waferRobotModule.Module), 2, WaferStatus.Normal); } if (!_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade3 && WaferManager.Instance.CheckHasWafer(_waferRobotModule.Module, 2)) { EV.PostInfoLog(Module, "Wafer Robot sensor no wafer on blade 3"); WaferManager.Instance.DeleteWafer(ModuleHelper.Converter(_waferRobotModule.Module), 2); } if (_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade4 && WaferManager.Instance.CheckNoWafer(_waferRobotModule.Module, 3)) { EV.PostInfoLog(Module, "Wafer Robot sensor found wafer on blade 4"); WaferManager.Instance.CreateWafer(ModuleHelper.Converter(_waferRobotModule.Module), 3, WaferStatus.Normal); } if (!_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade4 && WaferManager.Instance.CheckHasWafer(_waferRobotModule.Module, 3)) { EV.PostInfoLog(Module, "Wafer Robot sensor no wafer on blade 4"); WaferManager.Instance.DeleteWafer(ModuleHelper.Converter(_waferRobotModule.Module), 3); } if (_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade5 && WaferManager.Instance.CheckNoWafer(_waferRobotModule.Module, 4)) { EV.PostInfoLog(Module, "Wafer Robot sensor found wafer on blade 5"); WaferManager.Instance.CreateWafer(ModuleHelper.Converter(_waferRobotModule.Module), 4, WaferStatus.Normal); } if (!_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade5 && WaferManager.Instance.CheckHasWafer(_waferRobotModule.Module, 4)) { EV.PostInfoLog(Module, "Wafer Robot sensor no wafer on blade 5"); WaferManager.Instance.DeleteWafer(ModuleHelper.Converter(_waferRobotModule.Module), 4); } return true; }); if (ret.Item1) { throw (new RoutineBreakException()); } } } }