123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Fsm;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Utilities;
- using MECF.Framework.Common.Beckhoff.AxisProvider;
- using MECF.Framework.Common.Utilities;
- using CyberX8_Core;
- using CyberX8_RT.Devices.AXIS;
- using CyberX8_RT.Devices.SRD;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace CyberX8_RT.Modules.SRD
- {
- internal class UnloadingStateMachine : Entity, IEntity
- {
- #region 常量
- /// <summary>
- /// Arm Home最大retry次数
- /// </summary>
- private const int MAX_ARM_HOME_RETRIES = 3;
- /// <summary>
- /// Rotation Home最大retry次数
- /// </summary>
- private const int MAX_ROTATION_HOME_RETRIES = 3;
- /// <summary>
- /// 旋转增加时长
- /// </summary>
- private const int ROTATION_PLUS_TIME = 10;
- #endregion
- #region 内部变量
- /// <summary>
- /// 模块名称
- /// </summary>
- private string _module;
- /// <summary>
- /// SRD Common
- /// </summary>
- private SrdCommonDevice _srdCommon;
- /// <summary>
- /// Arm Axis
- /// </summary>
- private JetAxisBase _armAxis;
- /// <summary>
- /// Rotation Axis
- /// </summary>
- private JetAxisBase _rotationAxis;
- /// <summary>
- /// Arm重试次数
- /// </summary>
- private int _armRetryTimes = 0;
- /// <summary>
- /// Rotation重试次数
- /// </summary>
- private int _rotationRetryTimes = 0;
- /// <summary>
- /// ARM正在执行Home
- /// </summary>
- private bool _armHoming = false;
- /// <summary>
- /// Rotation正在执行Home
- /// </summary>
- private bool _rotationHoming = false;
- #endregion
- #region 属性
- /// <summary>
- /// 状态
- /// </summary>
- public string State { get { return ((UnloadingState)fsm.State).ToString(); } }
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public UnloadingStateMachine(string module)
- {
- _module = module;
- this.fsm = new StateMachine($"{module}_UnloadingStateMachine", (int)UnloadingState.Unloading_Complete, 10);
- fsm.EnableRepeatedMsg(true);
-
- AnyStateTransition(UnloadingMsg.Init, EnterUnloadingStart, UnloadingState.Unloading_Start);
- AnyStateTransition(UnloadingMsg.Error, EnterError, UnloadingState.Error);
- //Transition(UnloadingState.Unloading_Complete, UnloadingMsg.Unloading_Start, EnterUnloadingStart, UnloadingState.Unloading_Start);
- Transition(UnloadingState.Unloading_Start, UnloadingMsg.Unloading_Start, UnloadingCheckStatus, UnloadingState.Unloading_CheckRotationStopped);
- Transition(UnloadingState.Unloading_CheckRotationStopped, FSM_MSG.TIMER, CheckRotationStopped, UnloadingState.Unloading_WaferPresent);
- Transition(UnloadingState.Unloading_WaferPresent, FSM_MSG.TIMER, CheckWaferPresent, UnloadingState.Unloading_OpenDoor);
- Transition(UnloadingState.Unloading_OpenDoor, FSM_MSG.TIMER, OpenDoor, UnloadingState.Unloading_CheckDoorOpened);
- Transition(UnloadingState.Unloading_CheckDoorOpened, FSM_MSG.TIMER, CheckDoorOpened, UnloadingState.Unloading_ReleaseChuckVacuum);
- Transition(UnloadingState.Unloading_ReleaseChuckVacuum, FSM_MSG.TIMER, ReleaseChuckVacuum, UnloadingState.Unloading_CheckVacuum);
- Transition(UnloadingState.Unloading_CheckVacuum, FSM_MSG.TIMER, CheckVacuum, UnloadingState.Unloading_Complete);
- EnumLoop<UnloadingState>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
- EnumLoop<UnloadingMsg>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
- }
- /// <summary>
- /// Enter Error
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool EnterError(object param)
- {
-
- return true;
- }
- /// <summary>
- /// Enter Unloading_Start
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool EnterUnloadingStart(object param)
- {
- return true;
- }
- #region 状态方法
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool UnloadingCheckStatus(object param)
- {
-
- _armAxis = DEVICE.GetDevice<JetAxisBase>($"{_module}.Arm");
- _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{_module}.Rotation");
- _srdCommon = DEVICE.GetDevice<SrdCommonDevice>($"{_module}.Common");
- return true;
- }
- /// <summary>
- /// 检查Rotation与Arm是否home
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool CheckRotationStopped(object param)
- {
- CheckArmHome();
- CheckRotationHome();
- return _srdCommon.Status == RState.End;
- }
- /// <summary>
- /// 检验Arm home,发现失败则重试
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool CheckArmHome()
- {
- if (_armAxis.IsHomed)
- {
- return true;
- }
- else
- {
- if (_armRetryTimes < MAX_ARM_HOME_RETRIES)
- {
- if (!_armHoming)
- {
- LOG.WriteLog(eEvent.INFO_SRD, _module, $"Arm Home Retry Home {_armRetryTimes + 1} times");
- bool result = _armAxis.Home(false);
- if (result)
- {
- _armHoming = true;
- }
- _armRetryTimes++;
- return false;
- }
- else
- {
- if (_armAxis.IsHomed && _armAxis.Status == RState.End)
- {
- _armRetryTimes = 0;
- _armHoming = false;
- return true;
- }
- return false;
- }
- }
- else
- {
- LOG.WriteLog(eEvent.ERR_SRD, _module, $"Arm Home Retry Home {_armRetryTimes + 1} times is over {MAX_ARM_HOME_RETRIES}");
- PostMsg(UnloadingMsg.Error);
- return false;
- }
- }
- }
- /// <summary>
- /// 检验Rotation home,发现失败则重试
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool CheckRotationHome()
- {
- if (_rotationAxis.IsHomed)
- {
- return true;
- }
- else
- {
- if (_rotationRetryTimes < MAX_ROTATION_HOME_RETRIES)
- {
- if (!_rotationHoming)
- {
- LOG.WriteLog(eEvent.INFO_SRD, _module, $"Rotation Home Retry Home {_rotationRetryTimes + 1} times");
- bool result = _rotationAxis.Home(false);
- if (result)
- {
- _rotationHoming = true;
- }
- _rotationRetryTimes++;
- return false;
- }
- else
- {
- if (_rotationAxis.IsHomed && _rotationAxis.Status == RState.End)
- {
- _rotationRetryTimes = 0;
- _rotationHoming = false;
- return true;
- }
- return false;
- }
- }
- else
- {
- LOG.WriteLog(eEvent.ERR_SRD, _module, $"Rotation Home Retry Home {_rotationRetryTimes + 1} times is over {MAX_ROTATION_HOME_RETRIES}");
- PostMsg(UnloadingMsg.Error);
- return false;
- }
- }
- }
- /// <summary>
- /// Check Wafer Present
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool CheckWaferPresent(object param)
- {
- if (_srdCommon.IsWaferPresence)
- {
- if (_srdCommon.WaferPresence != "WellPlaced")
- {
- PostMsg(UnloadingMsg.Error);
- LOG.WriteLog(eEvent.ERR_SRD, _module, "Wafer Presence is not WellPlaced");
- return false;
- }
- }
- else
- {
- LOG.WriteLog(eEvent.INFO_SRD, _module, "CheckWaferPresent has been ignored");
-
- }
- return true;
- }
- /// <summary>
- /// Open Door
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool OpenDoor(object param)
- {
- bool result = _srdCommon.DoorOpenAction("", null);
- if (!result)
- {
- PostMsg(UnloadingMsg.Error);
- }
- return result;
- }
- /// <summary>
- /// 检验DoorOpened
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool CheckDoorOpened(object param)
- {
- if (_srdCommon.Status == RState.Failed || _srdCommon.Status == RState.Timeout)
- {
- PostMsg(UnloadingMsg.Error);
- return false;
- }
- return _srdCommon.Status == RState.End && _srdCommon.CommonData.DoorOpened;
- }
- /// <summary>
- /// 关闭Chuck Vacuum,并检查Vacuum Level
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool ReleaseChuckVacuum(object param)
- {
- if (_srdCommon.IsWaferPresence)
- {
- bool result = _srdCommon.ChuckVacuumOffAction("", null);
- if (!result)
- {
- PostMsg(UnloadingMsg.Error);
- }
- return result;
- }
- else
- {
- LOG.WriteLog(eEvent.INFO_SRD, _module, "ReleaseChuckVacuum has been ignored");
- return true;
- }
- }
- /// <summary>
- /// 检查真空状态
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool CheckVacuum(object param)
- {
- if (_srdCommon.IsWaferPresence)
- {
- if (_srdCommon.Status == RState.Failed || _srdCommon.Status == RState.Timeout)
- {
- PostMsg(UnloadingMsg.Error);
- return false;
- }
- bool result = _srdCommon.Status == RState.End && _srdCommon.CommonData.ChuckVacuum;
- return result;
- }
- else
- {
- LOG.WriteLog(eEvent.INFO_SRD, _module, "CheckVacuum has been ignored");
- return true;
- }
-
- }
- #endregion
- /// <summary>
- /// 停止
- /// </summary>
- public void Stop()
- {
-
- base.Terminate();
-
- }
-
- public bool Check(int msg, out string reason, params object[] args)
- {
- reason = "";
- return false;
- }
- #region State Msg枚举
- public enum UnloadingState
- {
- None,
- Error,
- Unloading_Start,
- Unloading_Complete,
- Unloading_CheckRotationStopped,
- Unloading_WaferPresent,
- Unloading_OpenDoor,
- Unloading_CheckDoorOpened,
- Unloading_ReleaseChuckVacuum,
- Unloading_CheckVacuum
-
- }
- public enum UnloadingMsg
- {
- Init,
- Error,
- Unloading_Start,
- Unloading_Complete,
- CheckRoationStopped,
- WaferPresent,
- OpenDoor,
- ReleaseChuckVacuum,
- Abort
- }
- #endregion
- }
- }
|