123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- using System;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using Aitex.Sorter.Common;
- using MECF.Framework.Common.Equipment;
- namespace FutureEfemLib.Efems
- {
- public class EfemGotoRoutine : ModuleRoutine, IRoutine
- {
- enum RoutineStep
- {
- CheckBeforeGoto,
- RobotGoto,
- }
- private int _gotoTimeout;
- private ModuleName _source;
- private int _sourceSlot;
- private Hand _hand;
-
- private EfemModule _robotModule;
-
- public EfemGotoRoutine(EfemModule robotModule)
- {
- Module = "EfemRobot";
- Name = "Goto";
- _robotModule = robotModule;
- }
- public Result Start(params object[] objs)
- {
- _gotoTimeout = SC.GetValue<int>("EFEM.EfemRobot.GotoTimeout");
- Reset();
- Notify($"Start, Goto {_source} slot {_sourceSlot + 1}, by {_hand}");
- return Result.RUN;
- }
- public void Init(ModuleName source, int slot, Hand hand)
- {
-
- _source = source;
- _sourceSlot = slot;
- _hand = hand;
-
- }
-
- public void Abort()
- {
- Notify("Abort");
- }
- public Result Monitor()
- {
- try
- {
-
- CheckBeforeGoto((int)RoutineStep.CheckBeforeGoto, _source, _sourceSlot, _hand);
- RobotGoto((int)RoutineStep.RobotGoto, _source, _sourceSlot, _hand, _gotoTimeout);
-
- }
- catch (RoutineBreakException)
- {
- return Result.RUN;
- }
- catch (RoutineFaildException)
- {
- return Result.FAIL;
- }
-
- Notify($"Finish, robot move to {_source} slot {_sourceSlot + 1}, by {_hand}");
- return Result.DONE;
- }
- public void CheckBeforeGoto(int id, ModuleName source, int slot, Hand blade)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- Notify("Check robot goto motion is enabled");
- string reason = string.Empty;
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
- }
- public void RobotGoto(int id, ModuleName chamber, int slot, Hand hand, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify("robot execute goto command");
-
- string reason;
- if (!_robotModule.RobotDevice.Goto(chamber, hand, slot, out reason))
- {
- Stop(reason);
- 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());
- }
- }
-
- }
- }
|