| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 | 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<int>($"{Module}.HomeTimeout");            _speed = SC.GetValue<int>($"{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;            }            Notify("Finished");            return Result.DONE;        }        private void RobotReset(int id, int timeout)        {            Tuple<bool, Result> 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<bool, Result> 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<bool, Result> 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<bool, Result> 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<bool, Result> 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<bool, Result> 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<bool, Result> 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<bool, Result> ret = Execute(id, () => {                Notify($"Update wafer info by robot wafer present");                if (SC.GetValue<bool>("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());            }        }            }}
 |