123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- using System;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Fsm;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.Utilities;
- 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.Efems.Rorzes;
- using MECF.Framework.RT.ModuleLibrary.AlignerModules;
- namespace FutureEfemLib.Aligners
- {
- public class AlignerModule : AlignerModuleBase
- {
- private FutureAligner _alignerDevice;
- public enum STATE
- {
- NotInstall,
- Init,
- Idle,
- Homing,
- MapWaferPresence,
- Error,
- NotConnect,
- InTransfer,
- Aligning,
- }
- public enum MSG
- {
- Home,
- Connected,
- Disconnected,
- MapWaferPresence,
- Align,
- Reset,
- Abort,
- Error,
- ToInit,
- InTransfer,
- TransferComplete
- }
- public event Action<string> OnEnterError;
- public override bool IsReady
- {
- get { return FsmState == (int)STATE.Idle && CheckAllMessageProcessed(); }
- }
- public override bool IsError
- {
- get { return FsmState == (int)STATE.Error; }
- }
- private bool _isInit;
- public override bool IsInit
- {
- get { return _isInit; }
- }
- private AlignerHomeRoutine _home;
- private AlignerAlignRoutine _align;
- public AlignerModule(ModuleName module) : base(1)
- {
- Name = module.ToString();
- Module = module.ToString();
- IsOnline = true;
- }
- public override bool Initialize()
- {
- InitRoutine();
- InitDevice();
- InitFsm();
- InitOp();
- InitData();
- return base.Initialize();
- }
- private void InitRoutine()
- {
- _home = new AlignerHomeRoutine(this);
- _align = new AlignerAlignRoutine(this);
- }
- public void InitDevice()
- {
- _alignerDevice = DEVICE.GetDevice<FutureAligner>($"{ModuleName.Aligner}.{ModuleName.Aligner}");
- }
- private void InitData()
- {
- DATA.Subscribe($"{Module}.Status", () => StringFsmStatus);
- DATA.Subscribe($"{Module}.IsOnline", () => IsOnline);
- DATA.Subscribe($"{Module}.WaferSize", () => WaferManager.Instance.GetWaferSize(ModuleHelper.Converter(Module), 0).ToString());
- }
- private void InitOp()
- {
- OP.Subscribe($"{Module}.Home", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Home));
- OP.Subscribe($"{Module}.Reset", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Reset));
- OP.Subscribe($"{Module}.Align", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Align,args));
- }
- private void InitFsm()
- {
- EnumLoop<STATE>.ForEach((item) =>
- {
- MapState((int)item, item.ToString());
- });
- EnumLoop<MSG>.ForEach((item) =>
- {
- MapMessage((int)item, item.ToString());
- });
- EnableFsm(50, IsInstalled ? STATE.Init : STATE.NotInstall);
- //Error
- AnyStateTransition(MSG.Error, FsmOnError, STATE.Error);
- Transition(STATE.Error, MSG.Reset, FsmReset, STATE.Idle);
- EnterExitTransition<STATE, FSM_MSG>(STATE.Error, FsmEnterError, FSM_MSG.NONE, FsmExitError);
- //Init
- Transition(STATE.Init, MSG.Home, FsmStartHome, STATE.Homing);
- Transition(STATE.Error, MSG.Home, FsmStartHome, STATE.Homing);
- Transition(STATE.Idle, MSG.Home, FsmStartHome, STATE.Homing);
- Transition(STATE.Homing, FSM_MSG.TIMER, FsmMonitorHomeTask, STATE.Idle);
- Transition(STATE.Homing, MSG.Error, null, STATE.Init);
- Transition(STATE.Homing, MSG.Abort, FsmAbortTask, STATE.Init);
- AnyStateTransition(MSG.ToInit, FsmToInit, STATE.Init);
- //idle
- EnterExitTransition<STATE, FSM_MSG>(STATE.Idle, FsmEnterIdle, FSM_MSG.NONE, FsmExitIdle);
- //align
- Transition(STATE.Idle, MSG.Align, FsmStartAlign, STATE.Aligning);
- Transition(STATE.Aligning, FSM_MSG.TIMER, FsmMonitorAlignTask, STATE.Idle);
- Transition(STATE.Aligning, MSG.Error, null, STATE.Init);
- Transition(STATE.Aligning, MSG.Abort, FsmAbortTask, STATE.Init);
- }
- #region Service Functions
- public override bool Align(double angle)
- {
- return CheckToPostMessage((int)MSG.Align,angle);
- }
- public override bool Home(out string reason)
- {
- if (!CheckToPostMessage((int)MSG.Home))
- {
- reason = $"Can not home in {StringFsmStatus} status";
- return false;
- }
- reason = string.Empty;
- return true;
- }
- public override void Reset()
- {
- if (IsError)
- {
- if (_alignerDevice.IsError)
- {
- _alignerDevice.Reset();
- }
- CheckToPostMessage((int)MSG.Reset);
- }
- }
- public override bool PrepareTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
- {
- reason = string.Empty;
- return true;
- }
- public override bool TransferHandoff(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
- {
- reason = string.Empty;
- return true;
- }
- public override bool PostTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
- {
- reason = string.Empty;
- return true;
- }
- public override bool CheckReadyForTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType,
- out string reason)
- {
- reason = string.Empty;
- if (transferType == EnumTransferType.Pick)
- {
- return IsReady&&WaferManager.Instance.CheckHasWafer(Module, targetSlot);
- }
- if (transferType == EnumTransferType.Place)
- {
- return IsReady&&WaferManager.Instance.CheckNoWafer(Module, targetSlot);
- }
- return false;
- }
- public override void NoteTransferStart(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType)
- {
- //CheckToPostMessage(MSG.InTransfer);
- }
- public override void NoteTransferStop(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType)
- {
- //if (FsmState == (int)STATE.InTransfer)
- // CheckToPostMessage(MSG.TransferComplete);
- }
- private bool FsmReset(object[] param)
- {
- if (!_isInit)
- {
- PostMsg(MSG.ToInit);
- return false;
- }
- if (_alignerDevice.IsError)
- {
- EV.PostWarningLog(Module, $"{Module} in error, home to recover");
- PostMsg(MSG.ToInit);
- return false;
- }
- return true;
- }
- private bool FsmOnError(object[] param)
- {
- if (FsmState == (int)STATE.Error)
- {
- return false;
- }
- AbortRoutine();
- if (FsmState == (int)STATE.Init)
- return false;
- return true;
- }
- private bool FsmExitIdle(object[] param)
- {
- return true;
- }
- private bool FsmEnterIdle(object[] param)
- {
- return true;
- }
- private bool FsmExitError(object[] param)
- {
- return true;
- }
- private bool FsmEnterError(object[] param)
- {
- if (OnEnterError != null)
- OnEnterError(Module);
- return true;
- }
- private bool FsmAbortTask(object[] param)
- {
- AbortRoutine();
- return true;
- }
- private bool FsmStartHome(object[] param)
- {
- Result ret = StartRoutine(_home);
- if (ret == Result.FAIL || ret == Result.DONE)
- return false;
- _isInit = false;
- return ret == Result.RUN;
- }
- private bool FsmMonitorHomeTask(object[] param)
- {
- Result ret = MonitorRoutine();
- if (ret == Result.FAIL)
- {
- PostMsg(MSG.Error);
- return false;
- }
- if (ret == Result.DONE)
- {
- _isInit = true;
- return true;
- }
- return false;
- }
- private bool FsmStartAlign(object[] param)
- {
- _align.Init(Convert.ToDouble(param[0]));
- Result ret = StartRoutine(_align);
- if (ret == Result.FAIL || ret == Result.DONE)
- return false;
- _isInit = false;
- return ret == Result.RUN;
- }
- private bool FsmMonitorAlignTask(object[] param)
- {
- Result ret = MonitorRoutine();
- if (ret == Result.FAIL)
- {
- PostMsg(MSG.Error);
- return false;
- }
- if (ret == Result.DONE)
- {
- _isInit = true;
- return true;
- }
- return false;
- }
- private bool FsmToInit(object[] param)
- {
- return true;
- }
- private bool FsmToIdle(object[] param)
- {
- return true;
- }
- public override bool Lift(bool up)
- {
- return true;
- }
- #endregion
- }
- }
|