SRDEntity.cs 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Fsm;
  5. using Aitex.Core.RT.Log;
  6. using Aitex.Core.RT.OperationCenter;
  7. using Aitex.Core.RT.RecipeCenter;
  8. using Aitex.Core.Util;
  9. using Aitex.Core.Utilities;
  10. using MECF.Framework.Common.Equipment;
  11. using MECF.Framework.Common.RecipeCenter;
  12. using MECF.Framework.Common.SubstrateTrackings;
  13. using CyberX8_Core;
  14. using CyberX8_RT.Devices.AXIS;
  15. using CyberX8_RT.Devices.SRD;
  16. using CyberX8_RT.Modules.Transporter;
  17. using System;
  18. using MECF.Framework.Common.Persistent.SRD;
  19. using MECF.Framework.Common.ToolLayout;
  20. using CyberX8_RT.Modules.Dryer;
  21. using MECF.Framework.Common.Alarm;
  22. using MECF.Framework.Common.CommonData;
  23. using CyberX8_RT.Modules.Loader;
  24. namespace CyberX8_RT.Modules.SRD
  25. {
  26. public class SRDEntity : Entity, IEntity, IModuleEntity
  27. {
  28. #region 常量
  29. private const string AUTO = "Auto";
  30. private const string MANUAL = "Manual";
  31. private const string DISABLED = "Disabled";
  32. private const string ENGINEERING = "Engineering";
  33. private const string PRODUCTION = "Production";
  34. #endregion
  35. #region 内部变量
  36. /// <summary>
  37. /// 是否Homed
  38. /// </summary>
  39. private bool _isHomed;
  40. /// <summary>
  41. /// rotation电机
  42. /// </summary>
  43. private JetAxisBase _rotationAxis;
  44. /// <summary>
  45. /// arm电机
  46. /// </summary>
  47. private JetAxisBase _armAxis;
  48. /// <summary>
  49. /// IsPresenceTesting
  50. /// </summary>
  51. private bool _isPresenceTesting = false;
  52. /// <summary>
  53. /// IsAWCCycling
  54. /// </summary>
  55. private bool _isAWCCycling = false;
  56. /// <summary>
  57. /// 当前Recipe
  58. /// </summary>
  59. private SrdRecipe _currentRecipe = null;
  60. /// <summary>
  61. /// 持久化对象
  62. /// </summary>
  63. private SRDPersistentValue _persistentValue;
  64. /// <summary>
  65. /// run recipe start time
  66. /// </summary>
  67. private DateTime _runRecipeStartTime;
  68. /// <summary>
  69. /// run recipe complete time
  70. /// </summary>
  71. private DateTime _runRecipeCompleteTime;
  72. /// <summary>
  73. /// Wafer已Loader完
  74. /// </summary>
  75. private bool _isLoaded = false;
  76. #endregion
  77. #region Routine
  78. /// <summary>
  79. /// SRD Home
  80. /// </summary>
  81. private SRDHomeRoutine _homeRoutine;
  82. /// <summary>
  83. /// SRD初始化Home Routine
  84. /// </summary>
  85. private SRDInitializeHomeRoutine _initializeHomeRoutine;
  86. /// <summary>
  87. /// SRD SwicthOn
  88. /// </summary>
  89. private SRDSwitchOnRoutine _switchOnRoutine;
  90. /// <summary>
  91. /// SRD SwicthOff
  92. /// </summary>
  93. private SRDSwitchOffRoutine _switchOffRoutine;
  94. /// <summary>
  95. /// SRD Initialize
  96. /// </summary>
  97. private SRDInitializeRoutine _initializeRoutine;
  98. /// <summary>
  99. /// SRD Common Device
  100. /// </summary>
  101. private SrdCommonDevice _srdCommon;
  102. /// <summary>
  103. /// SRD GoToPosition
  104. /// </summary>
  105. private SRDPositionRoutine _positionRoutine;
  106. /// <summary>
  107. /// SRD StartRotation
  108. /// </summary>
  109. private SRDRotationRoutine _rotationRoutine;
  110. /// <summary>
  111. /// SRD PresenceTest
  112. /// </summary>
  113. private SRDPresenceTestRoutine _presenceTestRoutine;
  114. /// <summary>
  115. /// SRD ProcessRecipe
  116. /// </summary>
  117. private SRDProcessRecipeRoutine _processRecipeRoutine;
  118. /// <summary>
  119. /// SRD AWC Cycle
  120. /// </summary>
  121. private SRDAWCCycleRoutine _awcCycleRoutine;
  122. /// <summary>
  123. /// SRD Process Error
  124. /// </summary>
  125. private SRDProcessErrorRoutine _processErrorRoutine;
  126. /// <summary>
  127. /// SRD Loader Routine
  128. /// </summary>
  129. private SRDLoaderRoutine _loaderRoutine;
  130. /// <summary>
  131. /// SRD Unloader Routine
  132. /// </summary>
  133. private SRDUnloaderRoutine _unloaderRoutine;
  134. /// <summary>
  135. /// RecipeCycle
  136. /// </summary>
  137. private int _cycle = 0;
  138. /// <summary>
  139. /// recipe时长
  140. /// </summary>
  141. private int _recipeTime;
  142. #endregion
  143. #region 属性
  144. /// <summary>
  145. /// 模块名称
  146. /// </summary>
  147. public ModuleName Module { get; private set; }
  148. /// <summary>
  149. /// 初始化状态
  150. /// </summary>
  151. public bool IsInit
  152. {
  153. get { return fsm.State == (int)SRDState.Init; }
  154. }
  155. /// <summary>
  156. /// 空闲状态
  157. /// </summary>
  158. public bool IsIdle
  159. {
  160. get
  161. {
  162. return fsm.State == (int)SRDState.Idle;
  163. }
  164. }
  165. /// <summary>
  166. /// 当前状态机状态
  167. /// </summary>
  168. public int State { get { return fsm.State; } }
  169. /// <summary>
  170. /// 是否发生错误
  171. /// </summary>
  172. public bool IsError
  173. {
  174. get { return fsm.State == (int)SRDState.Error; }
  175. }
  176. /// <summary>
  177. /// 是否正在作业
  178. /// </summary>
  179. public bool IsBusy
  180. {
  181. get { return !IsInit && !IsError && !IsIdle; }
  182. }
  183. /// <summary>
  184. /// 是否已Home
  185. /// </summary>
  186. public bool IsHomed
  187. {
  188. get { return _isHomed; }
  189. }
  190. /// <summary>
  191. /// 是否正在用水
  192. /// </summary>
  193. public bool IsUsingWater
  194. {
  195. get { return _processRecipeRoutine.IsUsingWater; }
  196. }
  197. /// <summary>
  198. /// SRD门是否关闭
  199. /// </summary>
  200. public bool IsSrdDoorClosed
  201. {
  202. get { return !_srdCommon.CommonData.DoorOpened && _srdCommon.CommonData.DoorClosed; }
  203. }
  204. /// <summary>
  205. /// SRD真空是否开启
  206. /// </summary>
  207. public bool IsSrdChuckVacuum
  208. {
  209. get { return _srdCommon.CommonData.ChuckVacuum; }
  210. }
  211. /// <summary>
  212. /// 是否禁用
  213. /// </summary>
  214. public bool IsDisable { get { return _persistentValue == null || _persistentValue.OperatingMode == DISABLED; } }
  215. /// <summary>
  216. /// 自动模式
  217. /// </summary>
  218. public bool IsAuto { get { return _persistentValue != null && _persistentValue.OperatingMode == AUTO; } }
  219. /// <summary>
  220. /// 自动模式
  221. /// </summary>
  222. public bool IsManual { get { return _persistentValue != null && _persistentValue.OperatingMode == MANUAL; } }
  223. /// <summary>
  224. /// Arm是否SwitchOn
  225. /// </summary>
  226. public bool IsArmSwitchOn
  227. {
  228. get { return _armAxis.IsSwitchOn; }
  229. }
  230. /// <summary>
  231. /// Rotation是否SwitchOn
  232. /// </summary>
  233. public bool IsRotationSwitchOn
  234. {
  235. get { return _rotationAxis.IsSwitchOn; }
  236. }
  237. /// <summary>
  238. /// 已完成的RunRecipeCycle次数
  239. /// </summary>
  240. public int AchievedCycle { get { return _processRecipeRoutine.AchievedCycle; } }
  241. /// <summary>
  242. /// PresenceTest状态
  243. /// </summary>
  244. public bool IsPresenceTesting
  245. {
  246. get { return _isPresenceTesting; }
  247. }
  248. /// <summary>
  249. /// AWCCycle状态
  250. /// </summary>
  251. public bool IsAWCCycling
  252. {
  253. get { return _isAWCCycling; }
  254. }
  255. /// <summary>
  256. /// 当前状态机
  257. /// </summary>
  258. public string CurrentStateMachine
  259. {
  260. get { return GetCurrentStateMachine(); }
  261. }
  262. /// <summary>
  263. /// 是否为工程模式
  264. /// </summary>
  265. public bool IsEngineering { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == ENGINEERING; } }
  266. /// <summary>
  267. /// 是否为产品模式
  268. /// </summary>
  269. public bool IsProduction { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == PRODUCTION; } }
  270. /// <summary>
  271. /// Wafer已Loader完
  272. /// </summary>
  273. public bool IsLoaded
  274. {
  275. get { return _isLoaded; }
  276. }
  277. #endregion
  278. /// <summary>
  279. /// 构造函数
  280. /// </summary>
  281. /// <param name="module"></param>
  282. public SRDEntity(ModuleName module)
  283. {
  284. this.Module = module;
  285. _armAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.Arm");
  286. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.Rotation");
  287. WaferManager.Instance.SubscribeLocation(Module, 1);
  288. InitialFsm();
  289. }
  290. /// <summary>
  291. /// 总初始化
  292. /// </summary>
  293. /// <returns></returns>
  294. protected override bool Init()
  295. {
  296. _srdCommon = DEVICE.GetDevice<SrdCommonDevice>($"{Module}.Common");
  297. InitializeParameter();
  298. InitialDATA();
  299. InitialRoutine();
  300. InitialOperation();
  301. return true;
  302. }
  303. /// <summary>
  304. /// 初始化参数
  305. /// </summary>
  306. private void InitializeParameter()
  307. {
  308. _persistentValue = SRDPersistentManager.Instance.GetModulePersistentValue(Module.ToString());
  309. if (_persistentValue == null)
  310. {
  311. LOG.WriteLog(eEvent.ERR_SRD, Module.ToString(), "Persistent Value Object is not exist");
  312. }
  313. }
  314. /// <summary>
  315. /// 初始化数据
  316. /// </summary>
  317. private void InitialDATA()
  318. {
  319. DATA.Subscribe($"{Module}.FsmState", () => ((SRDState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  320. DATA.Subscribe($"{Module}.IsHomed", () => _isHomed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  321. DATA.Subscribe($"{Module}.IsError", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  322. DATA.Subscribe($"{Module}.SrdDoorClosed", () => IsSrdDoorClosed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  323. DATA.Subscribe($"{Module}.AchievedCycle", () => AchievedCycle, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  324. DATA.Subscribe($"{Module}.IsPresenceTesting", () => IsPresenceTesting, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  325. DATA.Subscribe($"{Module}.CurrentStateMachine", () => CurrentStateMachine, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  326. DATA.Subscribe($"{Module}.IsAWCCycling", () => IsAWCCycling, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  327. DATA.Subscribe($"{Module}.CurrentRecipe", () => _currentRecipe != null ? _currentRecipe.Ppid : "", SubscriptionAttribute.FLAG.IgnoreSaveDB);
  328. DATA.Subscribe($"{Module}.TotalTime", () => _recipeTime, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  329. DATA.Subscribe($"{Module}.TimeRemain", () => CalculateTimeRemain(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  330. DATA.Subscribe($"{Module}.OperatingMode", () => _persistentValue != null ? _persistentValue.OperatingMode : "None", SubscriptionAttribute.FLAG.IgnoreSaveDB);
  331. }
  332. /// <summary>
  333. /// 初始化状态机
  334. /// </summary>
  335. private void InitialFsm()
  336. {
  337. fsm = new StateMachine<SRDEntity>(Module.ToString(), (int)SRDState.Init, 20);
  338. fsm.EnableRepeatedMsg(true);
  339. AnyStateTransition(SRDMSG.Error, EnterError, SRDState.Error);
  340. Transition(SRDState.Error, SRDMSG.ResumeError, (param) => { return true; }, SRDState.Init);
  341. //Initialized
  342. AnyStateTransition(SRDMSG.Initialize, InitializeAll, SRDState.Initializing);
  343. Transition(SRDState.Initializing, FSM_MSG.TIMER, InitializeAllTimeout, SRDState.Initialized);
  344. //SwitchOn
  345. Transition(SRDState.Init, SRDMSG.SwitchOn, SwitchOnAll, SRDState.SwitchOning);
  346. Transition(SRDState.Idle, SRDMSG.SwitchOn, SwitchOnAll, SRDState.SwitchOning);
  347. Transition(SRDState.Error, SRDMSG.SwitchOn, SwitchOnAll, SRDState.SwitchOning);
  348. Transition(SRDState.Initialized, SRDMSG.SwitchOn, SwitchOnAll, SRDState.SwitchOning);
  349. Transition(SRDState.SwitchOning, FSM_MSG.TIMER, SwitchOnTimeout, SRDState.Init);
  350. //SwitchOff
  351. Transition(SRDState.Init, SRDMSG.SwitchOff, SwitchOffAll, SRDState.SwitchOffing);
  352. Transition(SRDState.Idle, SRDMSG.SwitchOff, SwitchOffAll, SRDState.SwitchOffing);
  353. Transition(SRDState.Error, SRDMSG.SwitchOff, SwitchOffAll, SRDState.SwitchOffing);
  354. Transition(SRDState.Initialized, SRDMSG.SwitchOff, SwitchOffAll, SRDState.SwitchOffing);
  355. Transition(SRDState.SwitchOffing, FSM_MSG.TIMER, SwitchOffTimeout, SRDState.Init);
  356. // Home
  357. Transition(SRDState.Init, SRDMSG.HomeAll, HomeAll, SRDState.Homing);
  358. Transition(SRDState.Initialized, SRDMSG.HomeAll, HomeAll, SRDState.Homing);
  359. Transition(SRDState.Error, SRDMSG.HomeAll, HomeAll, SRDState.Homing);
  360. Transition(SRDState.Idle, SRDMSG.HomeAll, HomeAll, SRDState.Homing);
  361. Transition(SRDState.Abort, SRDMSG.HomeAll, HomeAll, SRDState.Homing);
  362. Transition(SRDState.Homing, FSM_MSG.TIMER, HomingTimeout, SRDState.Idle);
  363. //Initialize Home
  364. Transition(SRDState.Init, SRDMSG.InitializeHome, InitializeHome, SRDState.InitializeHoming);
  365. Transition(SRDState.Error, SRDMSG.InitializeHome, InitializeHome, SRDState.InitializeHoming);
  366. Transition(SRDState.InitializeHoming, FSM_MSG.TIMER, InitializeHomeTimeout, SRDState.Idle);
  367. Transition(SRDState.Abort, SRDMSG.InitializeHome, InitializeHome, SRDState.InitializeHoming);
  368. Transition(SRDState.Idle, SRDMSG.InitializeHome, InitializeHome, SRDState.InitializeHoming);
  369. //Process Recipe
  370. Transition(SRDState.Idle, SRDMSG.ProcessRecipe, ProcessRecipe, SRDState.ProcessReciping);
  371. Transition(SRDState.ProcessReciping, FSM_MSG.TIMER, ProcessRecipeTimeout, SRDState.Idle);
  372. Transition(SRDState.ProcessReciping, SRDMSG.ProcessError, ProcessError, SRDState.ProcessError);
  373. Transition(SRDState.ProcessError, FSM_MSG.TIMER, ProcessErrorMonitor, SRDState.Error);
  374. //GoToSavedPosition
  375. Transition(SRDState.Idle, SRDMSG.GoToSavedPosition, GotoPosition, SRDState.Positioning);
  376. Transition(SRDState.Positioning, FSM_MSG.TIMER, GotoPositionTimeout, SRDState.Idle);
  377. //StartRotation
  378. Transition(SRDState.Idle, SRDMSG.StartRotation, StartRotation, SRDState.Rotating);
  379. Transition(SRDState.Rotating, FSM_MSG.TIMER, RotationTimeout, SRDState.Idle);
  380. //StopRotation
  381. Transition(SRDState.Rotating, SRDMSG.StopRotation, StopRotation, SRDState.Stopping);
  382. Transition(SRDState.Stopping, FSM_MSG.TIMER, StopRotationTimeout, SRDState.Idle);
  383. //Abort
  384. Transition(SRDState.ProcessReciping, SRDMSG.Abort, AbortProcessRecipe, SRDState.Abort);
  385. Transition(SRDState.PresenceTesting, SRDMSG.Abort, AbortPresenceTest, SRDState.Abort);
  386. Transition(SRDState.AWCCycling, SRDMSG.Abort, AbortAWCCycle, SRDState.Abort);
  387. Transition(SRDState.ProcessError, SRDMSG.Abort, AbortProcessError, SRDState.Abort);
  388. //PresenceTestStart
  389. Transition(SRDState.Idle, SRDMSG.PresenceTestStart, PresenceTest, SRDState.PresenceTesting);
  390. Transition(SRDState.PresenceTesting, FSM_MSG.TIMER, PresenceTestTimeout, SRDState.Idle);
  391. //AWC Cycle
  392. Transition(SRDState.Idle, SRDMSG.AWCCycleStart, AWCCycle, SRDState.AWCCycling);
  393. Transition(SRDState.AWCCycling, FSM_MSG.TIMER, AWCCycleTimeout, SRDState.Idle);
  394. Transition(SRDState.AWCCycling, SRDMSG.HomeAll, HomeAll, SRDState.AWCHoming);
  395. Transition(SRDState.AWCHoming, FSM_MSG.TIMER, HomingTimeout, SRDState.AWCCycling);
  396. //Retry
  397. Transition(SRDState.Error, SRDMSG.Retry, NullFunc, SRDState.Retrying);
  398. Transition(SRDState.Retrying, FSM_MSG.TIMER, SRDRetry, SRDState.Retrying);
  399. Transition(SRDState.Retrying, SRDMSG.ProcessRecipe, RetryRunRecipe, SRDState.ProcessReciping);
  400. //ConfirmComplete
  401. Transition(SRDState.Init, SRDMSG.ConfirmComplete, ClearModuleAlarm, SRDState.Init);
  402. Transition(SRDState.Idle, SRDMSG.ConfirmComplete, ClearModuleAlarm, SRDState.Idle);
  403. Transition(SRDState.Error, SRDMSG.ConfirmComplete, NullFunc, SRDState.ConfirmCompleting);
  404. Transition(SRDState.ConfirmCompleting, FSM_MSG.TIMER, ConfirmComplete, SRDState.ConfirmCompleting);
  405. Transition(SRDState.ConfirmCompleting, SRDMSG.ProcessRecipe, ConfirmProcessRecipe, SRDState.Idle);
  406. //Enter Init
  407. Transition(SRDState.Idle, SRDMSG.Init, NullFunc, SRDState.Init);
  408. //Loader
  409. Transition(SRDState.Idle, SRDMSG.Loader, LoaderWafer, SRDState.Loading);
  410. Transition(SRDState.Loading, FSM_MSG.TIMER, LoaderWaferMonitor, SRDState.Idle);
  411. //UnLoader
  412. Transition(SRDState.Idle, SRDMSG.Unloader, UnloaderWafer, SRDState.Unloading);
  413. Transition(SRDState.Unloading, FSM_MSG.TIMER, UnloaderWaferMonitor, SRDState.Idle);
  414. EnumLoop<SRDState>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  415. EnumLoop<SRDMSG>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  416. }
  417. /// <summary>
  418. /// 初始化Routine
  419. /// </summary>
  420. private void InitialRoutine()
  421. {
  422. _initializeHomeRoutine = new SRDInitializeHomeRoutine(Module.ToString());
  423. _homeRoutine = new SRDHomeRoutine(Module.ToString());
  424. _switchOnRoutine = new SRDSwitchOnRoutine(Module.ToString());
  425. _switchOffRoutine = new SRDSwitchOffRoutine(Module.ToString());
  426. _initializeRoutine = new SRDInitializeRoutine(Module.ToString());
  427. _positionRoutine = new SRDPositionRoutine(Module);
  428. _rotationRoutine = new SRDRotationRoutine(Module, _rotationAxis);
  429. _presenceTestRoutine = new SRDPresenceTestRoutine(Module.ToString());
  430. _processRecipeRoutine = new SRDProcessRecipeRoutine(Module.ToString(), _rotationAxis, _armAxis, _srdCommon);
  431. _awcCycleRoutine = new SRDAWCCycleRoutine(Module);
  432. _processErrorRoutine=new SRDProcessErrorRoutine(Module.ToString());
  433. _loaderRoutine = new SRDLoaderRoutine(Module.ToString());
  434. _unloaderRoutine = new SRDUnloaderRoutine(Module.ToString());
  435. }
  436. /// <summary>
  437. /// 初始化操作
  438. /// </summary>
  439. private void InitialOperation()
  440. {
  441. OP.Subscribe($"{Module}.HomeAll", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.HomeAll); });
  442. OP.Subscribe($"{Module}.InitializeHome", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.InitializeHome); });
  443. OP.Subscribe($"{Module}.SwitchOnAll", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.SwitchOn); });
  444. OP.Subscribe($"{Module}.SwitchOffAll", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.SwitchOff); });
  445. OP.Subscribe($"{Module}.CycleManualProcessRecipe", (cmd, args) =>
  446. {
  447. SrdRecipe recipe = RecipeFileManager.Instance.LoadGenericityRecipe<SrdRecipe>(args[0].ToString());
  448. if (recipe == null)
  449. {
  450. LOG.WriteLog(eEvent.ERR_SRD, Module.ToString(), $"{args[0]} recipe is null");
  451. return false;
  452. }
  453. object[] objects = new object[args.Length];
  454. objects[0] = recipe;
  455. for (int i = 1; i < args.Length; i++)
  456. {
  457. objects[i] = args[i];
  458. }
  459. return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.ProcessRecipe, objects);
  460. });
  461. //OP.Subscribe($"{Module}.Arm.GotoSavedPosition", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.GoToSavedPosition, "Arm", args); });
  462. //OP.Subscribe($"{Module}.Rotation.GotoSavedPosition", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.GoToSavedPosition, "Rotation", args); });
  463. OP.Subscribe($"{Module}.Abort", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.Abort); });
  464. OP.Subscribe($"{Module}.StartRotation", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.StartRotation, "Rotation", args); });
  465. OP.Subscribe($"{Module}.StopRotation", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.StopRotation); });
  466. OP.Subscribe($"{Module}.PresenceTestStart", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.PresenceTestStart, args); });
  467. OP.Subscribe($"{Module}.AWCCycle", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.AWCCycleStart, args); });
  468. OP.Subscribe($"{Module}.Loader", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.Loader); });
  469. OP.Subscribe($"{Module}.Unloader", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.Unloader); });
  470. }
  471. /// <summary>
  472. /// Enter Init
  473. /// </summary>
  474. public void EnterInit()
  475. {
  476. if ((SRDState)fsm.State != SRDState.Idle) return;
  477. else
  478. {
  479. CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.Init);
  480. }
  481. }
  482. /// <summary>
  483. /// 进入Error状态
  484. /// </summary>
  485. /// <param name="param"></param>
  486. /// <returns></returns>
  487. private bool EnterError(object[] param)
  488. {
  489. _isHomed = false;
  490. return true;
  491. }
  492. #region Initialized
  493. /// <summary>
  494. /// Initialize
  495. /// </summary>
  496. /// <param name="param"></param>
  497. /// <returns></returns>
  498. private bool InitializeAll(object[] param)
  499. {
  500. if (fsm.State == (int)MetalState.Initializing)
  501. {
  502. LOG.WriteLog(eEvent.WARN_SRD, Module.ToString(), "state is Initializing,cannot do initialize");
  503. return false;
  504. }
  505. return _initializeRoutine.Start() == RState.Running;
  506. }
  507. /// <summary>
  508. /// Initialize 监控
  509. /// </summary>
  510. /// <param name="param"></param>
  511. /// <returns></returns>
  512. private bool InitializeAllTimeout(object[] param)
  513. {
  514. RState ret = _initializeRoutine.Monitor();
  515. if (ret == RState.Failed || ret == RState.Timeout)
  516. {
  517. PostMsg(SRDMSG.Error);
  518. return false;
  519. }
  520. bool result = ret == RState.End;
  521. if (result)
  522. {
  523. _isHomed = false;
  524. }
  525. return result;
  526. }
  527. #endregion
  528. #region Switch On
  529. /// <summary>
  530. /// SwitchAll
  531. /// </summary>
  532. /// <param name="param"></param>
  533. /// <returns></returns>
  534. private bool SwitchOnAll(object[] param)
  535. {
  536. return _switchOnRoutine.Start() == RState.Running;
  537. }
  538. private bool SwitchOnTimeout(object[] param)
  539. {
  540. RState ret = _switchOnRoutine.Monitor();
  541. if (ret == RState.Failed || ret == RState.Timeout)
  542. {
  543. PostMsg(SRDMSG.Error);
  544. return false;
  545. }
  546. bool result = ret == RState.End;
  547. if (result)
  548. {
  549. _isHomed = false;
  550. }
  551. return result;
  552. }
  553. #endregion
  554. #region Switch Off
  555. /// <summary>
  556. /// SwitchAll
  557. /// </summary>
  558. /// <param name="param"></param>
  559. /// <returns></returns>
  560. private bool SwitchOffAll(object[] param)
  561. {
  562. return _switchOffRoutine.Start() == RState.Running;
  563. }
  564. private bool SwitchOffTimeout(object[] param)
  565. {
  566. RState ret = _switchOffRoutine.Monitor();
  567. if (ret == RState.Failed || ret == RState.Timeout)
  568. {
  569. PostMsg(SRDMSG.Error);
  570. return false;
  571. }
  572. bool result = ret == RState.End;
  573. if (result)
  574. {
  575. _isHomed = false;
  576. }
  577. return result;
  578. }
  579. #endregion
  580. #region Home
  581. /// <summary>
  582. /// HomeAll
  583. /// </summary>
  584. /// <param name="param"></param>
  585. /// <returns></returns>
  586. private bool HomeAll(object[] param)
  587. {
  588. _isHomed = false;
  589. return _homeRoutine.Start() == RState.Running;
  590. }
  591. /// <summary>
  592. /// Home超时
  593. /// </summary>
  594. /// <param name="param"></param>
  595. /// <returns></returns>
  596. private bool HomingTimeout(object[] param)
  597. {
  598. RState ret = _homeRoutine.Monitor();
  599. if (ret == RState.Failed || ret == RState.Timeout)
  600. {
  601. PostMsg(SRDMSG.Error);
  602. return false;
  603. }
  604. bool result = ret == RState.End;
  605. if (result)
  606. {
  607. _isHomed = true;
  608. }
  609. return result;
  610. }
  611. #endregion
  612. #region Process Recipe
  613. /// <summary>
  614. /// ProcessRecipe
  615. /// </summary>
  616. /// <param name="param"></param>
  617. /// <returns></returns>
  618. private bool ProcessRecipe(object[] param)
  619. {
  620. SrdRecipe recipe= param[0] as SrdRecipe;
  621. if(param.Length >= 2) _cycle = (int)param[1];
  622. bool result = _processRecipeRoutine.Start(param) == RState.Running;
  623. if (result)
  624. {
  625. if (CellItemRecipeTimeManager.Instance.ContainRecipe(recipe.Ppid))
  626. {
  627. _recipeTime = _cycle * CellItemRecipeTimeManager.Instance.GetRecipeTotalTime(recipe.Ppid);
  628. }
  629. else
  630. {
  631. _recipeTime = 0;
  632. }
  633. _currentRecipe = recipe;
  634. _runRecipeStartTime = DateTime.Now;
  635. FaModuleNotifier.Instance.NotifySRDRecipeStart(Module, recipe.Ppid);
  636. }
  637. return result;
  638. }
  639. /// <summary>
  640. /// ProcessRecipe超时
  641. /// </summary>
  642. /// <param name="param"></param>
  643. /// <returns></returns>
  644. private bool ProcessRecipeTimeout(object[] param)
  645. {
  646. RState ret = _processRecipeRoutine.Monitor();
  647. if (ret == RState.Failed || ret == RState.Timeout)
  648. {
  649. PostMsg(SRDMSG.ProcessError);
  650. //记录LotTrack
  651. _runRecipeCompleteTime = DateTime.Now;
  652. _processRecipeRoutine.SRDLotTrackHeaderDatas.ProcessTime = (_runRecipeCompleteTime - _runRecipeStartTime).TotalSeconds.ToString("F2");
  653. SRDLotTrackUtil.ExportSRDLotTrack(Module.ToString(), _processRecipeRoutine.SRDLotTrackDatas,
  654. _processRecipeRoutine.SRDLotTrackHeaderDatas, IsAuto);
  655. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  656. {
  657. AlarmList alarmList = new AlarmList(Module.ToString(), ((SRDState)fsm.State).ToString(), (int)SRDMSG.ProcessRecipe,
  658. _processRecipeRoutine.ErrorMsg, _processRecipeRoutine.ErrorStep, (int)AlarmType.Error);
  659. AlarmListManager.Instance.AddAlarm(alarmList);
  660. }
  661. if (_currentRecipe != null)
  662. {
  663. FaModuleNotifier.Instance.NotifySRDRecipeFailed(Module, _currentRecipe.Ppid);
  664. }
  665. return false;
  666. }
  667. bool result = ret == RState.End;
  668. if (result)
  669. {
  670. double elapsedMilliseconds = _processRecipeRoutine.ElapsedMilliseconds;
  671. int recipeTime = (int)Math.Floor(elapsedMilliseconds / _cycle / 1000);
  672. CellItemRecipeTimeManager.Instance.UpdateRecipeTime(_currentRecipe.Ppid, recipeTime);
  673. //记录LotTrack
  674. _runRecipeCompleteTime = DateTime.Now;
  675. _processRecipeRoutine.SRDLotTrackHeaderDatas.ProcessTime = (_runRecipeCompleteTime - _runRecipeStartTime).TotalSeconds.ToString("F2");
  676. SRDLotTrackUtil.ExportSRDLotTrack(Module.ToString(), _processRecipeRoutine.SRDLotTrackDatas,
  677. _processRecipeRoutine.SRDLotTrackHeaderDatas, IsAuto);
  678. if (_currentRecipe != null)
  679. {
  680. FaModuleNotifier.Instance.NotifySRDRecipeEnd(Module, _currentRecipe.Ppid);
  681. }
  682. _currentRecipe = null;
  683. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), SRDState.ProcessReciping.ToString());
  684. }
  685. return result;
  686. }
  687. /// <summary>
  688. /// Abort Recipe
  689. /// </summary>
  690. /// <param name="param"></param>
  691. /// <returns></returns>
  692. private bool AbortProcessRecipe(object[] param)
  693. {
  694. _processRecipeRoutine.Abort();
  695. //记录LotTrack
  696. _runRecipeCompleteTime = DateTime.Now;
  697. _processRecipeRoutine.SRDLotTrackHeaderDatas.ProcessTime = (_runRecipeCompleteTime - _runRecipeStartTime).TotalSeconds.ToString("F2");
  698. SRDLotTrackUtil.ExportSRDLotTrack(Module.ToString(), _processRecipeRoutine.SRDLotTrackDatas,
  699. _processRecipeRoutine.SRDLotTrackHeaderDatas, IsAuto);
  700. return true;
  701. }
  702. /// <summary>
  703. /// 计算剩余时间
  704. /// </summary>
  705. /// <returns></returns>
  706. private double CalculateTimeRemain()
  707. {
  708. if (IsBusy)
  709. {
  710. return _recipeTime != 0 ? (_recipeTime - Math.Floor((double)_processRecipeRoutine.ElapsedMilliseconds / 1000)) : 0;
  711. }
  712. else
  713. {
  714. return 0;
  715. }
  716. }
  717. /// <summary>
  718. /// ProcessError
  719. /// </summary>
  720. /// <param name="param"></param>
  721. /// <returns></returns>
  722. private bool ProcessError(object[] param)
  723. {
  724. return _processErrorRoutine.Start(param)==RState.Running;
  725. }
  726. /// <summary>
  727. /// Process Error监控
  728. /// </summary>
  729. /// <param name="param"></param>
  730. /// <returns></returns>
  731. private bool ProcessErrorMonitor(object[] param)
  732. {
  733. RState state = _processErrorRoutine.Monitor();
  734. if (state == RState.End||state==RState.Failed||state==RState.Timeout)
  735. {
  736. return true;
  737. }
  738. return false;
  739. }
  740. private bool AbortProcessError(object[] param)
  741. {
  742. _processErrorRoutine.Abort();
  743. return false;
  744. }
  745. /// <summary>
  746. /// Retry RunRecipe
  747. /// </summary>
  748. /// <param name="param"></param>
  749. /// <returns></returns>
  750. private bool RetryRunRecipe(object[] param)
  751. {
  752. int stepIndex = (int)param[0];
  753. bool result = _processRecipeRoutine.Retry(stepIndex) == RState.Running;
  754. if (result)
  755. {
  756. if (_currentRecipe != null)
  757. {
  758. if (CellItemRecipeTimeManager.Instance.ContainRecipe(_currentRecipe.Ppid))
  759. {
  760. _recipeTime = _cycle * CellItemRecipeTimeManager.Instance.GetRecipeTotalTime(_currentRecipe.Ppid);
  761. }
  762. else
  763. {
  764. _recipeTime = 0;
  765. }
  766. _runRecipeStartTime = DateTime.Now;
  767. }
  768. }
  769. return result;
  770. }
  771. /// <summary>
  772. /// 确认ProcessRecipe是否完成
  773. /// </summary>
  774. /// <param name="param"></param>
  775. /// <returns></returns>
  776. private bool ConfirmProcessRecipe(object[] param)
  777. {
  778. int stepIdex = (int)param[0];
  779. bool result = _processRecipeRoutine.CheckCompleteCondition(stepIdex);
  780. if (!result)
  781. {
  782. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  783. {
  784. AlarmList alarmList = new AlarmList(Module.ToString(), ((SRDState)fsm.State).ToString(), (int)SRDMSG.ProcessRecipe,
  785. _processRecipeRoutine.ErrorMsg, _processRecipeRoutine.ErrorStep, (int)AlarmType.Error);
  786. AlarmListManager.Instance.AddAlarm(alarmList);
  787. }
  788. PostMsg(SRDMSG.Error);
  789. }
  790. else
  791. {
  792. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  793. {
  794. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), SRDState.ProcessReciping.ToString());
  795. }
  796. }
  797. return result;
  798. }
  799. #endregion
  800. #region AWC Cycle
  801. /// <summary>
  802. /// AWC Cycle
  803. /// </summary>
  804. /// <returns></returns>
  805. private bool AWCCycle(object[] param)
  806. {
  807. return _awcCycleRoutine.Start(param) == RState.Running;
  808. }
  809. /// <summary>
  810. /// AWC Cycle超时
  811. /// </summary>
  812. /// <param name="param"></param>
  813. /// <returns></returns>
  814. private bool AWCCycleTimeout(object[] param)
  815. {
  816. RState ret = _awcCycleRoutine.Monitor();
  817. if (ret == RState.Failed || ret == RState.Timeout)
  818. {
  819. _isAWCCycling = false;
  820. PostMsg(SRDMSG.Error);
  821. return false;
  822. }
  823. //设置IsPresenceTesting
  824. if (ret == RState.Running)
  825. {
  826. _isAWCCycling = true;
  827. }
  828. else
  829. {
  830. _isAWCCycling = false;
  831. }
  832. return ret == RState.End;
  833. }
  834. /// <summary>
  835. /// Abort AWC Cycle
  836. /// </summary>
  837. /// <param name="param"></param>
  838. /// <returns></returns>
  839. private bool AbortAWCCycle(object[] param)
  840. {
  841. _awcCycleRoutine.Abort();
  842. return true;
  843. }
  844. #endregion
  845. #region InitializeHome
  846. /// <summary>
  847. /// InitializeHome
  848. /// </summary>
  849. /// <param name="param"></param>
  850. /// <returns></returns>
  851. private bool InitializeHome(object[] param)
  852. {
  853. _isHomed = false;
  854. return _initializeHomeRoutine.Start() == RState.Running;
  855. }
  856. /// <summary>
  857. /// InitializeHome超时
  858. /// </summary>
  859. /// <param name="param"></param>
  860. /// <returns></returns>
  861. private bool InitializeHomeTimeout(object[] param)
  862. {
  863. RState ret = _initializeHomeRoutine.Monitor();
  864. if (ret == RState.Failed || ret == RState.Timeout)
  865. {
  866. PostMsg(SRDMSG.Error);
  867. return false;
  868. }
  869. bool result = ret == RState.End;
  870. if (result)
  871. {
  872. _isHomed = true;
  873. }
  874. return result;
  875. }
  876. #endregion
  877. #region RunRecipeRetry
  878. /// <summary>
  879. /// Retry
  880. /// </summary>
  881. /// <param name="param"></param>
  882. /// <returns></returns>
  883. private bool SRDRetry(object[] param)
  884. {
  885. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  886. if (alarmList != null)
  887. {
  888. CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), alarmList.ModuleCmd,
  889. alarmList.ModuleStep);
  890. }
  891. return false;
  892. }
  893. #endregion
  894. #region ConfirmComplete
  895. /// <summary>
  896. /// 确认是否完成
  897. /// </summary>
  898. /// <param name="param"></param>
  899. /// <returns></returns>
  900. private bool ConfirmComplete(object[] param)
  901. {
  902. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  903. if (alarmList != null)
  904. {
  905. if (alarmList.ModuleState == SRDState.ProcessReciping.ToString())
  906. {
  907. CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.ProcessRecipe, alarmList.ModuleStep);
  908. }
  909. else
  910. {
  911. PostMsg(SRDState.Error);
  912. }
  913. }
  914. return false;
  915. }
  916. /// <summary>
  917. /// 清除报警
  918. /// </summary>
  919. /// <param name="param"></param>
  920. /// <returns></returns>
  921. private bool ClearModuleAlarm(object[] param)
  922. {
  923. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  924. if (alarmList != null)
  925. {
  926. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), "");
  927. }
  928. return true;
  929. }
  930. #endregion
  931. #region Loader
  932. /// <summary>
  933. /// SRD Loader Wafer
  934. /// </summary>
  935. /// <param name="param"></param>
  936. /// <returns></returns>
  937. private bool LoaderWafer(object[] param)
  938. {
  939. return _loaderRoutine.Start(param) == RState.Running;
  940. }
  941. /// <summary>
  942. /// SRD Loader Wafer Monitor
  943. /// </summary>
  944. /// <param name="param"></param>
  945. /// <returns></returns>
  946. private bool LoaderWaferMonitor(object[] param)
  947. {
  948. RState state = _loaderRoutine.Monitor();
  949. if (state == RState.End || state == RState.Failed || state == RState.Timeout)
  950. {
  951. _isLoaded = state == RState.End;
  952. return true;
  953. }
  954. return false;
  955. }
  956. #endregion
  957. #region Unloader
  958. /// <summary>
  959. /// SRD Unloader Wafer
  960. /// </summary>
  961. /// <param name="param"></param>
  962. /// <returns></returns>
  963. private bool UnloaderWafer(object[] param)
  964. {
  965. return _unloaderRoutine.Start(false) == RState.Running;
  966. }
  967. /// <summary>
  968. /// SRD Unloader Wafer Monitor
  969. /// </summary>
  970. /// <param name="param"></param>
  971. /// <returns></returns>
  972. private bool UnloaderWaferMonitor(object[] param)
  973. {
  974. RState state = _unloaderRoutine.Monitor();
  975. if (state == RState.End || state == RState.Failed || state == RState.Timeout)
  976. {
  977. _isLoaded = !(state == RState.End);
  978. return true;
  979. }
  980. return false;
  981. }
  982. #endregion
  983. public bool Check(int msg, out string reason, params object[] args)
  984. {
  985. reason = "";
  986. return false;
  987. }
  988. public bool CheckAcked(int msg)
  989. {
  990. return false;
  991. }
  992. public int Invoke(string function, params object[] args)
  993. {
  994. switch (function)
  995. {
  996. case "HomeAll":
  997. if (IsIdle)
  998. {
  999. return (int)FSM_MSG.NONE;
  1000. }
  1001. if (CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.InitializeHome))
  1002. {
  1003. return (int)SRDMSG.Initialize;
  1004. }
  1005. else
  1006. {
  1007. return (int)FSM_MSG.NONE;
  1008. }
  1009. case "Retry":
  1010. if (CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.Retry, args))
  1011. {
  1012. return (int)SRDMSG.Retry;
  1013. }
  1014. else
  1015. {
  1016. return (int)FSM_MSG.NONE;
  1017. }
  1018. case "ConfirmComplete":
  1019. if (CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.ConfirmComplete, args))
  1020. {
  1021. return (int)SRDMSG.ConfirmComplete;
  1022. }
  1023. else
  1024. {
  1025. return (int)FSM_MSG.NONE;
  1026. }
  1027. }
  1028. return (int)FSM_MSG.NONE;
  1029. }
  1030. #region GoToPosition
  1031. /// <summary>
  1032. /// Go to Position
  1033. /// </summary>
  1034. /// <param name="param"></param>
  1035. /// <returns></returns>
  1036. private bool GotoPosition(object[] param)
  1037. {
  1038. string axis = param[0].ToString();
  1039. object[] objs = (object[])param[1];
  1040. string position = objs[1].ToString();
  1041. var result = CheckGotoPositionPreCondition(axis, position);
  1042. if (result.result)
  1043. {
  1044. return _positionRoutine.Start(result.axis, position) == RState.Running;
  1045. }
  1046. else
  1047. {
  1048. return false;
  1049. }
  1050. }
  1051. /// <summary>
  1052. /// 检验GotoPosition前置条件
  1053. /// </summary>
  1054. /// <param name="axis"></param>
  1055. /// <param name="position"></param>
  1056. /// <returns></returns>
  1057. private (bool result, JetAxisBase axis) CheckGotoPositionPreCondition(string axis, string position)
  1058. {
  1059. switch (axis)
  1060. {
  1061. case "Rotation":
  1062. return (_rotationAxis.CheckGotoPosition(position), _rotationAxis);
  1063. case "Arm":
  1064. return (_armAxis.CheckGotoPosition(position), _armAxis);
  1065. default:
  1066. return (false, null);
  1067. }
  1068. }
  1069. /// <summary>
  1070. /// GotoPosition超时
  1071. /// </summary>
  1072. /// <param name="param"></param>
  1073. /// <returns></returns>
  1074. private bool GotoPositionTimeout(object[] param)
  1075. {
  1076. RState ret = _positionRoutine.Monitor();
  1077. if (ret == RState.Failed || ret == RState.Timeout)
  1078. {
  1079. return true;
  1080. }
  1081. return ret == RState.End;
  1082. }
  1083. #endregion
  1084. #region 旋转
  1085. /// <summary>
  1086. /// 开始旋转
  1087. /// </summary>
  1088. /// <param name="param"></param>
  1089. /// <returns></returns>
  1090. private bool StartRotation(object[] param)
  1091. {
  1092. string axis = param[0].ToString();
  1093. object[] objs = (object[])param[1];
  1094. double time = double.Parse(objs[0].ToString());
  1095. double speed = double.Parse(objs[1].ToString());
  1096. return _rotationRoutine.Start(_rotationAxis, time, speed) == RState.Running;
  1097. }
  1098. /// <summary>
  1099. /// RotationTimeout
  1100. /// </summary>
  1101. /// <param name="param"></param>
  1102. /// <returns></returns>
  1103. private bool RotationTimeout(object[] param)
  1104. {
  1105. RState ret = _rotationRoutine.Monitor();
  1106. if (ret == RState.Failed || ret == RState.Timeout)
  1107. {
  1108. //PostMsg(SRDMSG.Error);
  1109. return true;
  1110. }
  1111. return ret == RState.End;
  1112. }
  1113. /// <summary>
  1114. /// 停止旋转
  1115. /// </summary>
  1116. /// <param name="param"></param>
  1117. /// <returns></returns>
  1118. private bool StopRotation(object[] param)
  1119. {
  1120. _rotationAxis.StopPositionOperation();
  1121. return _rotationAxis.Status == RState.Running;
  1122. }
  1123. /// <summary>
  1124. /// 停止旋转监控
  1125. /// </summary>
  1126. /// <param name="param"></param>
  1127. /// <returns></returns>
  1128. private bool StopRotationTimeout(object[] param)
  1129. {
  1130. RState ret = _rotationAxis.Status;
  1131. if (ret == RState.Failed || ret == RState.Timeout)
  1132. {
  1133. //PostMsg(SRDMSG.Error);
  1134. return true;
  1135. }
  1136. return ret == RState.End;
  1137. }
  1138. #endregion
  1139. #region PresenceTest
  1140. private bool PresenceTest(object[] param)
  1141. {
  1142. _recipeTime = 0;
  1143. return _presenceTestRoutine.Start(param) == RState.Running;
  1144. }
  1145. private bool PresenceTestTimeout(object[] param)
  1146. {
  1147. RState ret = _presenceTestRoutine.Monitor();
  1148. if (ret == RState.Failed || ret == RState.Timeout)
  1149. {
  1150. _isPresenceTesting = false;
  1151. PostMsg(SRDMSG.Error);
  1152. return false;
  1153. }
  1154. //设置IsPresenceTesting
  1155. if (ret == RState.Running)
  1156. {
  1157. _isPresenceTesting = true;
  1158. }
  1159. else
  1160. {
  1161. _isPresenceTesting = false;
  1162. }
  1163. return ret == RState.End;
  1164. }
  1165. /// <summary>
  1166. /// Abort PresenceTest
  1167. /// </summary>
  1168. /// <param name="param"></param>
  1169. /// <returns></returns>
  1170. private bool AbortPresenceTest(object[] param)
  1171. {
  1172. _presenceTestRoutine.Abort();
  1173. return true;
  1174. }
  1175. #endregion
  1176. /// <summary>
  1177. /// 获取当前子状态机
  1178. /// </summary>
  1179. private string GetCurrentStateMachine()
  1180. {
  1181. string state = "";
  1182. switch ((SRDState)fsm.State)
  1183. {
  1184. case SRDState.Init:
  1185. state = "Init";
  1186. break;
  1187. case SRDState.Initializing:
  1188. state = _initializeRoutine.CurrentStateMachine;
  1189. break;
  1190. case SRDState.Homing:
  1191. state = _homeRoutine.CurrentStateMachine;
  1192. break;
  1193. case SRDState.SwitchOning:
  1194. state = _switchOnRoutine.CurrentStateMachine;
  1195. break;
  1196. case SRDState.SwitchOffing:
  1197. state = _switchOffRoutine.CurrentStateMachine;
  1198. break;
  1199. case SRDState.Positioning:
  1200. state = _positionRoutine.CurrentStateMachine;
  1201. break;
  1202. case SRDState.Rotating:
  1203. state = _rotationRoutine.CurrentStateMachine;
  1204. break;
  1205. case SRDState.PresenceTesting:
  1206. state = _presenceTestRoutine.CurrentStateMachine;
  1207. break;
  1208. case SRDState.ProcessReciping:
  1209. state = _processRecipeRoutine.CurrentStateMachine;
  1210. break;
  1211. case SRDState.AWCCycling:
  1212. state = _awcCycleRoutine.CurrentStateMachine;
  1213. break;
  1214. default:
  1215. state = Enum.GetName(typeof(SRDState),fsm.State);
  1216. break;
  1217. }
  1218. return state;
  1219. }
  1220. /// <summary>
  1221. /// 设置IsAWCCycling
  1222. /// </summary>
  1223. /// <param name="flag"></param>
  1224. public void SetIsAWCCycling(bool flag)
  1225. {
  1226. _isAWCCycling = flag;
  1227. }
  1228. }
  1229. public enum SRDMSG
  1230. {
  1231. Initialize,
  1232. InitializeHome,
  1233. ProcessRecipe,
  1234. ResumeError,
  1235. SwitchOn,
  1236. SwitchOff,
  1237. HomeAll,
  1238. Error,
  1239. GoToSavedPosition,
  1240. Abort,
  1241. StartRotation,
  1242. StopRotation,
  1243. PresenceTestStart,
  1244. PresenceTestStop,
  1245. AWCCycleStart,
  1246. Init,
  1247. ProcessError,
  1248. Retry,
  1249. ConfirmComplete,
  1250. Loader,
  1251. Unloader
  1252. }
  1253. }