SETMEntity.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Fsm;
  3. using Aitex.Core.RT.Log;
  4. using MECF.Framework.Common.Equipment;
  5. using MECF.Framework.Common.SubstrateTrackings;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using Venus_Core;
  14. using Venus_RT.Devices;
  15. using Venus_RT.Devices.PreAligner;
  16. using Venus_RT.Devices.VCE;
  17. using Venus_RT.Modules.PMs;
  18. namespace Venus_RT.Modules.TM.VenusEntity
  19. {
  20. public class SETMEntity : Entity, IModuleEntity
  21. {
  22. public enum STATE
  23. {
  24. Unknown,
  25. Init,
  26. Initializing,
  27. InitializingRB,
  28. Idle,
  29. Error,
  30. Pumping,
  31. Venting,
  32. Purging,
  33. Leakchecking,
  34. Picking,
  35. Placing,
  36. Swaping,
  37. PMPicking,
  38. PMPlacing,
  39. PMSwaping,
  40. Aligning,
  41. Mapping,
  42. Extending,
  43. Retracting,
  44. Swapping,
  45. Gotoing,
  46. ControllingPressure
  47. }
  48. public enum MSG
  49. {
  50. Home,
  51. RobotHome,
  52. Online,
  53. Offline,
  54. Pump,
  55. Vent,
  56. Purge,
  57. CyclePurge,
  58. LeakCheck,
  59. Pick,
  60. Place,
  61. Swap,
  62. DoublePick,
  63. DoublePlace,
  64. DoubleSwap,
  65. PMPick,
  66. PMPlace,
  67. PMSwap,
  68. Extend,
  69. Retract,
  70. TMCycle,
  71. ControlPressure,
  72. Error,
  73. Abort,
  74. AbortControlPressure
  75. }
  76. #region 公开变量
  77. public bool IsIdle
  78. {
  79. get { return fsm.State == (int)STATE.Idle; }
  80. }
  81. public bool IsError
  82. {
  83. get { return fsm.State == (int)STATE.Error; }
  84. }
  85. public bool IsInit
  86. {
  87. get { return fsm.State == (int)STATE.Unknown || fsm.State == (int)STATE.Init; }
  88. }
  89. public bool IsBusy
  90. {
  91. get { return !IsInit && !IsError && !IsIdle; }
  92. }
  93. public RState RobotStatus
  94. {
  95. get
  96. {
  97. if (_robot.Status != RState.Running)
  98. {
  99. if (_robotWatch.ElapsedMilliseconds < 100)
  100. return RState.Running;
  101. else
  102. return _robot.Status;
  103. }
  104. else
  105. return RState.Running;
  106. }
  107. }
  108. public bool IsOnline { get; internal set; }
  109. //public bool IsTMVac => _tm.IsTMVac;
  110. //public bool IsTMATM => _tm.IsTMATM;
  111. #endregion
  112. #region 私有变量
  113. private readonly HongHuTM _tm;
  114. private readonly ITransferRobot _robot;
  115. private readonly IPreAlign _vpa;
  116. private readonly SEMFHomeRoutine _homeRoutine;
  117. private readonly SEMFPickRoutine _pickRoutine;
  118. private readonly SEMFPlaceRoutine _placeRoutine;
  119. //private readonly
  120. private readonly Stopwatch _robotWatch = new Stopwatch();
  121. #endregion
  122. public SETMEntity()
  123. {
  124. _tm = DEVICE.GetDevice<HongHuTM>("TM");
  125. _robot = new HongHuVR();
  126. _vpa = new HongHuVPA(ModuleName.VPA);
  127. _robotWatch = new Stopwatch();
  128. _homeRoutine = new SEMFHomeRoutine(_tm,_robot, _vpa);
  129. _pickRoutine = new SEMFPickRoutine(_tm,_robot, _vpa);
  130. _placeRoutine = new SEMFPlaceRoutine(_tm, _robot, _vpa);
  131. //routine
  132. //wafermanager
  133. WaferManager.Instance.SubscribeLocation(ModuleName.TMRobot,2);
  134. WaferManager.Instance.SubscribeLocation(ModuleName.VPA,1);
  135. InitFsmMap();
  136. }
  137. private void InitFsmMap()
  138. {
  139. fsm = new StateMachine<SETMEntity>("SETM", (int)STATE.Init, 50);
  140. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  141. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  142. AnyStateTransition(MSG.Offline, fnOffline, FSM_STATE.SAME);
  143. AnyStateTransition(MSG.Home, fnHome, STATE.Initializing);
  144. //Home
  145. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHomeTimeout, STATE.Idle);
  146. Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
  147. //Pick
  148. Transition(STATE.Idle, MSG.Pick, fnStartPick, STATE.Picking);
  149. Transition(STATE.Picking, FSM_MSG.TIMER, fnPickTimeout, STATE.Idle);
  150. Transition(STATE.Picking, MSG.Abort, fnAbortPick, STATE.Idle);
  151. //Place
  152. Transition(STATE.Idle, MSG.Place, fnStartPlace, STATE.Placing);
  153. Transition(STATE.Placing, FSM_MSG.TIMER, fnPlaceTimeout, STATE.Idle);
  154. Transition(STATE.Placing, MSG.Abort, fnAbortPlace, STATE.Idle);
  155. //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
  156. //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
  157. //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
  158. //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
  159. //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
  160. //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
  161. //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
  162. //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
  163. //Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Idle);
  164. Running = true;
  165. }
  166. protected override bool Init()
  167. {
  168. return true;
  169. }
  170. private bool fnAbortPlace(object[] param)
  171. {
  172. return true;
  173. }
  174. private bool fnPlaceTimeout(object[] param)
  175. {
  176. RState ret = _placeRoutine.Monitor();
  177. if (ret == RState.Failed || ret == RState.Timeout)
  178. {
  179. PostMsg(MSG.Error);
  180. return false;
  181. }
  182. return ret == RState.End;
  183. }
  184. private bool fnStartPlace(object[] param)
  185. {
  186. return _placeRoutine.Start(param) == RState.Running;
  187. }
  188. private bool fnAbortPick(object[] param)
  189. {
  190. _pickRoutine.Abort();
  191. return true;
  192. }
  193. private bool fnStartPick(object[] param)
  194. {
  195. return _pickRoutine.Start(param) == RState.Running;
  196. }
  197. private bool fnPickTimeout(object[] param)
  198. {
  199. RState ret = _pickRoutine.Monitor();
  200. if (ret == RState.Failed || ret == RState.Timeout)
  201. {
  202. PostMsg(MSG.Error);
  203. return false;
  204. }
  205. return ret == RState.End;
  206. }
  207. private bool fnAbortHome(object[] param)
  208. {
  209. _homeRoutine.Abort();
  210. return true;
  211. }
  212. private bool fnHome(object[] param)
  213. {
  214. if (fsm.State == (int)STATE.Init && param.Length > 0)//带参home
  215. {
  216. return false;
  217. }
  218. else
  219. return _homeRoutine.Start(param) == RState.Running;
  220. }
  221. private bool fnHomeTimeout(object[] param)
  222. {
  223. RState ret = _homeRoutine.Monitor();
  224. if (ret == RState.Failed || ret == RState.Timeout)
  225. {
  226. PostMsg(MSG.Error);
  227. return false;
  228. }
  229. return ret == RState.End;
  230. }
  231. private bool fnOffline(object[] param)
  232. {
  233. throw new NotImplementedException();
  234. }
  235. private bool fnOnline(object[] param)
  236. {
  237. throw new NotImplementedException();
  238. }
  239. private bool fnError(object[] param)
  240. {
  241. return true;
  242. }
  243. public bool Check(int msg, out string reason, params object[] args)
  244. {
  245. reason = "";
  246. return true;
  247. }
  248. public bool CheckAcked(int msg)
  249. {
  250. return fsm.CheckExecuted(msg);
  251. }
  252. public bool CheckToPostMessage(int msg, params object[] args)
  253. {
  254. if (!fsm.FindTransition(fsm.State, msg))
  255. {
  256. LOG.Write(eEvent.WARN_FSM_WARN, ModuleName.TM, $"TM is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  257. return false;
  258. }
  259. Running = true;
  260. fsm.PostMsg(msg, args);
  261. return true;
  262. }
  263. public int Invoke(string function, params object[] args)
  264. {
  265. switch (function)
  266. {
  267. case "Home":
  268. CheckToPostMessage((int)MSG.Home);
  269. return (int)MSG.Home;
  270. }
  271. return (int)FSM_MSG.NONE;
  272. }
  273. }
  274. }