123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- using System;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
- namespace JetMainframe.TMs
- {
- public class TMHomeRoutine : ModuleRoutine, IRoutine
- {
- enum RoutineStep
- {
- ClearError,
- QueryArmPos,
- CheckArmPos,
- InitRobot,
- HomeRobot,
- }
- private int _timeout = 0;
- private TMModule _tmModule;
- public TMHomeRoutine(TMModule robotModule)
- {
- Module = ModuleName.TMRobot.ToString();
- Name = "Home";
- _tmModule = robotModule;
- }
- public Result Start(params object[] objs)
- {
- Reset();
- _timeout = SC.GetValue<int>("TM.TMRobot.HomeTimeout");
- Notify($"Start");
- return Result.RUN;
- }
- public Result Monitor()
- {
- try
- {
- ClearError((int)RoutineStep.ClearError, _timeout);
- QueryArmPos((int)RoutineStep.QueryArmPos, _timeout);
- CheckArmPos((int)RoutineStep.CheckArmPos, _timeout);
- //InitRobot((int)RoutineStep.InitRobot, _timeout);
- HomeRobot((int)RoutineStep.HomeRobot, _timeout);
- }
- catch (RoutineBreakException)
- {
- return Result.RUN;
- }
- catch (RoutineFaildException)
- {
- return Result.FAIL;
- }
- Notify("Finished");
- return Result.DONE;
- }
- public void ClearError(int id, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"Start clear Robot error");
- _tmModule.RobotDevice.Reset();
- return true;
- }, () =>
- {
- if (_tmModule.RobotDevice.IsBusy)
- return false;
- if (_tmModule.RobotDevice.IsError)
- return false;
- return true;
- }, timeout * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop(string.Format("Home failed."));
- throw new RoutineFaildException();
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop(string.Format("Home timeout, can not clear error in {0} seconds", timeout));
- throw new RoutineFaildException();
- }
- else
- throw new RoutineBreakException();
- }
- }
- public void QueryArmPos(int id, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"Start Query arm pos");
- _tmModule.RobotDevice.PostMsg(RobotBaseDevice.RobotMsg.ReadData, "CurrentPositionData");
- return true;
- }, () =>
- {
- if (_tmModule.RobotDevice.IsError)
- return null;
- if (!_tmModule.RobotDevice.IsIdle)
- return false;
- return true;
- }, timeout * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop(string.Format("Home failed , Query arm pos failed ."));
- throw new RoutineFaildException();
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop(string.Format("Home timeout, can not complete in {0} seconds", timeout));
- throw new RoutineFaildException();
- }
- else
- throw new RoutineBreakException();
- }
- }
- public void CheckArmPos(int id, int timeout)
- {
- Tuple<bool, Result> ret = Check(id, () =>
- {
- return _tmModule.RobotDevice.IsInSafePosition();
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop(string.Format("Home failed , arm in unsafe position ."));
- throw new RoutineFaildException();
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop(string.Format("Home timeout, can not complete in {0} seconds", timeout));
- throw new RoutineFaildException();
- }
- else
- throw new RoutineBreakException();
- }
- }
- //public void InitRobot(int id, int timeout)
- //{
- // Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- // {
- // Notify($"Start Retract robot arm");
- // if (!_tmModule.RobotDevice.Retract(null))
- // {
- // return false;
- // }
- // return true;
- // }, () =>
- // {
- // if (!_tmModule.RobotDevice.IsIdle)
- // return false;
- // return true;
- // }, timeout * 1000);
- // if (ret.Item1)
- // {
- // if (ret.Item2 == Result.FAIL)
- // {
- // Stop(string.Format("Home failed."));
- // throw new RoutineFaildException();
- // }
- // else if (ret.Item2 == Result.TIMEOUT) //timeout
- // {
- // Stop(string.Format("Home timeout, can not complete in {0} seconds", timeout));
- // throw new RoutineFaildException();
- // }
- // else
- // throw new RoutineBreakException();
- // }
- //}
- public void HomeRobot(int id, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"Start home robot");
- if (!_tmModule.RobotDevice.Home(null))
- {
- return false;
- }
- return true;
- }, () =>
- {
- if (_tmModule.RobotDevice.IsError)
- {
- return null;
- }
- if (!_tmModule.RobotDevice.IsIdle)
- return false;
- return true;
- }, timeout * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop(string.Format("Home failed."));
- throw new RoutineFaildException();
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop(string.Format("Home timeout, can not complete in {0} seconds", timeout));
- throw new RoutineFaildException();
- }
- else
- throw new RoutineBreakException();
- }
- }
-
- //public void CheckRobotWafer(int id, int timeout)
- //{
- // Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- // {
- // Notify($"Start check robot wafer present");
- // //string reason;
- // //if (!_efem.QueryRobotWaferPresence(out _, out reason))
- // //{
- // // Stop(reason);
- // // return false;
- // //}
- // return true;
- // }, () =>
- // {
- // //if (_efem.CheckIsBusy(ModuleName.System))
- // // return false;
- // return true;
- // }, timeout * 1000);
- // if (ret.Item1)
- // {
- // if (ret.Item2 == Result.FAIL)
- // {
- // Stop(string.Format("Home failed."));
- // throw new RoutineFaildException();
- // }
- // else if (ret.Item2 == Result.TIMEOUT) //timeout
- // {
- // Stop(string.Format("Home timeout, can not complete in {0} seconds", timeout));
- // throw new RoutineFaildException();
- // }
- // else
- // throw new RoutineBreakException();
- // }
- //}
- public void Abort()
- {
- }
- }
- }
|