SRDEntity.cs 49 KB

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