123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Fsm;
- using Aitex.Core.RT.Log;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using Venus_Core;
- using Venus_RT.Devices;
- using Venus_RT.Devices.PreAligner;
- using Venus_RT.Devices.VCE;
- using Venus_RT.Modules.PMs;
- namespace Venus_RT.Modules.TM.VenusEntity
- {
- public class SETMEntity : Entity, IModuleEntity
- {
- public enum STATE
- {
- Unknown,
- Init,
- Initializing,
- InitializingRB,
- Idle,
- Error,
- Pumping,
- Venting,
- Purging,
- Leakchecking,
- Picking,
- Placing,
- Swaping,
- PMPicking,
- PMPlacing,
- PMSwaping,
- Aligning,
- Mapping,
- Extending,
- Retracting,
- Swapping,
- Gotoing,
- ControllingPressure
- }
- public enum MSG
- {
- Home,
- RobotHome,
- Online,
- Offline,
- Pump,
- Vent,
- Purge,
- CyclePurge,
- LeakCheck,
- Pick,
- Place,
- Swap,
- DoublePick,
- DoublePlace,
- DoubleSwap,
- PMPick,
- PMPlace,
- PMSwap,
- Extend,
- Retract,
- TMCycle,
- ControlPressure,
- Error,
- Abort,
- AbortControlPressure
- }
- #region 公开变量
- public bool IsIdle
- {
- get { return fsm.State == (int)STATE.Idle; }
- }
- public bool IsError
- {
- get { return fsm.State == (int)STATE.Error; }
- }
- public bool IsInit
- {
- get { return fsm.State == (int)STATE.Unknown || fsm.State == (int)STATE.Init; }
- }
- public bool IsBusy
- {
- get { return !IsInit && !IsError && !IsIdle; }
- }
- public RState RobotStatus
- {
- get
- {
- if (_robot.Status != RState.Running)
- {
- if (_robotWatch.ElapsedMilliseconds < 100)
- return RState.Running;
- else
- return _robot.Status;
- }
- else
- return RState.Running;
- }
- }
- public bool IsOnline { get; internal set; }
- //public bool IsTMVac => _tm.IsTMVac;
- //public bool IsTMATM => _tm.IsTMATM;
- #endregion
- #region 私有变量
- private readonly HongHuTM _tm;
- private readonly ITransferRobot _robot;
- private readonly IPreAlign _vpa;
- private readonly SEMFHomeRoutine _homeRoutine;
- private readonly SEMFPickRoutine _pickRoutine;
- private readonly SEMFPlaceRoutine _placeRoutine;
- //private readonly
- private readonly Stopwatch _robotWatch = new Stopwatch();
- #endregion
-
- public SETMEntity()
- {
- _tm = DEVICE.GetDevice<HongHuTM>("TM");
- _robot = new HongHuVR();
- _vpa = new HongHuVPA(ModuleName.VPA);
- _robotWatch = new Stopwatch();
- _homeRoutine = new SEMFHomeRoutine(_tm,_robot, _vpa);
- _pickRoutine = new SEMFPickRoutine(_tm,_robot, _vpa);
- _placeRoutine = new SEMFPlaceRoutine(_tm, _robot, _vpa);
- //routine
- //wafermanager
- WaferManager.Instance.SubscribeLocation(ModuleName.TMRobot,2);
- WaferManager.Instance.SubscribeLocation(ModuleName.VPA,1);
- InitFsmMap();
- }
- private void InitFsmMap()
- {
- fsm = new StateMachine<SETMEntity>("SETM", (int)STATE.Init, 50);
- AnyStateTransition(MSG.Error, fnError, STATE.Error);
- AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
- AnyStateTransition(MSG.Offline, fnOffline, FSM_STATE.SAME);
- AnyStateTransition(MSG.Home, fnHome, STATE.Initializing);
- //Home
- Transition(STATE.Initializing, FSM_MSG.TIMER, fnHomeTimeout, STATE.Idle);
- Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
- //Pick
- Transition(STATE.Idle, MSG.Pick, fnStartPick, STATE.Picking);
- Transition(STATE.Picking, FSM_MSG.TIMER, fnPickTimeout, STATE.Idle);
- Transition(STATE.Picking, MSG.Abort, fnAbortPick, STATE.Idle);
- //Place
- Transition(STATE.Idle, MSG.Place, fnStartPlace, STATE.Placing);
- Transition(STATE.Placing, FSM_MSG.TIMER, fnPlaceTimeout, STATE.Idle);
- Transition(STATE.Placing, MSG.Abort, fnAbortPlace, STATE.Idle);
- //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
- //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
- //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
- //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
- //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
- //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
- //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
- //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
- //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
- Running = true;
- }
- protected override bool Init()
- {
- return true;
- }
- private bool fnAbortPlace(object[] param)
- {
- return true;
- }
- private bool fnPlaceTimeout(object[] param)
- {
- RState ret = _placeRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- PostMsg(MSG.Error);
- return false;
- }
- return ret == RState.End;
- }
- private bool fnStartPlace(object[] param)
- {
- return _placeRoutine.Start(param) == RState.Running;
- }
- private bool fnAbortPick(object[] param)
- {
- _pickRoutine.Abort();
- return true;
- }
- private bool fnStartPick(object[] param)
- {
- return _pickRoutine.Start(param) == RState.Running;
- }
- private bool fnPickTimeout(object[] param)
- {
- RState ret = _pickRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- PostMsg(MSG.Error);
- return false;
- }
- return ret == RState.End;
- }
- private bool fnAbortHome(object[] param)
- {
- _homeRoutine.Abort();
- return true;
- }
- private bool fnHome(object[] param)
- {
- if (fsm.State == (int)STATE.Init && param.Length > 0)//带参home
- {
- return false;
- }
- else
- return _homeRoutine.Start(param) == RState.Running;
- }
- private bool fnHomeTimeout(object[] param)
- {
- RState ret = _homeRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- PostMsg(MSG.Error);
- return false;
- }
- return ret == RState.End;
- }
- private bool fnOffline(object[] param)
- {
- throw new NotImplementedException();
- }
- private bool fnOnline(object[] param)
- {
- throw new NotImplementedException();
- }
- private bool fnError(object[] param)
- {
- return true;
- }
- public bool Check(int msg, out string reason, params object[] args)
- {
- reason = "";
- return true;
- }
- public bool CheckAcked(int msg)
- {
- return fsm.CheckExecuted(msg);
- }
- public bool CheckToPostMessage(int msg, params object[] args)
- {
- if (!fsm.FindTransition(fsm.State, msg))
- {
- LOG.Write(eEvent.WARN_FSM_WARN, ModuleName.TM, $"TM is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
- return false;
- }
- Running = true;
- fsm.PostMsg(msg, args);
- return true;
- }
- public int Invoke(string function, params object[] args)
- {
- switch (function)
- {
- case "Home":
- CheckToPostMessage((int)MSG.Home);
- return (int)MSG.Home;
- }
- return (int)FSM_MSG.NONE;
- }
- }
- }
|