123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212 |
- using Aitex.Core.Common;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Fsm;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.RT.RecipeCenter;
- using Aitex.Core.Util;
- using Aitex.Core.Utilities;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.RecipeCenter;
- using MECF.Framework.Common.SubstrateTrackings;
- using CyberX8_Core;
- using CyberX8_RT.Devices.AXIS;
- using CyberX8_RT.Devices.SRD;
- using CyberX8_RT.Modules.Transporter;
- using System;
- using MECF.Framework.Common.Persistent.SRD;
- using MECF.Framework.Common.ToolLayout;
- using CyberX8_RT.Modules.Dryer;
- using MECF.Framework.Common.Alarm;
- using MECF.Framework.Common.CommonData;
- using CyberX8_RT.Modules.Loader;
- namespace CyberX8_RT.Modules.SRD
- {
- public class SRDEntity : Entity, IEntity, IModuleEntity
- {
- #region 常量
- private const string AUTO = "Auto";
- private const string MANUAL = "Manual";
- private const string DISABLED = "Disabled";
- private const string ENGINEERING = "Engineering";
- private const string PRODUCTION = "Production";
- #endregion
- #region 内部变量
- /// <summary>
- /// 是否Homed
- /// </summary>
- private bool _isHomed;
- /// <summary>
- /// rotation电机
- /// </summary>
- private JetAxisBase _rotationAxis;
- /// <summary>
- /// arm电机
- /// </summary>
- private JetAxisBase _armAxis;
- /// <summary>
- /// IsPresenceTesting
- /// </summary>
- private bool _isPresenceTesting = false;
- /// <summary>
- /// IsAWCCycling
- /// </summary>
- private bool _isAWCCycling = false;
- /// <summary>
- /// 当前Recipe
- /// </summary>
- private SrdRecipe _currentRecipe = null;
- /// <summary>
- /// 持久化对象
- /// </summary>
- private SRDPersistentValue _persistentValue;
- /// <summary>
- /// run recipe start time
- /// </summary>
- private DateTime _runRecipeStartTime;
- /// <summary>
- /// run recipe complete time
- /// </summary>
- private DateTime _runRecipeCompleteTime;
- #endregion
- #region Routine
- /// <summary>
- /// SRD Home
- /// </summary>
- private SRDHomeRoutine _homeRoutine;
- /// <summary>
- /// SRD初始化Home Routine
- /// </summary>
- private SRDInitializeHomeRoutine _initializeHomeRoutine;
- /// <summary>
- /// SRD SwicthOn
- /// </summary>
- private SRDSwitchOnRoutine _switchOnRoutine;
- /// <summary>
- /// SRD SwicthOff
- /// </summary>
- private SRDSwitchOffRoutine _switchOffRoutine;
- /// <summary>
- /// SRD Initialize
- /// </summary>
- private SRDInitializeRoutine _initializeRoutine;
- /// <summary>
- /// SRD Common Device
- /// </summary>
- private SrdCommonDevice _srdCommon;
- /// <summary>
- /// SRD GoToPosition
- /// </summary>
- private SRDPositionRoutine _positionRoutine;
- /// <summary>
- /// SRD StartRotation
- /// </summary>
- private SRDRotationRoutine _rotationRoutine;
- /// <summary>
- /// SRD PresenceTest
- /// </summary>
- private SRDPresenceTestRoutine _presenceTestRoutine;
- /// <summary>
- /// SRD ProcessRecipe
- /// </summary>
- private SRDProcessRecipeRoutine _processRecipeRoutine;
- /// <summary>
- /// SRD AWC Cycle
- /// </summary>
- private SRDAWCCycleRoutine _awcCycleRoutine;
- /// <summary>
- /// SRD Process Error
- /// </summary>
- private SRDProcessErrorRoutine _processErrorRoutine;
- /// <summary>
- /// RecipeCycle
- /// </summary>
- private int _cycle = 0;
- /// <summary>
- /// recipe时长
- /// </summary>
- private int _recipeTime;
- #endregion
- #region 属性
- /// <summary>
- /// 模块名称
- /// </summary>
- public ModuleName Module { get; private set; }
- /// <summary>
- /// 初始化状态
- /// </summary>
- public bool IsInit
- {
- get { return fsm.State == (int)SRDState.Init; }
- }
- /// <summary>
- /// 空闲状态
- /// </summary>
- public bool IsIdle
- {
- get
- {
- return fsm.State == (int)SRDState.Idle;
- }
- }
- /// <summary>
- /// 当前状态机状态
- /// </summary>
- public int State { get { return fsm.State; } }
- /// <summary>
- /// 是否发生错误
- /// </summary>
- public bool IsError
- {
- get { return fsm.State == (int)SRDState.Error; }
- }
- /// <summary>
- /// 是否正在作业
- /// </summary>
- public bool IsBusy
- {
- get { return !IsInit && !IsError && !IsIdle; }
- }
- /// <summary>
- /// 是否已Home
- /// </summary>
- public bool IsHomed
- {
- get { return _isHomed; }
- }
- /// <summary>
- /// 是否正在用水
- /// </summary>
- public bool IsUsingWater
- {
- get { return _processRecipeRoutine.IsUsingWater; }
- }
- /// <summary>
- /// SRD门是否关闭
- /// </summary>
- public bool IsSrdDoorClosed
- {
- get { return !_srdCommon.CommonData.DoorOpened && _srdCommon.CommonData.DoorClosed; }
- }
- /// <summary>
- /// SRD真空是否开启
- /// </summary>
- public bool IsSrdChuckVacuum
- {
- get { return _srdCommon.CommonData.ChuckVacuum; }
- }
- /// <summary>
- /// 是否禁用
- /// </summary>
- public bool IsDisable { get { return _persistentValue == null || _persistentValue.OperatingMode == DISABLED; } }
- /// <summary>
- /// 自动模式
- /// </summary>
- public bool IsAuto { get { return _persistentValue != null && _persistentValue.OperatingMode == AUTO; } }
- /// <summary>
- /// 自动模式
- /// </summary>
- public bool IsManual { get { return _persistentValue != null && _persistentValue.OperatingMode == MANUAL; } }
- /// <summary>
- /// Arm是否SwitchOn
- /// </summary>
- public bool IsArmSwitchOn
- {
- get { return _armAxis.IsSwitchOn; }
- }
- /// <summary>
- /// Rotation是否SwitchOn
- /// </summary>
- public bool IsRotationSwitchOn
- {
- get { return _rotationAxis.IsSwitchOn; }
- }
- /// <summary>
- /// 已完成的RunRecipeCycle次数
- /// </summary>
- public int AchievedCycle { get { return _processRecipeRoutine.AchievedCycle; } }
- /// <summary>
- /// PresenceTest状态
- /// </summary>
- public bool IsPresenceTesting
- {
- get { return _isPresenceTesting; }
- }
- /// <summary>
- /// AWCCycle状态
- /// </summary>
- public bool IsAWCCycling
- {
- get { return _isAWCCycling; }
- }
- /// <summary>
- /// 当前状态机
- /// </summary>
- public string CurrentStateMachine
- {
- get { return GetCurrentStateMachine(); }
- }
- /// <summary>
- /// 是否为工程模式
- /// </summary>
- public bool IsEngineering { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == ENGINEERING; } }
- /// <summary>
- /// 是否为产品模式
- /// </summary>
- public bool IsProduction { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == PRODUCTION; } }
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public SRDEntity(ModuleName module)
- {
- this.Module = module;
- _armAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.Arm");
- _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.Rotation");
- WaferManager.Instance.SubscribeLocation(Module, 1);
- InitialFsm();
- }
- /// <summary>
- /// 总初始化
- /// </summary>
- /// <returns></returns>
- protected override bool Init()
- {
- _srdCommon = DEVICE.GetDevice<SrdCommonDevice>($"{Module}.Common");
- InitializeParameter();
- InitialDATA();
- InitialRoutine();
- InitialOperation();
- return true;
- }
- /// <summary>
- /// 初始化参数
- /// </summary>
- private void InitializeParameter()
- {
- _persistentValue = SRDPersistentManager.Instance.GetModulePersistentValue(Module.ToString());
- if (_persistentValue == null)
- {
- LOG.WriteLog(eEvent.ERR_SRD, Module.ToString(), "Persistent Value Object is not exist");
- }
- }
- /// <summary>
- /// 初始化数据
- /// </summary>
- private void InitialDATA()
- {
- DATA.Subscribe($"{Module}.FsmState", () => ((SRDState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.IsHomed", () => _isHomed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.IsError", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SrdDoorClosed", () => IsSrdDoorClosed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.AchievedCycle", () => AchievedCycle, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.IsPresenceTesting", () => IsPresenceTesting, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.CurrentStateMachine", () => CurrentStateMachine, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.IsAWCCycling", () => IsAWCCycling, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.CurrentRecipe", () => _currentRecipe != null ? _currentRecipe.Ppid : "", SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.TotalTime", () => _recipeTime, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.TimeRemain", () => CalculateTimeRemain(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.OperatingMode", () => _persistentValue != null ? _persistentValue.OperatingMode : "None", SubscriptionAttribute.FLAG.IgnoreSaveDB);
- }
- /// <summary>
- /// 初始化状态机
- /// </summary>
- private void InitialFsm()
- {
- fsm = new StateMachine<SRDEntity>(Module.ToString(), (int)SRDState.Init, 20);
- fsm.EnableRepeatedMsg(true);
- AnyStateTransition(SRDMSG.Error, EnterError, SRDState.Error);
- Transition(SRDState.Error, SRDMSG.ResumeError, (param) => { return true; }, SRDState.Init);
- //Initialized
- AnyStateTransition(SRDMSG.Initialize, InitializeAll, SRDState.Initializing);
- Transition(SRDState.Initializing, FSM_MSG.TIMER, InitializeAllTimeout, SRDState.Initialized);
- //SwitchOn
- Transition(SRDState.Init, SRDMSG.SwitchOn, SwitchOnAll, SRDState.SwitchOning);
- Transition(SRDState.Idle, SRDMSG.SwitchOn, SwitchOnAll, SRDState.SwitchOning);
- Transition(SRDState.Error, SRDMSG.SwitchOn, SwitchOnAll, SRDState.SwitchOning);
- Transition(SRDState.Initialized, SRDMSG.SwitchOn, SwitchOnAll, SRDState.SwitchOning);
- Transition(SRDState.SwitchOning, FSM_MSG.TIMER, SwitchOnTimeout, SRDState.Init);
- //SwitchOff
- Transition(SRDState.Init, SRDMSG.SwitchOff, SwitchOffAll, SRDState.SwitchOffing);
- Transition(SRDState.Idle, SRDMSG.SwitchOff, SwitchOffAll, SRDState.SwitchOffing);
- Transition(SRDState.Error, SRDMSG.SwitchOff, SwitchOffAll, SRDState.SwitchOffing);
- Transition(SRDState.Initialized, SRDMSG.SwitchOff, SwitchOffAll, SRDState.SwitchOffing);
- Transition(SRDState.SwitchOffing, FSM_MSG.TIMER, SwitchOffTimeout, SRDState.Init);
- // Home
- Transition(SRDState.Init, SRDMSG.HomeAll, HomeAll, SRDState.Homing);
- Transition(SRDState.Initialized, SRDMSG.HomeAll, HomeAll, SRDState.Homing);
- Transition(SRDState.Error, SRDMSG.HomeAll, HomeAll, SRDState.Homing);
- Transition(SRDState.Idle, SRDMSG.HomeAll, HomeAll, SRDState.Homing);
- Transition(SRDState.Abort, SRDMSG.HomeAll, HomeAll, SRDState.Homing);
- Transition(SRDState.Homing, FSM_MSG.TIMER, HomingTimeout, SRDState.Idle);
- //Initialize Home
- Transition(SRDState.Init, SRDMSG.InitializeHome, InitializeHome, SRDState.InitializeHoming);
- Transition(SRDState.Error, SRDMSG.InitializeHome, InitializeHome, SRDState.InitializeHoming);
- Transition(SRDState.InitializeHoming, FSM_MSG.TIMER, InitializeHomeTimeout, SRDState.Idle);
- Transition(SRDState.Abort, SRDMSG.InitializeHome, InitializeHome, SRDState.InitializeHoming);
- Transition(SRDState.Idle, SRDMSG.InitializeHome, InitializeHome, SRDState.InitializeHoming);
- //Process Recipe
- Transition(SRDState.Idle, SRDMSG.ProcessRecipe, ProcessRecipe, SRDState.ProcessReciping);
- Transition(SRDState.ProcessReciping, FSM_MSG.TIMER, ProcessRecipeTimeout, SRDState.Idle);
- Transition(SRDState.ProcessReciping, SRDMSG.ProcessError, ProcessError, SRDState.ProcessError);
- Transition(SRDState.ProcessError, FSM_MSG.TIMER, ProcessErrorMonitor, SRDState.Error);
- //GoToSavedPosition
- Transition(SRDState.Idle, SRDMSG.GoToSavedPosition, GotoPosition, SRDState.Positioning);
- Transition(SRDState.Positioning, FSM_MSG.TIMER, GotoPositionTimeout, SRDState.Idle);
- //StartRotation
- Transition(SRDState.Idle, SRDMSG.StartRotation, StartRotation, SRDState.Rotating);
- Transition(SRDState.Rotating, FSM_MSG.TIMER, RotationTimeout, SRDState.Idle);
- //StopRotation
- Transition(SRDState.Rotating, SRDMSG.StopRotation, StopRotation, SRDState.Stopping);
- Transition(SRDState.Stopping, FSM_MSG.TIMER, StopRotationTimeout, SRDState.Idle);
- //Abort
- Transition(SRDState.ProcessReciping, SRDMSG.Abort, AbortProcessRecipe, SRDState.Abort);
- Transition(SRDState.PresenceTesting, SRDMSG.Abort, AbortPresenceTest, SRDState.Abort);
- Transition(SRDState.AWCCycling, SRDMSG.Abort, AbortAWCCycle, SRDState.Abort);
- //PresenceTestStart
- Transition(SRDState.Idle, SRDMSG.PresenceTestStart, PresenceTest, SRDState.PresenceTesting);
- Transition(SRDState.PresenceTesting, FSM_MSG.TIMER, PresenceTestTimeout, SRDState.Idle);
- //AWC Cycle
- Transition(SRDState.Idle, SRDMSG.AWCCycleStart, AWCCycle, SRDState.AWCCycling);
- Transition(SRDState.AWCCycling, FSM_MSG.TIMER, AWCCycleTimeout, SRDState.Idle);
- Transition(SRDState.AWCCycling, SRDMSG.HomeAll, HomeAll, SRDState.AWCHoming);
- Transition(SRDState.AWCHoming, FSM_MSG.TIMER, HomingTimeout, SRDState.AWCCycling);
- //Retry
- Transition(SRDState.Error, SRDMSG.Retry, NullFunc, SRDState.Retrying);
- Transition(SRDState.Retrying, FSM_MSG.TIMER, SRDRetry, SRDState.Retrying);
- Transition(SRDState.Retrying, SRDMSG.ProcessRecipe, RetryRunRecipe, SRDState.ProcessReciping);
- //ConfirmComplete
- Transition(SRDState.Init, SRDMSG.ConfirmComplete, ClearModuleAlarm, SRDState.Init);
- Transition(SRDState.Idle, SRDMSG.ConfirmComplete, ClearModuleAlarm, SRDState.Idle);
- Transition(SRDState.Error, SRDMSG.ConfirmComplete, NullFunc, SRDState.ConfirmCompleting);
- Transition(SRDState.ConfirmCompleting, FSM_MSG.TIMER, ConfirmComplete, SRDState.ConfirmCompleting);
- Transition(SRDState.ConfirmCompleting, SRDMSG.ProcessRecipe, ConfirmProcessRecipe, SRDState.Idle);
- //Enter Init
- Transition(SRDState.Idle, SRDMSG.Init, NullFunc, SRDState.Init);
- EnumLoop<SRDState>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
- EnumLoop<SRDMSG>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
- }
- /// <summary>
- /// 初始化Routine
- /// </summary>
- private void InitialRoutine()
- {
- _initializeHomeRoutine = new SRDInitializeHomeRoutine(Module.ToString());
- _homeRoutine = new SRDHomeRoutine(Module.ToString());
- _switchOnRoutine = new SRDSwitchOnRoutine(Module.ToString());
- _switchOffRoutine = new SRDSwitchOffRoutine(Module.ToString());
- _initializeRoutine = new SRDInitializeRoutine(Module.ToString());
- _positionRoutine = new SRDPositionRoutine(Module);
- _rotationRoutine = new SRDRotationRoutine(Module, _rotationAxis);
- _presenceTestRoutine = new SRDPresenceTestRoutine(Module.ToString());
- _processRecipeRoutine = new SRDProcessRecipeRoutine(Module.ToString(), _rotationAxis, _armAxis, _srdCommon);
- _awcCycleRoutine = new SRDAWCCycleRoutine(Module);
- _processErrorRoutine=new SRDProcessErrorRoutine(Module.ToString());
- }
- /// <summary>
- /// 初始化操作
- /// </summary>
- private void InitialOperation()
- {
- OP.Subscribe($"{Module}.HomeAll", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.HomeAll); });
- OP.Subscribe($"{Module}.InitializeHome", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.InitializeHome); });
- OP.Subscribe($"{Module}.SwitchOnAll", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.SwitchOn); });
- OP.Subscribe($"{Module}.SwitchOffAll", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.SwitchOff); });
- OP.Subscribe($"{Module}.CycleManualProcessRecipe", (cmd, args) =>
- {
- SrdRecipe recipe = RecipeFileManager.Instance.LoadGenericityRecipe<SrdRecipe>(args[0].ToString());
- if (recipe == null)
- {
- LOG.WriteLog(eEvent.ERR_SRD, Module.ToString(), $"{args[0]} recipe is null");
- return false;
- }
- object[] objects = new object[args.Length];
- objects[0] = recipe;
- for (int i = 1; i < args.Length; i++)
- {
- objects[i] = args[i];
- }
- return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.ProcessRecipe, objects);
- });
- //OP.Subscribe($"{Module}.Arm.GotoSavedPosition", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.GoToSavedPosition, "Arm", args); });
- //OP.Subscribe($"{Module}.Rotation.GotoSavedPosition", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.GoToSavedPosition, "Rotation", args); });
- OP.Subscribe($"{Module}.Abort", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.Abort); });
- OP.Subscribe($"{Module}.StartRotation", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.StartRotation, "Rotation", args); });
- OP.Subscribe($"{Module}.StopRotation", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.StopRotation); });
- OP.Subscribe($"{Module}.PresenceTestStart", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.PresenceTestStart, args); });
- OP.Subscribe($"{Module}.AWCCycle", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.AWCCycleStart, args); });
- }
- /// <summary>
- /// Enter Init
- /// </summary>
- public void EnterInit()
- {
- if ((SRDState)fsm.State != SRDState.Idle) return;
- else
- {
- CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.Init);
- }
- }
- /// <summary>
- /// 进入Error状态
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool EnterError(object[] param)
- {
- _isHomed = false;
- return true;
- }
- #region Initialized
- /// <summary>
- /// Initialize
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool InitializeAll(object[] param)
- {
- if (fsm.State == (int)MetalState.Initializing)
- {
- LOG.WriteLog(eEvent.WARN_SRD, Module.ToString(), "state is Initializing,cannot do initialize");
- return false;
- }
- return _initializeRoutine.Start() == RState.Running;
- }
- /// <summary>
- /// Initialize 监控
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool InitializeAllTimeout(object[] param)
- {
- RState ret = _initializeRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- PostMsg(SRDMSG.Error);
- return false;
- }
- bool result = ret == RState.End;
- if (result)
- {
- _isHomed = false;
- }
- return result;
- }
- #endregion
- #region Switch On
- /// <summary>
- /// SwitchAll
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool SwitchOnAll(object[] param)
- {
- return _switchOnRoutine.Start() == RState.Running;
- }
- private bool SwitchOnTimeout(object[] param)
- {
- RState ret = _switchOnRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- PostMsg(SRDMSG.Error);
- return false;
- }
- bool result = ret == RState.End;
- if (result)
- {
- _isHomed = false;
- }
- return result;
- }
- #endregion
- #region Switch Off
- /// <summary>
- /// SwitchAll
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool SwitchOffAll(object[] param)
- {
- return _switchOffRoutine.Start() == RState.Running;
- }
- private bool SwitchOffTimeout(object[] param)
- {
- RState ret = _switchOffRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- PostMsg(SRDMSG.Error);
- return false;
- }
- bool result = ret == RState.End;
- if (result)
- {
- _isHomed = false;
- }
- return result;
- }
- #endregion
- #region Home
- /// <summary>
- /// HomeAll
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool HomeAll(object[] param)
- {
- _isHomed = false;
- return _homeRoutine.Start() == RState.Running;
- }
- /// <summary>
- /// Home超时
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool HomingTimeout(object[] param)
- {
- RState ret = _homeRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- PostMsg(SRDMSG.Error);
- return false;
- }
- bool result = ret == RState.End;
- if (result)
- {
- _isHomed = true;
- }
- return result;
- }
- #endregion
- #region Process Recipe
- /// <summary>
- /// ProcessRecipe
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool ProcessRecipe(object[] param)
- {
- SrdRecipe recipe= param[0] as SrdRecipe;
- if(param.Length >= 2) _cycle = (int)param[1];
- bool result = _processRecipeRoutine.Start(param) == RState.Running;
- if (result)
- {
- if (CellItemRecipeTimeManager.Instance.ContainRecipe(recipe.Ppid))
- {
- _recipeTime = _cycle * CellItemRecipeTimeManager.Instance.GetRecipeTotalTime(recipe.Ppid);
- }
- else
- {
- _recipeTime = 0;
- }
- _currentRecipe = recipe;
- _runRecipeStartTime = DateTime.Now;
- FaModuleNotifier.Instance.NotifySRDRecipeStart(Module, recipe.Ppid);
- }
- return result;
- }
- /// <summary>
- /// ProcessRecipe超时
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool ProcessRecipeTimeout(object[] param)
- {
- RState ret = _processRecipeRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- PostMsg(SRDMSG.ProcessError);
- //记录LotTrack
- _runRecipeCompleteTime = DateTime.Now;
- _processRecipeRoutine.SRDLotTrackHeaderDatas.ProcessTime = (_runRecipeCompleteTime - _runRecipeStartTime).TotalSeconds.ToString("F2");
- SRDLotTrackUtil.ExportSRDLotTrack(Module.ToString(), _processRecipeRoutine.SRDLotTrackDatas,
- _processRecipeRoutine.SRDLotTrackHeaderDatas, IsAuto);
- if (Singleton<RouteManager>.Instance.IsAutoRunning)
- {
- AlarmList alarmList = new AlarmList(Module.ToString(), ((SRDState)fsm.State).ToString(), (int)SRDMSG.ProcessRecipe,
- _processRecipeRoutine.ErrorMsg, _processRecipeRoutine.ErrorStep, (int)AlarmType.Error);
- AlarmListManager.Instance.AddAlarm(alarmList);
- }
- if (_currentRecipe != null)
- {
- FaModuleNotifier.Instance.NotifySRDRecipeFailed(Module, _currentRecipe.Ppid);
- }
- return false;
- }
- bool result = ret == RState.End;
- if (result)
- {
- double elapsedMilliseconds = _processRecipeRoutine.ElapsedMilliseconds;
- int recipeTime = (int)Math.Floor(elapsedMilliseconds / _cycle / 1000);
- CellItemRecipeTimeManager.Instance.UpdateRecipeTime(_currentRecipe.Ppid, recipeTime);
- //记录LotTrack
- _runRecipeCompleteTime = DateTime.Now;
- _processRecipeRoutine.SRDLotTrackHeaderDatas.ProcessTime = (_runRecipeCompleteTime - _runRecipeStartTime).TotalSeconds.ToString("F2");
- SRDLotTrackUtil.ExportSRDLotTrack(Module.ToString(), _processRecipeRoutine.SRDLotTrackDatas,
- _processRecipeRoutine.SRDLotTrackHeaderDatas, IsAuto);
- if (_currentRecipe != null)
- {
- FaModuleNotifier.Instance.NotifySRDRecipeEnd(Module, _currentRecipe.Ppid);
- }
- _currentRecipe = null;
- AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), SRDState.ProcessReciping.ToString());
- }
- return result;
- }
- /// <summary>
- /// Abort Recipe
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool AbortProcessRecipe(object[] param)
- {
- _processRecipeRoutine.Abort();
- //记录LotTrack
- _runRecipeCompleteTime = DateTime.Now;
- _processRecipeRoutine.SRDLotTrackHeaderDatas.ProcessTime = (_runRecipeCompleteTime - _runRecipeStartTime).TotalSeconds.ToString("F2");
- SRDLotTrackUtil.ExportSRDLotTrack(Module.ToString(), _processRecipeRoutine.SRDLotTrackDatas,
- _processRecipeRoutine.SRDLotTrackHeaderDatas, IsAuto);
- return true;
- }
- /// <summary>
- /// 计算剩余时间
- /// </summary>
- /// <returns></returns>
- private double CalculateTimeRemain()
- {
- if (IsBusy)
- {
- return _recipeTime != 0 ? (_recipeTime - Math.Floor((double)_processRecipeRoutine.ElapsedMilliseconds / 1000)) : 0;
- }
- else
- {
- return 0;
- }
- }
- /// <summary>
- /// ProcessError
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool ProcessError(object[] param)
- {
- return _processErrorRoutine.Start(param)==RState.Running;
- }
- /// <summary>
- /// Process Error监控
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool ProcessErrorMonitor(object[] param)
- {
- RState state = _processErrorRoutine.Monitor();
- if (state == RState.End||state==RState.Failed||state==RState.Timeout)
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// Retry RunRecipe
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool RetryRunRecipe(object[] param)
- {
- int stepIndex = (int)param[0];
- bool result = _processRecipeRoutine.Retry(stepIndex) == RState.Running;
- if (result)
- {
- if (_currentRecipe != null)
- {
- if (CellItemRecipeTimeManager.Instance.ContainRecipe(_currentRecipe.Ppid))
- {
- _recipeTime = _cycle * CellItemRecipeTimeManager.Instance.GetRecipeTotalTime(_currentRecipe.Ppid);
- }
- else
- {
- _recipeTime = 0;
- }
- _runRecipeStartTime = DateTime.Now;
- }
- }
- return result;
- }
- /// <summary>
- /// 确认ProcessRecipe是否完成
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool ConfirmProcessRecipe(object[] param)
- {
- int stepIdex = (int)param[0];
- bool result = _processRecipeRoutine.CheckCompleteCondition(stepIdex);
- if (!result)
- {
- if (Singleton<RouteManager>.Instance.IsAutoRunning)
- {
- AlarmList alarmList = new AlarmList(Module.ToString(), ((SRDState)fsm.State).ToString(), (int)SRDMSG.ProcessRecipe,
- _processRecipeRoutine.ErrorMsg, _processRecipeRoutine.ErrorStep, (int)AlarmType.Error);
- AlarmListManager.Instance.AddAlarm(alarmList);
- }
- PostMsg(SRDMSG.Error);
- }
- else
- {
- if (Singleton<RouteManager>.Instance.IsAutoRunning)
- {
- AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), SRDState.ProcessReciping.ToString());
- }
- }
- return result;
- }
- #endregion
- #region AWC Cycle
- /// <summary>
- /// AWC Cycle
- /// </summary>
- /// <returns></returns>
- private bool AWCCycle(object[] param)
- {
- return _awcCycleRoutine.Start(param) == RState.Running;
- }
- /// <summary>
- /// AWC Cycle超时
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool AWCCycleTimeout(object[] param)
- {
- RState ret = _awcCycleRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- _isAWCCycling = false;
- PostMsg(SRDMSG.Error);
- return false;
- }
- //设置IsPresenceTesting
- if (ret == RState.Running)
- {
- _isAWCCycling = true;
- }
- else
- {
- _isAWCCycling = false;
- }
- return ret == RState.End;
- }
- /// <summary>
- /// Abort AWC Cycle
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool AbortAWCCycle(object[] param)
- {
- _awcCycleRoutine.Abort();
- return true;
- }
- #endregion
- #region InitializeHome
- /// <summary>
- /// InitializeHome
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool InitializeHome(object[] param)
- {
- _isHomed = false;
- return _initializeHomeRoutine.Start() == RState.Running;
- }
- /// <summary>
- /// InitializeHome超时
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool InitializeHomeTimeout(object[] param)
- {
- RState ret = _initializeHomeRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- PostMsg(SRDMSG.Error);
- return false;
- }
- bool result = ret == RState.End;
- if (result)
- {
- _isHomed = true;
- }
- return result;
- }
- #endregion
- #region RunRecipeRetry
- /// <summary>
- /// Retry
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool SRDRetry(object[] param)
- {
- AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
- if (alarmList != null)
- {
- CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), alarmList.ModuleCmd,
- alarmList.ModuleStep);
- }
- return false;
- }
- #endregion
- #region ConfirmComplete
- /// <summary>
- /// 确认是否完成
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool ConfirmComplete(object[] param)
- {
- AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
- if (alarmList != null)
- {
- if (alarmList.ModuleState == SRDState.ProcessReciping.ToString())
- {
- CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.ProcessRecipe, alarmList.ModuleStep);
- }
- else
- {
- PostMsg(SRDState.Error);
- }
- }
- return false;
- }
- /// <summary>
- /// 清除报警
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool ClearModuleAlarm(object[] param)
- {
- AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
- if (alarmList != null)
- {
- AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), "");
- }
- return true;
- }
- #endregion
- public bool Check(int msg, out string reason, params object[] args)
- {
- reason = "";
- return false;
- }
- public bool CheckAcked(int msg)
- {
- return false;
- }
- public int Invoke(string function, params object[] args)
- {
- switch (function)
- {
- case "HomeAll":
- if (IsIdle)
- {
- return (int)FSM_MSG.NONE;
- }
- if (CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.InitializeHome))
- {
- return (int)SRDMSG.Initialize;
- }
- else
- {
- return (int)FSM_MSG.NONE;
- }
- case "Retry":
- if (CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.Retry, args))
- {
- return (int)SRDMSG.Retry;
- }
- else
- {
- return (int)FSM_MSG.NONE;
- }
- case "ConfirmComplete":
- if (CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.ConfirmComplete, args))
- {
- return (int)SRDMSG.ConfirmComplete;
- }
- else
- {
- return (int)FSM_MSG.NONE;
- }
- }
- return (int)FSM_MSG.NONE;
- }
- #region GoToPosition
- /// <summary>
- /// Go to Position
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool GotoPosition(object[] param)
- {
- string axis = param[0].ToString();
- object[] objs = (object[])param[1];
- string position = objs[1].ToString();
- var result = CheckGotoPositionPreCondition(axis, position);
- if (result.result)
- {
- return _positionRoutine.Start(result.axis, position) == RState.Running;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 检验GotoPosition前置条件
- /// </summary>
- /// <param name="axis"></param>
- /// <param name="position"></param>
- /// <returns></returns>
- private (bool result, JetAxisBase axis) CheckGotoPositionPreCondition(string axis, string position)
- {
- switch (axis)
- {
- case "Rotation":
- return (_rotationAxis.CheckGotoPosition(position), _rotationAxis);
- case "Arm":
- return (_armAxis.CheckGotoPosition(position), _armAxis);
- default:
- return (false, null);
- }
- }
- /// <summary>
- /// GotoPosition超时
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool GotoPositionTimeout(object[] param)
- {
- RState ret = _positionRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- return true;
- }
- return ret == RState.End;
- }
- #endregion
- #region 旋转
- /// <summary>
- /// 开始旋转
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool StartRotation(object[] param)
- {
- string axis = param[0].ToString();
- object[] objs = (object[])param[1];
- double time = double.Parse(objs[0].ToString());
- double speed = double.Parse(objs[1].ToString());
- return _rotationRoutine.Start(_rotationAxis, time, speed) == RState.Running;
- }
- /// <summary>
- /// RotationTimeout
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool RotationTimeout(object[] param)
- {
- RState ret = _rotationRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- //PostMsg(SRDMSG.Error);
- return true;
- }
- return ret == RState.End;
- }
- /// <summary>
- /// 停止旋转
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool StopRotation(object[] param)
- {
- _rotationAxis.StopPositionOperation();
- return _rotationAxis.Status == RState.Running;
- }
- /// <summary>
- /// 停止旋转监控
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool StopRotationTimeout(object[] param)
- {
- RState ret = _rotationAxis.Status;
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- //PostMsg(SRDMSG.Error);
- return true;
- }
- return ret == RState.End;
- }
- #endregion
- #region PresenceTest
- private bool PresenceTest(object[] param)
- {
- _recipeTime = 0;
- return _presenceTestRoutine.Start(param) == RState.Running;
- }
- private bool PresenceTestTimeout(object[] param)
- {
- RState ret = _presenceTestRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- _isPresenceTesting = false;
- PostMsg(SRDMSG.Error);
- return false;
- }
- //设置IsPresenceTesting
- if (ret == RState.Running)
- {
- _isPresenceTesting = true;
- }
- else
- {
- _isPresenceTesting = false;
- }
- return ret == RState.End;
- }
- /// <summary>
- /// Abort PresenceTest
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool AbortPresenceTest(object[] param)
- {
- _presenceTestRoutine.Abort();
- return true;
- }
- #endregion
- /// <summary>
- /// 获取当前子状态机
- /// </summary>
- private string GetCurrentStateMachine()
- {
- string state = "";
- switch ((SRDState)fsm.State)
- {
- case SRDState.Init:
- state = "Init";
- break;
- case SRDState.Initializing:
- state = _initializeRoutine.CurrentStateMachine;
- break;
- case SRDState.Homing:
- state = _homeRoutine.CurrentStateMachine;
- break;
- case SRDState.SwitchOning:
- state = _switchOnRoutine.CurrentStateMachine;
- break;
- case SRDState.SwitchOffing:
- state = _switchOffRoutine.CurrentStateMachine;
- break;
- case SRDState.Positioning:
- state = _positionRoutine.CurrentStateMachine;
- break;
- case SRDState.Rotating:
- state = _rotationRoutine.CurrentStateMachine;
- break;
- case SRDState.PresenceTesting:
- state = _presenceTestRoutine.CurrentStateMachine;
- break;
- case SRDState.ProcessReciping:
- state = _processRecipeRoutine.CurrentStateMachine;
- break;
- case SRDState.AWCCycling:
- state = _awcCycleRoutine.CurrentStateMachine;
- break;
- default:
- state = Enum.GetName(typeof(SRDState),fsm.State);
- break;
- }
- return state;
- }
- /// <summary>
- /// 设置IsAWCCycling
- /// </summary>
- /// <param name="flag"></param>
- public void SetIsAWCCycling(bool flag)
- {
- _isAWCCycling = flag;
- }
- }
- public enum SRDMSG
- {
- Initialize,
- InitializeHome,
- ProcessRecipe,
- ResumeError,
- SwitchOn,
- SwitchOff,
- HomeAll,
- Error,
- GoToSavedPosition,
- Abort,
- StartRotation,
- StopRotation,
- PresenceTestStart,
- PresenceTestStop,
- AWCCycleStart,
- Init,
- ProcessError,
- Retry,
- ConfirmComplete
- }
- }
|