SRDEntity.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  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. PostMsg(SRDMSG.Error);
  651. //记录LotTrack
  652. _runRecipeCompleteTime = DateTime.Now;
  653. _processRecipeRoutine.SRDLotTrackHeaderDatas.ProcessTime = (_runRecipeCompleteTime - _runRecipeStartTime).TotalSeconds.ToString("F2");
  654. SRDLotTrackUtil.ExportSRDLotTrack(Module.ToString(), _processRecipeRoutine.SRDLotTrackDatas,
  655. _processRecipeRoutine.SRDLotTrackHeaderDatas, IsAuto);
  656. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  657. {
  658. AlarmList alarmList = new AlarmList(Module.ToString(), ((SRDState)fsm.State).ToString(), (int)SRDMSG.ProcessRecipe,
  659. _processRecipeRoutine.ErrorMsg, _processRecipeRoutine.ErrorStep, (int)AlarmType.Error);
  660. AlarmListManager.Instance.AddAlarm(alarmList);
  661. }
  662. if (_currentRecipe != null)
  663. {
  664. FaModuleNotifier.Instance.NotifySRDRecipeFailed(Module, _currentRecipe.Ppid);
  665. }
  666. return false;
  667. }
  668. bool result = ret == RState.End;
  669. if (result)
  670. {
  671. double elapsedMilliseconds = _processRecipeRoutine.ElapsedMilliseconds;
  672. int recipeTime = (int)Math.Floor(elapsedMilliseconds / _cycle / 1000);
  673. CellItemRecipeTimeManager.Instance.UpdateRecipeTime(_currentRecipe.Ppid, recipeTime);
  674. //记录LotTrack
  675. _runRecipeCompleteTime = DateTime.Now;
  676. _processRecipeRoutine.SRDLotTrackHeaderDatas.ProcessTime = (_runRecipeCompleteTime - _runRecipeStartTime).TotalSeconds.ToString("F2");
  677. SRDLotTrackUtil.ExportSRDLotTrack(Module.ToString(), _processRecipeRoutine.SRDLotTrackDatas,
  678. _processRecipeRoutine.SRDLotTrackHeaderDatas, IsAuto);
  679. if (_currentRecipe != null)
  680. {
  681. FaModuleNotifier.Instance.NotifySRDRecipeEnd(Module, _currentRecipe.Ppid);
  682. }
  683. _currentRecipe = null;
  684. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), SRDState.ProcessReciping.ToString());
  685. }
  686. return result;
  687. }
  688. /// <summary>
  689. /// Abort Recipe
  690. /// </summary>
  691. /// <param name="param"></param>
  692. /// <returns></returns>
  693. private bool AbortProcessRecipe(object[] param)
  694. {
  695. _processRecipeRoutine.Abort();
  696. //记录LotTrack
  697. _runRecipeCompleteTime = DateTime.Now;
  698. _processRecipeRoutine.SRDLotTrackHeaderDatas.ProcessTime = (_runRecipeCompleteTime - _runRecipeStartTime).TotalSeconds.ToString("F2");
  699. SRDLotTrackUtil.ExportSRDLotTrack(Module.ToString(), _processRecipeRoutine.SRDLotTrackDatas,
  700. _processRecipeRoutine.SRDLotTrackHeaderDatas, IsAuto);
  701. return true;
  702. }
  703. /// <summary>
  704. /// 计算剩余时间
  705. /// </summary>
  706. /// <returns></returns>
  707. private double CalculateTimeRemain()
  708. {
  709. if (IsBusy)
  710. {
  711. return _recipeTime != 0 ? (_recipeTime - Math.Floor((double)_processRecipeRoutine.ElapsedMilliseconds / 1000)) : 0;
  712. }
  713. else
  714. {
  715. return 0;
  716. }
  717. }
  718. /// <summary>
  719. /// ProcessError
  720. /// </summary>
  721. /// <param name="param"></param>
  722. /// <returns></returns>
  723. private bool ProcessError(object[] param)
  724. {
  725. return _processErrorRoutine.Start(param)==RState.Running;
  726. }
  727. /// <summary>
  728. /// Process Error监控
  729. /// </summary>
  730. /// <param name="param"></param>
  731. /// <returns></returns>
  732. private bool ProcessErrorMonitor(object[] param)
  733. {
  734. RState state = _processErrorRoutine.Monitor();
  735. if (state == RState.End||state==RState.Failed||state==RState.Timeout)
  736. {
  737. return true;
  738. }
  739. return false;
  740. }
  741. private bool AbortProcessError(object[] param)
  742. {
  743. _processErrorRoutine.Abort();
  744. return false;
  745. }
  746. /// <summary>
  747. /// Retry RunRecipe
  748. /// </summary>
  749. /// <param name="param"></param>
  750. /// <returns></returns>
  751. private bool RetryRunRecipe(object[] param)
  752. {
  753. int stepIndex = (int)param[0];
  754. bool result = _processRecipeRoutine.Retry(stepIndex) == RState.Running;
  755. if (result)
  756. {
  757. if (_currentRecipe != null)
  758. {
  759. if (CellItemRecipeTimeManager.Instance.ContainRecipe(_currentRecipe.Ppid))
  760. {
  761. _recipeTime = _cycle * CellItemRecipeTimeManager.Instance.GetRecipeTotalTime(_currentRecipe.Ppid);
  762. }
  763. else
  764. {
  765. _recipeTime = 0;
  766. }
  767. _runRecipeStartTime = DateTime.Now;
  768. }
  769. }
  770. return result;
  771. }
  772. /// <summary>
  773. /// 确认ProcessRecipe是否完成
  774. /// </summary>
  775. /// <param name="param"></param>
  776. /// <returns></returns>
  777. private bool ConfirmProcessRecipe(object[] param)
  778. {
  779. int stepIdex = (int)param[0];
  780. bool result = _processRecipeRoutine.CheckCompleteCondition(stepIdex);
  781. if (!result)
  782. {
  783. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  784. {
  785. AlarmList alarmList = new AlarmList(Module.ToString(), ((SRDState)fsm.State).ToString(), (int)SRDMSG.ProcessRecipe,
  786. _processRecipeRoutine.ErrorMsg, _processRecipeRoutine.ErrorStep, (int)AlarmType.Error);
  787. AlarmListManager.Instance.AddAlarm(alarmList);
  788. }
  789. PostMsg(SRDMSG.Error);
  790. }
  791. else
  792. {
  793. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  794. {
  795. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), SRDState.ProcessReciping.ToString());
  796. }
  797. }
  798. return result;
  799. }
  800. #endregion
  801. #region AWC Cycle
  802. /// <summary>
  803. /// AWC Cycle
  804. /// </summary>
  805. /// <returns></returns>
  806. private bool AWCCycle(object[] param)
  807. {
  808. return _awcCycleRoutine.Start(param) == RState.Running;
  809. }
  810. /// <summary>
  811. /// AWC Cycle超时
  812. /// </summary>
  813. /// <param name="param"></param>
  814. /// <returns></returns>
  815. private bool AWCCycleTimeout(object[] param)
  816. {
  817. RState ret = _awcCycleRoutine.Monitor();
  818. if (ret == RState.Failed || ret == RState.Timeout)
  819. {
  820. _isAWCCycling = false;
  821. PostMsg(SRDMSG.Error);
  822. return false;
  823. }
  824. //设置IsPresenceTesting
  825. if (ret == RState.Running)
  826. {
  827. _isAWCCycling = true;
  828. }
  829. else
  830. {
  831. _isAWCCycling = false;
  832. }
  833. return ret == RState.End;
  834. }
  835. /// <summary>
  836. /// Abort AWC Cycle
  837. /// </summary>
  838. /// <param name="param"></param>
  839. /// <returns></returns>
  840. private bool AbortAWCCycle(object[] param)
  841. {
  842. _awcCycleRoutine.Abort();
  843. return true;
  844. }
  845. #endregion
  846. #region InitializeHome
  847. /// <summary>
  848. /// InitializeHome
  849. /// </summary>
  850. /// <param name="param"></param>
  851. /// <returns></returns>
  852. private bool InitializeHome(object[] param)
  853. {
  854. _isHomed = false;
  855. return _initializeHomeRoutine.Start() == RState.Running;
  856. }
  857. /// <summary>
  858. /// InitializeHome超时
  859. /// </summary>
  860. /// <param name="param"></param>
  861. /// <returns></returns>
  862. private bool InitializeHomeTimeout(object[] param)
  863. {
  864. RState ret = _initializeHomeRoutine.Monitor();
  865. if (ret == RState.Failed || ret == RState.Timeout)
  866. {
  867. PostMsg(SRDMSG.Error);
  868. return false;
  869. }
  870. bool result = ret == RState.End;
  871. if (result)
  872. {
  873. _isHomed = true;
  874. }
  875. return result;
  876. }
  877. #endregion
  878. #region RunRecipeRetry
  879. /// <summary>
  880. /// Retry
  881. /// </summary>
  882. /// <param name="param"></param>
  883. /// <returns></returns>
  884. private bool SRDRetry(object[] param)
  885. {
  886. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  887. if (alarmList != null)
  888. {
  889. CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), alarmList.ModuleCmd,
  890. alarmList.ModuleStep);
  891. }
  892. return false;
  893. }
  894. #endregion
  895. #region ConfirmComplete
  896. /// <summary>
  897. /// 确认是否完成
  898. /// </summary>
  899. /// <param name="param"></param>
  900. /// <returns></returns>
  901. private bool ConfirmComplete(object[] param)
  902. {
  903. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  904. if (alarmList != null)
  905. {
  906. if (alarmList.ModuleState == SRDState.ProcessReciping.ToString())
  907. {
  908. CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.ProcessRecipe, alarmList.ModuleStep);
  909. }
  910. else
  911. {
  912. PostMsg(SRDState.Error);
  913. }
  914. }
  915. return false;
  916. }
  917. /// <summary>
  918. /// 清除报警
  919. /// </summary>
  920. /// <param name="param"></param>
  921. /// <returns></returns>
  922. private bool ClearModuleAlarm(object[] param)
  923. {
  924. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  925. if (alarmList != null)
  926. {
  927. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), "");
  928. }
  929. return true;
  930. }
  931. #endregion
  932. #region Loader
  933. /// <summary>
  934. /// SRD Loader Wafer
  935. /// </summary>
  936. /// <param name="param"></param>
  937. /// <returns></returns>
  938. private bool LoaderWafer(object[] param)
  939. {
  940. return _loaderRoutine.Start(param) == RState.Running;
  941. }
  942. /// <summary>
  943. /// SRD Loader Wafer Monitor
  944. /// </summary>
  945. /// <param name="param"></param>
  946. /// <returns></returns>
  947. private bool LoaderWaferMonitor(object[] param)
  948. {
  949. RState state = _loaderRoutine.Monitor();
  950. if (state == RState.End || state == RState.Failed || state == RState.Timeout)
  951. {
  952. _isLoaded = state == RState.End;
  953. return true;
  954. }
  955. return false;
  956. }
  957. #endregion
  958. #region Unloader
  959. /// <summary>
  960. /// SRD Unloader Wafer
  961. /// </summary>
  962. /// <param name="param"></param>
  963. /// <returns></returns>
  964. private bool UnloaderWafer(object[] param)
  965. {
  966. return _unloaderRoutine.Start(false) == RState.Running;
  967. }
  968. /// <summary>
  969. /// SRD Unloader Wafer Monitor
  970. /// </summary>
  971. /// <param name="param"></param>
  972. /// <returns></returns>
  973. private bool UnloaderWaferMonitor(object[] param)
  974. {
  975. RState state = _unloaderRoutine.Monitor();
  976. if (state == RState.End || state == RState.Failed || state == RState.Timeout)
  977. {
  978. _isLoaded = !(state == RState.End);
  979. return true;
  980. }
  981. return false;
  982. }
  983. #endregion
  984. public bool Check(int msg, out string reason, params object[] args)
  985. {
  986. reason = "";
  987. return false;
  988. }
  989. public bool CheckAcked(int msg)
  990. {
  991. return false;
  992. }
  993. public int Invoke(string function, params object[] args)
  994. {
  995. switch (function)
  996. {
  997. case "HomeAll":
  998. if (IsIdle)
  999. {
  1000. return (int)FSM_MSG.NONE;
  1001. }
  1002. if (CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.InitializeHome))
  1003. {
  1004. return (int)SRDMSG.Initialize;
  1005. }
  1006. else
  1007. {
  1008. return (int)FSM_MSG.NONE;
  1009. }
  1010. case "Retry":
  1011. if (CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.Retry, args))
  1012. {
  1013. return (int)SRDMSG.Retry;
  1014. }
  1015. else
  1016. {
  1017. return (int)FSM_MSG.NONE;
  1018. }
  1019. case "ConfirmComplete":
  1020. if (CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.ConfirmComplete, args))
  1021. {
  1022. return (int)SRDMSG.ConfirmComplete;
  1023. }
  1024. else
  1025. {
  1026. return (int)FSM_MSG.NONE;
  1027. }
  1028. }
  1029. return (int)FSM_MSG.NONE;
  1030. }
  1031. #region GoToPosition
  1032. /// <summary>
  1033. /// Go to Position
  1034. /// </summary>
  1035. /// <param name="param"></param>
  1036. /// <returns></returns>
  1037. private bool GotoPosition(object[] param)
  1038. {
  1039. string axis = param[0].ToString();
  1040. object[] objs = (object[])param[1];
  1041. string position = objs[1].ToString();
  1042. var result = CheckGotoPositionPreCondition(axis, position);
  1043. if (result.result)
  1044. {
  1045. return _positionRoutine.Start(result.axis, position) == RState.Running;
  1046. }
  1047. else
  1048. {
  1049. return false;
  1050. }
  1051. }
  1052. /// <summary>
  1053. /// 检验GotoPosition前置条件
  1054. /// </summary>
  1055. /// <param name="axis"></param>
  1056. /// <param name="position"></param>
  1057. /// <returns></returns>
  1058. private (bool result, JetAxisBase axis) CheckGotoPositionPreCondition(string axis, string position)
  1059. {
  1060. switch (axis)
  1061. {
  1062. case "Rotation":
  1063. return (_rotationAxis.CheckGotoPosition(position), _rotationAxis);
  1064. case "Arm":
  1065. return (_armAxis.CheckGotoPosition(position), _armAxis);
  1066. default:
  1067. return (false, null);
  1068. }
  1069. }
  1070. /// <summary>
  1071. /// GotoPosition超时
  1072. /// </summary>
  1073. /// <param name="param"></param>
  1074. /// <returns></returns>
  1075. private bool GotoPositionTimeout(object[] param)
  1076. {
  1077. RState ret = _positionRoutine.Monitor();
  1078. if (ret == RState.Failed || ret == RState.Timeout)
  1079. {
  1080. return true;
  1081. }
  1082. return ret == RState.End;
  1083. }
  1084. #endregion
  1085. #region 旋转
  1086. /// <summary>
  1087. /// 开始旋转
  1088. /// </summary>
  1089. /// <param name="param"></param>
  1090. /// <returns></returns>
  1091. private bool StartRotation(object[] param)
  1092. {
  1093. string axis = param[0].ToString();
  1094. object[] objs = (object[])param[1];
  1095. double time = double.Parse(objs[0].ToString());
  1096. double speed = double.Parse(objs[1].ToString());
  1097. return _rotationRoutine.Start(_rotationAxis, time, speed) == RState.Running;
  1098. }
  1099. /// <summary>
  1100. /// RotationTimeout
  1101. /// </summary>
  1102. /// <param name="param"></param>
  1103. /// <returns></returns>
  1104. private bool RotationTimeout(object[] param)
  1105. {
  1106. RState ret = _rotationRoutine.Monitor();
  1107. if (ret == RState.Failed || ret == RState.Timeout)
  1108. {
  1109. //PostMsg(SRDMSG.Error);
  1110. return true;
  1111. }
  1112. return ret == RState.End;
  1113. }
  1114. /// <summary>
  1115. /// 停止旋转
  1116. /// </summary>
  1117. /// <param name="param"></param>
  1118. /// <returns></returns>
  1119. private bool StopRotation(object[] param)
  1120. {
  1121. _rotationAxis.StopPositionOperation();
  1122. return _rotationAxis.Status == RState.Running;
  1123. }
  1124. /// <summary>
  1125. /// 停止旋转监控
  1126. /// </summary>
  1127. /// <param name="param"></param>
  1128. /// <returns></returns>
  1129. private bool StopRotationTimeout(object[] param)
  1130. {
  1131. RState ret = _rotationAxis.Status;
  1132. if (ret == RState.Failed || ret == RState.Timeout)
  1133. {
  1134. //PostMsg(SRDMSG.Error);
  1135. return true;
  1136. }
  1137. return ret == RState.End;
  1138. }
  1139. #endregion
  1140. #region PresenceTest
  1141. private bool PresenceTest(object[] param)
  1142. {
  1143. _recipeTime = 0;
  1144. return _presenceTestRoutine.Start(param) == RState.Running;
  1145. }
  1146. private bool PresenceTestTimeout(object[] param)
  1147. {
  1148. RState ret = _presenceTestRoutine.Monitor();
  1149. if (ret == RState.Failed || ret == RState.Timeout)
  1150. {
  1151. _isPresenceTesting = false;
  1152. PostMsg(SRDMSG.Error);
  1153. return false;
  1154. }
  1155. //设置IsPresenceTesting
  1156. if (ret == RState.Running)
  1157. {
  1158. _isPresenceTesting = true;
  1159. }
  1160. else
  1161. {
  1162. _isPresenceTesting = false;
  1163. }
  1164. return ret == RState.End;
  1165. }
  1166. /// <summary>
  1167. /// Abort PresenceTest
  1168. /// </summary>
  1169. /// <param name="param"></param>
  1170. /// <returns></returns>
  1171. private bool AbortPresenceTest(object[] param)
  1172. {
  1173. _presenceTestRoutine.Abort();
  1174. return true;
  1175. }
  1176. #endregion
  1177. /// <summary>
  1178. /// 获取当前子状态机
  1179. /// </summary>
  1180. private string GetCurrentStateMachine()
  1181. {
  1182. string state = "";
  1183. switch ((SRDState)fsm.State)
  1184. {
  1185. case SRDState.Init:
  1186. state = "Init";
  1187. break;
  1188. case SRDState.Initializing:
  1189. state = _initializeRoutine.CurrentStateMachine;
  1190. break;
  1191. case SRDState.Homing:
  1192. state = _homeRoutine.CurrentStateMachine;
  1193. break;
  1194. case SRDState.SwitchOning:
  1195. state = _switchOnRoutine.CurrentStateMachine;
  1196. break;
  1197. case SRDState.SwitchOffing:
  1198. state = _switchOffRoutine.CurrentStateMachine;
  1199. break;
  1200. case SRDState.Positioning:
  1201. state = _positionRoutine.CurrentStateMachine;
  1202. break;
  1203. case SRDState.Rotating:
  1204. state = _rotationRoutine.CurrentStateMachine;
  1205. break;
  1206. case SRDState.PresenceTesting:
  1207. state = _presenceTestRoutine.CurrentStateMachine;
  1208. break;
  1209. case SRDState.ProcessReciping:
  1210. state = _processRecipeRoutine.CurrentStateMachine;
  1211. break;
  1212. case SRDState.AWCCycling:
  1213. state = _awcCycleRoutine.CurrentStateMachine;
  1214. break;
  1215. default:
  1216. state = Enum.GetName(typeof(SRDState),fsm.State);
  1217. break;
  1218. }
  1219. return state;
  1220. }
  1221. /// <summary>
  1222. /// 设置IsAWCCycling
  1223. /// </summary>
  1224. /// <param name="flag"></param>
  1225. public void SetIsAWCCycling(bool flag)
  1226. {
  1227. _isAWCCycling = flag;
  1228. }
  1229. }
  1230. public enum SRDMSG
  1231. {
  1232. Initialize,
  1233. InitializeHome,
  1234. ProcessRecipe,
  1235. ResumeError,
  1236. SwitchOn,
  1237. SwitchOff,
  1238. HomeAll,
  1239. Error,
  1240. GoToSavedPosition,
  1241. Abort,
  1242. StartRotation,
  1243. StopRotation,
  1244. PresenceTestStart,
  1245. PresenceTestStop,
  1246. AWCCycleStart,
  1247. Init,
  1248. ProcessError,
  1249. Retry,
  1250. ConfirmComplete,
  1251. Loader,
  1252. Unloader
  1253. }
  1254. }