123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- 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.Event;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
- using MECF.Framework.RT.ModuleLibrary.TMModules;
- namespace JetMainframe.TMs
- {
- public partial class TMModule : TMModuleBase
- {
- public enum STATE
- {
- NotInstall,
- Init,
- Idle,
- Homing,
- Picking,
- Placing,
- RobotGoto,
- Swapping,
- Mapping,
- Load,
- Unload,
- Error,
- NotConnect,
- }
- public enum MSG
- {
- Home,
- Connected,
- Disconnected,
- Map,
- Pick,
- PickAndPlace,
- Place,
- Goto,
- Reset,
- Abort,
- Error,
- ToInit,
- }
- public override bool IsReady
- {
- get { return FsmState == (int)STATE.Idle && CheckAllMessageProcessed(); }
- }
- public override bool IsError
- {
- get { return FsmState == (int)STATE.Error; }
- }
- public override bool IsInit
- {
- get { return FsmState == (int)STATE.Init; }
- }
- public bool IsBusy
- {
- get { return !IsInit && !IsError && !IsReady; }
- }
- public event Action<string> OnEnterError;
- public bool IsEfemRobotHomed { get; set; }
- public RobotBaseDevice RobotDevice { get; set; }
- protected TMHomeRoutine _homeRoutine = null;
- protected TMPickRoutine _pickRoutine = null;
- protected TMPlaceRoutine _placeRoutine = null;
- protected TMGotoRoutine _gotoRoutine = null;
- protected TMMapRoutine _mapRoutine = null;
- protected TMPickAndPlaceRoutine _pickAndPlaceRoutine = null;
- //private bool _isInit;
- public TMModule(ModuleName module, int slotCount = 2) : base(slotCount)
- {
- Module = module.ToString();
- Name = module.ToString();
- IsOnline = true;
- }
- public override bool Initialize()
- {
- InitRoutine();
- InitDevice();
- InitFsm();
- InitOp();
- InitData();
- return base.Initialize();
- }
- protected virtual void InitRoutine()
- {
- _homeRoutine = new TMHomeRoutine(this);
- _pickRoutine = new TMPickRoutine(this);
- _placeRoutine = new TMPlaceRoutine(this);
- _gotoRoutine = new TMGotoRoutine(this);
- _mapRoutine = new TMMapRoutine(this);
- _pickAndPlaceRoutine = new TMPickAndPlaceRoutine(this);
- }
- private void InitData()
- {
- DATA.Subscribe($"{Module}.Status", () => StringFsmStatus);
- DATA.Subscribe($"{Module}.IsOnline", () => IsOnline);
- DATA.Subscribe($"{Module}.IsHomed", () => IsEfemRobotHomed);
- DATA.Subscribe($"{Module}.IsError", () => IsError);
- DATA.Subscribe($"{Module}.WaferSize", () => WaferManager.Instance.GetWaferSize(ModuleHelper.Converter(Module), 0).ToString());
- }
- private void InitOp()
- {
- OP.Subscribe($"{Name}.Home", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Home);
- });
- OP.Subscribe($"{Name}.Abort", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Abort);
- });
- OP.Subscribe($"{Name}.Reset", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Reset);
- });
- OP.Subscribe($"{Name}.Pick", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Pick, args);
- });
- OP.Subscribe($"{Name}.Place", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Place, args);
- });
- OP.Subscribe($"{Name}.Goto", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Goto, args[0]);
- });
- OP.Subscribe($"{Name}.Map", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Map, args[0]);
- });
- OP.Subscribe($"{Name}.SetOnline", (string cmd, object[] args) =>
- {
- IsOnline = true;
- return true;
- });
- OP.Subscribe($"{Name}.SetOffline", (string cmd, object[] args) =>
- {
- IsOnline = false;
- return true;
- });
- //OP.Subscribe("EFEM.Initialize", (method, objects) =>
- //{
- // Init();
- // return true;
- //});
- //OP.Subscribe("EFEM.ClearError", (method, objects) =>
- //{
- // ClearError();
- // return true;
- //});
- }
- 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);
- AnyStateTransition(FSM_MSG.WARNING, fWarning, FSM_STATE.SAME);
- AnyStateTransition((int)FSM_MSG.ALARM, fAlarm, (int)STATE.Error);
- //connection
- AnyStateTransition(MSG.Disconnected, FsmOnDisconnected, STATE.NotConnect);
- Transition(STATE.NotConnect, MSG.Connected, FsmOnConnected, STATE.Init);
- Transition(STATE.NotConnect, MSG.Reset, FsmResetConnect, STATE.NotConnect);
- //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);
- EnterExitTransition<STATE, FSM_MSG>(STATE.Idle, FsmEnterIdle, FSM_MSG.NONE, FsmExitIdle);
- AnyStateTransition(MSG.ToInit, FsmToInit, STATE.Init);
- //robot home
- Transition(STATE.Idle, MSG.Map, FsmStartMap, STATE.Mapping);
- Transition(STATE.Mapping, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
- Transition(STATE.Mapping, MSG.Abort, FsmAbortTask, STATE.Idle);
- //robot pick
- Transition(STATE.Idle, MSG.Pick, FsmStartRobotPick, STATE.Picking);
- Transition(STATE.Picking, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
- Transition(STATE.Picking, MSG.Abort, FsmAbortTask, STATE.Idle);
- //robot pickAndplace
- Transition(STATE.Idle, MSG.PickAndPlace, FsmStartPickAndPlace, STATE.Swapping);
- Transition(STATE.Swapping, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
- Transition(STATE.Swapping, MSG.Abort, FsmAbortTask, STATE.Idle);
- //robot place
- Transition(STATE.Idle, MSG.Place, FsmStartRobotPlace, STATE.Placing);
- Transition(STATE.Placing, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
- Transition(STATE.Placing, MSG.Abort, FsmAbortTask, STATE.Idle);
- //robot goto
- Transition(STATE.Idle, MSG.Goto, FsmStartRobotGoto, STATE.RobotGoto);
- Transition(STATE.RobotGoto, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
- Transition(STATE.RobotGoto, MSG.Abort, FsmAbortTask, STATE.Idle);
- }
- private bool FsmToInit(object[] param)
- {
- return true;
- }
- private bool FsmResetConnect(object[] param)
- {
- //if (!EfemDevice.Connection.IsConnected)
- //{
- // EfemDevice.Connect();
- // return false;
- //}
- //if (!EfemDevice.EmoAlarm.IsAcknowledged)
- //{
- // EfemDevice.ClearError();
- // return false;
- //}
- return true;
- }
- private bool FsmOnConnected(object[] param)
- {
- //SignalTowerDevice.ResetData();
- //LP1Device.ResetData();
- //LP2Device.ResetData();
- //LP3Device.ResetData();
- //LP4Device.ResetData();
- //EfemDevice.ResetData();
- return true;
- }
- private bool FsmOnDisconnected(object[] param)
- {
- 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 fWarning(object[] objs)
- {
- //IsWarning = false;
- return true;
- }
- private bool fAlarm(object[] objs)
- {
- if (FsmState == (int)STATE.Init)
- return false;
- return true;
- }
- private bool FsmStartHome(object[] param)
- {
- Result ret = StartRoutine(_homeRoutine);
- if (ret == Result.FAIL)
- {
- PostMsg(MSG.Error);
- return false;
- }
- if (ret == Result.DONE)
- return false;
- //_isInit = false;
- IsEfemRobotHomed = false;
- return ret == Result.RUN;
- }
- private bool FsmStartRobotPick(object[] param)
- {
- if (param.Length == 6)
- {
- _pickRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1], (Hand)param[2], (double)param[3], (double)param[4], (bool)param[5]);
- }
- else
- {
- _pickRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1], (double)param[2], (double)param[3], (bool)param[4]);
- }
- Result ret = StartRoutine(_pickRoutine);
- if (ret == Result.FAIL)
- {
- PostMsg(MSG.Error);
- return false;
- }
- if (ret == Result.DONE)
- return false;
- return ret == Result.RUN;
- }
- private bool FsmStartPickAndPlace(object[] param)
- {
- _pickAndPlaceRoutine.Init(ModuleHelper.Converter((string)param[0]), (Hand)param[1], (int)param[2], (Hand)param[3], (int)param[4]);
- Result ret = StartRoutine(_pickAndPlaceRoutine);
- if (ret == Result.FAIL)
- {
- PostMsg(MSG.Error);
- return false;
- }
- if (ret == Result.DONE)
- return false;
- return ret == Result.RUN;
- }
- private bool FsmStartRobotPlace(object[] param)
- {
- if (param.Length == 6)
- {
- _placeRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1], (Hand)param[2], (double)param[3], (double)param[4], (bool)param[5]);
- }
- else
- {
- _placeRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1], (double)param[2], (double)param[3], (bool)param[4]);
- }
- Result ret = StartRoutine(_placeRoutine);
- if (ret == Result.FAIL)
- {
- PostMsg(MSG.Error);
- return false;
- }
- if (ret == Result.DONE)
- return false;
- return ret == Result.RUN;
- }
- private bool FsmStartRobotGoto(object[] param)
- {
- _gotoRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1], (Hand)param[2]);
- Result ret = StartRoutine(_gotoRoutine);
- if (ret == Result.FAIL)
- {
- PostMsg(MSG.Error);
- return false;
- }
- if (ret == Result.DONE)
- return false;
- return ret == Result.RUN;
- }
- private bool FsmStartMap(object[] param)
- {
- _mapRoutine.Init(ModuleHelper.Converter((string)param[0]));
- Result ret = StartRoutine(_mapRoutine);
- if (ret == Result.FAIL)
- {
- PostMsg(MSG.Error);
- return false;
- }
- if (ret == Result.DONE)
- return false;
- return ret == Result.RUN;
- }
- private bool FsmAbortTask(object[] param)
- {
- AbortRoutine();
- if (!RobotDevice.IsIdle)
- {
- RobotDevice.PostMsg(RobotBaseDevice.RobotMsg.Stop);
- }
- return true;
- }
- private bool FsmMonitorHomeTask(object[] param)
- {
- Result ret = MonitorRoutine();
- if (ret == Result.FAIL)
- {
- PostMsg(MSG.Error);
- return false;
- }
- if (ret == Result.DONE)
- {
- OP.DoOperation($"{Module}.ResetTask");
- //_isInit = true;
- return true;
- }
- return false;
- }
- private bool FsmMonitorTask(object[] param)
- {
- Result ret = MonitorRoutine();
- if (ret == Result.FAIL)
- {
- PostMsg(MSG.Error);
- return false;
- }
- return ret == Result.DONE;
- }
- private bool FsmOnError(object[] param)
- {
- if (FsmState == (int)STATE.Error)
- {
- return false;
- }
- if (FsmState == (int)STATE.Picking)
- {
- _pickRoutine.Abort();
- }
- if (FsmState == (int)STATE.Placing)
- {
- _placeRoutine.Abort();
- }
- if (FsmState == (int)STATE.RobotGoto)
- {
- _gotoRoutine.Abort();
- }
- if (FsmState == (int)STATE.Init)
- return false;
- return true;
- }
- private bool FsmReset(object[] param)
- {
- //if (!EfemDevice.Connection.IsConnected)
- //{
- // EfemDevice.Connect();
- // return false;
- //}
- //if (!EfemDevice.EmoAlarm.IsAcknowledged)
- //{
- // EfemDevice.ClearError();
- // return false;
- //}
- //if (!_isInit)
- //{
- // PostMsg(MSG.ToInit);
- // return false;
- //}
- if (RobotDevice.IsError)
- {
- EV.PostWarningLog(Module, $"Robot in error, home to recover");
- RobotDevice.PostMsg(RobotBaseDevice.RobotMsg.Reset);
- //return false;
- }
- return true;
- }
- #region Service functions
- 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 (RobotDevice.IsError)
- //{
- // RobotDevice.Reset();
- //}
- //else if (RobotDevice.RobotState != RobotStateEnum.Idle && RobotDevice.RobotState != RobotStateEnum.Init)
- //{
- // EV.PostWarningLog(Module, $"Robot in {RobotDevice.RobotState}, need home to reset error");
- // return;
- //}
- CheckToPostMessage((int)MSG.Reset);
- }
- }
- public override bool Pick(ModuleName target, Hand blade, int targetSlot, out string reason)
- {
- reason = string.Empty;
- return true;
- }
- public override bool Place(ModuleName target, Hand blade, int targetSlot, out string reason)
- {
- reason = string.Empty;
- return true;
- }
- public override bool Pick(ModuleName target, Hand blade, int targetSlot, double temp1, double temp2, bool EnableCheck, out string reason)
- {
- CheckToPostMessage((int)MSG.Pick, target.ToString(), targetSlot, blade, temp1, temp2, EnableCheck);
- reason = string.Empty;
- return true;
- }
- public override bool Place(ModuleName target, Hand blade, int targetSlot, double temp1, double temp2, bool EnableCheck, out string reason)
- {
- CheckToPostMessage((int)MSG.Place, target.ToString(), targetSlot, blade, temp1, temp2, EnableCheck);
- reason = string.Empty;
- return true;
- }
- public override bool PickAndPlace(ModuleName pickTarget, Hand pickHand, int pickSlot, ModuleName placeTarget, Hand placeHand,
- int placeSlot, out string reason)
- {
- CheckToPostMessage((int)MSG.PickAndPlace, pickTarget.ToString(), pickHand, pickSlot, placeHand, placeSlot);
- reason = string.Empty;
- return true;
- }
- public override bool Goto(ModuleName target, Hand blade, int targetSlot, out string reason)
- {
- CheckToPostMessage((int)MSG.Goto, target.ToString(), targetSlot, blade);
- reason = string.Empty;
- return true;
- }
- public override bool Map(ModuleName target, out string reason)
- {
- if (!CheckToPostMessage((int)MSG.Map, target.ToString()))
- {
- reason = $"Can not support map in {StringFsmStatus}";
- return false;
- }
- reason = string.Empty;
- return true;
- }
- private void EfemDevice_OnDeviceAlarmStateChanged(string module, AlarmEventItem alarmItem)
- {
- if (IsInit)
- return;
- if (!alarmItem.IsAcknowledged)
- {
- if (alarmItem.Level == EventLevel.Warning)
- {
- EV.PostWarningLog(Module, alarmItem.Description);
- }
- else
- {
- EV.PostAlarmLog(Module, alarmItem.Description);
- }
- //if (alarmItem.EventEnum == EfemDevice.IsMaintain.EventEnum
- //|| alarmItem.EventEnum == EfemDevice.EmoAlarm.EventEnum
- //|| alarmItem.EventEnum == EfemDevice.DoorOpen.EventEnum)
- //{
- // _isInit = false;
- // PostMsg(MSG.Error);
- //}
- //else if (alarmItem.Level == EventLevel.Alarm)
- //{
- // PostMsg(MSG.Error);
- //}
- }
- else
- {
- if (IsError)
- CheckToPostMessage((int)MSG.Reset);
- }
- }
- private void Connection_OnError(string obj)
- {
- PostMsg(MSG.Disconnected);
- }
- private void Connection_OnDisconnected()
- {
- PostMsg(MSG.Disconnected);
- }
- private void Connection_OnConnected()
- {
- PostMsg(MSG.Connected);
- }
- #endregion
- }
- }
|