PUFEntity.cs 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Fsm;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.RT.Routine;
  7. using Aitex.Core.Utilities;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using MECF.Framework.Common.Utilities;
  11. using CyberX8_Core;
  12. using CyberX8_RT.Devices.AXIS;
  13. using CyberX8_RT.Devices.PUF;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using System.Windows.Interop;
  20. using MECF.Framework.Common.CommonData;
  21. using MECF.Framework.Common.Alarm;
  22. using Aitex.Core.Util;
  23. using MECF.Framework.Common.WaferHolder;
  24. namespace CyberX8_RT.Modules.PUF
  25. {
  26. public class PUFEntity : Entity, IEntity, IModuleEntity
  27. {
  28. #region 常量
  29. #endregion
  30. #region 属性
  31. public bool IsInRobotStation
  32. {
  33. get { return CheckPufVerticalAndRotationInRobot(); }
  34. }
  35. public ModuleName Module { get; private set; }
  36. public bool IsInit
  37. {
  38. get { return fsm.State == (int)PUFSTATE.Init; }
  39. }
  40. public bool IsIdle
  41. {
  42. get
  43. {
  44. return fsm.State == (int)PUFSTATE.Idle;
  45. }
  46. }
  47. public bool IsError
  48. {
  49. get { return fsm.State == (int)PUFSTATE.Error; }
  50. }
  51. public bool IsBusy
  52. {
  53. get { return !IsInit && !IsError && !IsIdle; }
  54. }
  55. public bool IsAuto { get; } = true;
  56. /// <summary>
  57. /// 是否为工程模式
  58. /// </summary>
  59. public bool IsEngineering { get; } = false;
  60. /// <summary>
  61. /// 是否为产品模式
  62. /// </summary>
  63. public bool IsProduction { get; } = true;
  64. /// <summary>
  65. /// SideA Wafer情况
  66. /// </summary>
  67. public bool SideAWaferPresent
  68. {
  69. get { return _pufVacuum.ChuckAWaferPresent; }
  70. }
  71. /// <summary>
  72. /// SideB Wafer情况
  73. /// </summary>
  74. public bool SideBWaferPresent
  75. {
  76. get { return _pufVacuum.ChuckBWaferPresent; }
  77. }
  78. public bool IsHomed
  79. {
  80. get { return _isHomed; }
  81. }
  82. /// <summary>
  83. /// 是否禁用
  84. /// </summary>
  85. public bool IsDisable { get; internal set; }
  86. /// <summary>
  87. /// Rotation是否SwitchOn
  88. /// </summary>
  89. public bool IsRotationSwitchOn
  90. {
  91. get { return _rotationAxis.IsSwitchOn; }
  92. }
  93. /// <summary>
  94. /// Vertical是否SwitchOn
  95. /// </summary>
  96. public bool IsVerticalSwitchOn
  97. {
  98. get { return _verticalAxis.IsSwitchOn; }
  99. }
  100. /// <summary>
  101. /// Flip是否SwitchOn
  102. /// </summary>
  103. public bool IsFlipSwitchOn
  104. {
  105. get { return _flipAxis.IsSwitchOn; }
  106. }
  107. /// <summary>
  108. /// 当前状态机状态
  109. /// </summary>
  110. public int State { get { return fsm.State; } }
  111. /// <summary>
  112. /// 是否回到安全位置
  113. /// </summary>
  114. public bool IsBackToParkStation
  115. {
  116. get
  117. {
  118. double flipPosition = _flipAxis.MotionData.MotorPosition;
  119. double rotationPosition = _rotationAxis.MotionData.MotorPosition;
  120. double verticalPosition=_verticalAxis.MotionData.MotorPosition;
  121. return (_flipAxis.CheckPositionIsInStation(flipPosition, "SideA")||Module==ModuleName.PUF2)
  122. && _rotationAxis.CheckPositionIsInStation(rotationPosition, "Park") &&
  123. _verticalAxis.CheckPositionIsInStation(verticalPosition, "Park");
  124. }
  125. }
  126. /// <summary>
  127. /// 是否Flip到达sideA
  128. /// </summary>
  129. public bool IsFlipSideA
  130. {
  131. get { return _flipAxis.CheckPositionIsInStation(_flipAxis.MotionData.MotorPosition, "SideA"); }
  132. }
  133. /// <summary>
  134. /// Vacuum状态
  135. /// </summary>
  136. public PufVacuum PufVacuum { get { return _pufVacuum; } }
  137. #endregion
  138. #region 内部变量
  139. private bool _isHomed;
  140. private JetAxisBase _flipAxis;
  141. private JetAxisBase _rotationAxis;
  142. private JetAxisBase _verticalAxis;
  143. private PufVacuum _pufVacuum;
  144. private IRoutine _currentRoutine;
  145. #endregion
  146. #region routine
  147. private PufHomeAllRoutine _homeAllRoutine;
  148. private PufSwitchOnRoutine _switchOnRoutine;
  149. private PufSwitchOffRoutine _switchOffRoutine;
  150. private PufCalibrateRoutine _calibrateRoutine;
  151. private PufPickFromLoaderRoutine _pickFromLoaderRoutine;
  152. private PufPlaceToLoaderRoutine _placeToLoaderRoutine;
  153. private PufPositionRoutine _positionRoutine;
  154. private PufGotoRobotForPlaceRoutine _gotoRobotForPlaceRoutine;
  155. private PufGotoRobotForPickRoutine _gotoRobotForPickRoutine;
  156. private PufReadyForRobotPlaceRoutine _readyForRobotPlaceRoutine;
  157. private PufReadyForSwapRoutine _readyForSwapRoutine;
  158. private PufSwapRoutine _swapRoutine;
  159. private PufReadyForRobotPickRoutine _readyForRobotPickRoutine;
  160. private PufBackToParkRoutine _backToParkRoutine;
  161. #endregion
  162. /// <summary>
  163. /// 构造函数
  164. /// </summary>
  165. /// <param name="module"></param>
  166. public PUFEntity(ModuleName module)
  167. {
  168. this.Module = module;
  169. _flipAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.Flip");
  170. _rotationAxis=DEVICE.GetDevice<JetAxisBase>($"{module}.Rotation");
  171. _verticalAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.Vertical");
  172. _pufVacuum = DEVICE.GetDevice<PufVacuum>($"{module}.Vacuum");
  173. _pufVacuum.OnVacuumLeak += PufVacuum_OnVacuumLeak;
  174. WaferManager.Instance.SubscribeLocation(Module, 2);
  175. InitialFsm();
  176. InitializeRoutine();
  177. }
  178. /// <summary>
  179. /// Vacuum Leak 异常
  180. /// </summary>
  181. /// <param name="sender"></param>
  182. /// <param name="e"></param>
  183. private void PufVacuum_OnVacuumLeak(object sender, string e)
  184. {
  185. PostMsg((int)PUFMSG.Error);
  186. }
  187. protected override bool Init()
  188. {
  189. InitialOperation();
  190. InitialDATA();
  191. return true;
  192. }
  193. private void InitialDATA()
  194. {
  195. DATA.Subscribe($"{Module}.FsmState", () => ((PUFSTATE)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  196. DATA.Subscribe($"{Module}.IsHomed", () => _isHomed,SubscriptionAttribute.FLAG.IgnoreSaveDB);
  197. DATA.Subscribe($"{Module}.IsError", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  198. DATA.Subscribe($"{Module}.IsInRobotStation", () => IsInRobotStation, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  199. DATA.Subscribe($"{Module}.State", () => ((PUFSTATE)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  200. }
  201. /// <summary>
  202. /// 初始化操作
  203. /// </summary>
  204. private void InitialOperation()
  205. {
  206. OP.Subscribe($"{Module}.Abort", (cmd, args) => { return CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(), (int)PUFMSG.Abort); });
  207. OP.Subscribe($"{Module}.ClearError", (cmd, args) => { return CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(), (int)PUFMSG.ResumeError); });
  208. OP.Subscribe($"{Module}.{MotionOperation.HomeAll}", (cmd, args) => { return CheckToPostMessage<PUFSTATE,PUFMSG>(eEvent.ERR_PUF,Module.ToString(),(int)PUFMSG.HomeAll);});
  209. OP.Subscribe($"{Module}.{MotionOperation.SwitchOff}", (cmd, args) => { return CheckToPostMessage<PUFSTATE,PUFMSG>(eEvent.ERR_PUF,Module.ToString(),(int)PUFMSG.SwitchOff); });
  210. OP.Subscribe($"{Module}.{MotionOperation.SwitchOn}", (cmd, args) => { return CheckToPostMessage<PUFSTATE,PUFMSG>(eEvent.ERR_PUF,Module.ToString(),(int)PUFMSG.SwitchOn); });
  211. OP.Subscribe($"{Module}.{MotionOperation.Calibrate}", (cmd, args) => { return CheckToPostMessage<PUFSTATE,PUFMSG>(eEvent.ERR_PUF,Module.ToString(),(int)PUFMSG.Calibrate, args);});
  212. OP.Subscribe($"{Module}.{MotionOperation.Pick}", (cmd, args) => { return CheckToPostMessage<PUFSTATE,PUFMSG>(eEvent.ERR_PUF,Module.ToString(),(int)PUFMSG.PickFromLoader, args); });
  213. OP.Subscribe($"{Module}.{MotionOperation.Place}", (cmd, args) => { return CheckToPostMessage<PUFSTATE,PUFMSG>(eEvent.ERR_PUF,Module.ToString(),(int)PUFMSG.PlaceToLoader, args); });
  214. OP.Subscribe($"{Module}.GotoRobotPositionForPlace", (cmd, args) => { return CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(), (int)PUFMSG.GotoRobotPositionForPlace, args); });
  215. OP.Subscribe($"{Module}.GotoRobotPositionForPick", (cmd, args) => { return CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(), (int)PUFMSG.GotoRobotPositionForPick, args); });
  216. }
  217. /// <summary>
  218. /// 初始化Routine
  219. /// </summary>
  220. private void InitializeRoutine()
  221. {
  222. _homeAllRoutine = new PufHomeAllRoutine(Module,this);
  223. _switchOnRoutine = new PufSwitchOnRoutine(Module);
  224. _switchOffRoutine= new PufSwitchOffRoutine(Module);
  225. _calibrateRoutine = new PufCalibrateRoutine(Module);
  226. _pickFromLoaderRoutine = new PufPickFromLoaderRoutine(Module.ToString());
  227. _placeToLoaderRoutine=new PufPlaceToLoaderRoutine(Module.ToString());
  228. _positionRoutine = new PufPositionRoutine(Module);
  229. _gotoRobotForPlaceRoutine = new PufGotoRobotForPlaceRoutine(Module.ToString());
  230. _gotoRobotForPickRoutine=new PufGotoRobotForPickRoutine(Module.ToString());
  231. _readyForRobotPlaceRoutine=new PufReadyForRobotPlaceRoutine(Module.ToString());
  232. _readyForSwapRoutine=new PufReadyForSwapRoutine(Module.ToString());
  233. _swapRoutine=new PufSwapRoutine(Module.ToString());
  234. _readyForRobotPickRoutine=new PufReadyForRobotPickRoutine(Module.ToString());
  235. _backToParkRoutine=new PufBackToParkRoutine(Module.ToString());
  236. }
  237. /// <summary>
  238. /// 初始化状态机
  239. /// </summary>
  240. private void InitialFsm()
  241. {
  242. fsm = new StateMachine<PUFEntity>(Module.ToString(), (int)PUFSTATE.Init, 20);
  243. fsm.EnableRepeatedMsg(true);
  244. AnyStateTransition(PUFMSG.Error, EnterError, PUFSTATE.Error);
  245. AnyStateTransition(PUFMSG.ReturnIdle, (param) => { return true; }, PUFSTATE.Idle);
  246. AnyStateTransition(PUFMSG.Abort, Abort, PUFSTATE.Init);
  247. AnyStateTransition(PUFMSG.HomeAll, HomeAll, PUFSTATE.Homing);
  248. Transition(PUFSTATE.Error, PUFMSG.ResumeError, ResumeError, PUFSTATE.Init);
  249. //SwitchOn
  250. Transition(PUFSTATE.Init, PUFMSG.SwitchOn, SwitchOnAll, PUFSTATE.SwitchOning);
  251. Transition(PUFSTATE.Idle, PUFMSG.SwitchOn, SwitchOnAll, PUFSTATE.SwitchOning);
  252. Transition(PUFSTATE.Error, PUFMSG.SwitchOn, SwitchOnAll, PUFSTATE.SwitchOning);
  253. Transition(PUFSTATE.SwitchOning, FSM_MSG.TIMER, SwitchOnTimeout, PUFSTATE.Init);
  254. //SwitchOff
  255. Transition(PUFSTATE.Init, PUFMSG.SwitchOff, SwitchOffAll, PUFSTATE.SwitchOffing);
  256. Transition(PUFSTATE.Idle, PUFMSG.SwitchOff, SwitchOffAll, PUFSTATE.SwitchOffing);
  257. Transition(PUFSTATE.Error, PUFMSG.SwitchOff, SwitchOffAll, PUFSTATE.SwitchOffing);
  258. Transition(PUFSTATE.SwitchOffing, FSM_MSG.TIMER, SwitchOffTimeout, PUFSTATE.Init);
  259. // Home
  260. Transition(PUFSTATE.Homing, FSM_MSG.TIMER, HomingTimeout, PUFSTATE.Idle);
  261. //Calibrate
  262. Transition(PUFSTATE.Idle, PUFMSG.Calibrate, Calibrate, PUFSTATE.Calibrating);
  263. Transition(PUFSTATE.Calibrating, FSM_MSG.TIMER, CalibrateTimeout, PUFSTATE.Idle);
  264. //PickFromLoader
  265. Transition(PUFSTATE.Idle, PUFMSG.PickFromLoader, PickFromLoader, PUFSTATE.Picking);
  266. Transition(PUFSTATE.Picking, FSM_MSG.TIMER, PickTimeout, PUFSTATE.Idle);
  267. //PlaceToLoader
  268. Transition(PUFSTATE.Idle, PUFMSG.PlaceToLoader, PlaceToLoader, PUFSTATE.Placing);
  269. Transition(PUFSTATE.Placing, FSM_MSG.TIMER, PlaceToLoaderMonitor, PUFSTATE.Idle);
  270. //GotoRobotPositionForPlace
  271. Transition(PUFSTATE.Idle, PUFMSG.GotoRobotPositionForPlace, GotoRobotPositionForPlace, PUFSTATE.GotoRobotPositionForPlace);
  272. Transition(PUFSTATE.GotoRobotPositionForPlace, FSM_MSG.TIMER, GotoRobotPositionForPlaceMonitor, PUFSTATE.Idle);
  273. //GotoRobotPositionForPick
  274. Transition(PUFSTATE.Idle, PUFMSG.GotoRobotPositionForPick, GotoRobotPositionForPick, PUFSTATE.GotoRobotPositionForPick);
  275. Transition(PUFSTATE.GotoRobotPositionForPick, FSM_MSG.TIMER, GotoRobotPositionForPickMonitor, PUFSTATE.Idle);
  276. //ready for robot place
  277. Transition(PUFSTATE.Idle, PUFMSG.ReadyForRobotPlace, ReadyForRobotPlace, PUFSTATE.WaitForRobotPlacing);
  278. Transition(PUFSTATE.WaitForRobotPlacing, FSM_MSG.TIMER, ReadyForRobotPlaceMonitor, PUFSTATE.WaitForRobotPlace);
  279. Transition(PUFSTATE.WaitForRobotPlace, PUFMSG.ReadyForSwap, ReadyForSwap, PUFSTATE.WaitForSwaping);
  280. Transition(PUFSTATE.WaitForSwaping, FSM_MSG.TIMER, ReadyForSwapMonitor, PUFSTATE.WaitForSwap);
  281. Transition(PUFSTATE.WaitForSwap, PUFMSG.Swap, Swap, PUFSTATE.Swaping);
  282. Transition(PUFSTATE.Swaping, FSM_MSG.TIMER, SwapMonitor, PUFSTATE.AferSwapParkStation);
  283. Transition(PUFSTATE.AferSwapParkStation, PUFMSG.ReadyForRobotPick, ReadyForRobotPick, PUFSTATE.WaitForRobotPicking);
  284. Transition(PUFSTATE.WaitForRobotPicking, FSM_MSG.TIMER, ReadyForRobotPickMonitor, PUFSTATE.WaitForRobotPick);
  285. Transition(PUFSTATE.WaitForRobotPick, PUFMSG.RobotPickComplete, BackToParkStation, PUFSTATE.BackToPackStationing);
  286. Transition(PUFSTATE.BackToPackStationing, FSM_MSG.TIMER, BackToParkStationMonitor, PUFSTATE.Idle);
  287. Transition(PUFSTATE.Idle, PUFMSG.FlipSideA, FlipSideA, PUFSTATE.Fliping);
  288. Transition(PUFSTATE.Fliping,FSM_MSG.TIMER,FlipSideAMonitor,PUFSTATE.Idle);
  289. //Retry
  290. Transition(PUFSTATE.Error, PUFMSG.Retry, NullFunc, PUFSTATE.Retrying);
  291. Transition(PUFSTATE.Retrying, FSM_MSG.TIMER, PufRetry,PUFSTATE.Retrying);
  292. Transition(PUFSTATE.Retrying, PUFMSG.ReadyForRobotPlace, RetryReadyForRobotPlace, PUFSTATE.WaitForRobotPlacing);
  293. Transition(PUFSTATE.Retrying, PUFMSG.ReadyForSwap, RetryReadyForSwap, PUFSTATE.WaitForSwaping);
  294. Transition(PUFSTATE.Retrying, PUFMSG.Swap, RetrySwap, PUFSTATE.Swaping);
  295. Transition(PUFSTATE.Retrying, PUFMSG.ReadyForRobotPick, RetryReadyForRobotPick, PUFSTATE.WaitForRobotPicking);
  296. Transition(PUFSTATE.Retrying, PUFMSG.RobotPickComplete, RetryBackToParkStation, PUFSTATE.BackToPackStationing);
  297. //ConfirmComplete
  298. Transition(PUFSTATE.Error, PUFMSG.ConfirmComplete, NullFunc, PUFSTATE.ConfirmCompleting);
  299. Transition(PUFSTATE.Init, PUFMSG.ConfirmComplete, ClearModuleAlarm, PUFSTATE.Init);
  300. Transition(PUFSTATE.Idle, PUFMSG.ConfirmComplete, ClearModuleAlarm, PUFSTATE.Idle);
  301. Transition(PUFSTATE.ConfirmCompleting, FSM_MSG.TIMER, ConfirmComplete, PUFSTATE.ConfirmCompleting);
  302. Transition(PUFSTATE.ConfirmCompleting, PUFMSG.ReadyForRobotPlace, ConfirmReadyForRobotPlace, PUFSTATE.WaitForRobotPlace);
  303. Transition(PUFSTATE.ConfirmCompleting, PUFMSG.ReadyForSwap, ConfirmReadyForSwap, PUFSTATE.WaitForSwap);
  304. Transition(PUFSTATE.ConfirmCompleting, PUFMSG.Swap, ConfirmSwap, PUFSTATE.Swaping);
  305. Transition(PUFSTATE.ConfirmCompleting, PUFMSG.ReadyForRobotPick, ConfirmReadyForRobotPick, PUFSTATE.WaitForRobotPick);
  306. Transition(PUFSTATE.ConfirmCompleting, PUFMSG.RobotPickComplete, ConfirmBackToParkStation, PUFSTATE.Idle);
  307. EnumLoop<PUFSTATE>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  308. EnumLoop<PUFMSG>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  309. }
  310. private bool EnterError(object[] param)
  311. {
  312. return true;
  313. }
  314. /// <summary>
  315. /// 恢复错误
  316. /// </summary>
  317. /// <param name="param"></param>
  318. /// <returns></returns>
  319. private bool ResumeError(object[] param)
  320. {
  321. if (_isHomed)
  322. {
  323. PostMsg(PUFMSG.ReturnIdle);
  324. return false;
  325. }
  326. return true;
  327. }
  328. #region Abort
  329. private bool Abort(object parameter)
  330. {
  331. bool preHomed = IsHomed;
  332. _flipAxis.StopPositionOperation();
  333. _rotationAxis.StopPositionOperation();
  334. _verticalAxis.StopPositionOperation();
  335. if(_currentRoutine!=null)
  336. {
  337. _currentRoutine.Abort();
  338. _currentRoutine = null;
  339. }
  340. if (preHomed)
  341. {
  342. PostMsg(PUFMSG.ReturnIdle);
  343. return false;
  344. }
  345. return true;
  346. }
  347. #endregion
  348. #region Switch On
  349. /// <summary>
  350. /// SwitchAll
  351. /// </summary>
  352. /// <param name="param"></param>
  353. /// <returns></returns>
  354. private bool SwitchOnAll(object[] param)
  355. {
  356. return _switchOnRoutine.Start() == RState.Running;
  357. }
  358. private bool SwitchOnTimeout(object[] param)
  359. {
  360. RState ret = _switchOnRoutine.Monitor();
  361. if (ret == RState.Failed || ret == RState.Timeout)
  362. {
  363. PostMsg(PUFMSG.Error);
  364. return false;
  365. }
  366. bool result= ret == RState.End;
  367. if(result)
  368. {
  369. _isHomed = false;
  370. }
  371. return result;
  372. }
  373. #endregion
  374. #region Switch Off
  375. /// <summary>
  376. /// SwitchAll
  377. /// </summary>
  378. /// <param name="param"></param>
  379. /// <returns></returns>
  380. private bool SwitchOffAll(object[] param)
  381. {
  382. return _switchOffRoutine.Start() == RState.Running;
  383. }
  384. private bool SwitchOffTimeout(object[] param)
  385. {
  386. RState ret = _switchOffRoutine.Monitor();
  387. if (ret == RState.Failed || ret == RState.Timeout)
  388. {
  389. PostMsg(PUFMSG.Error);
  390. return false;
  391. }
  392. bool result= ret == RState.End;
  393. if(result)
  394. {
  395. _isHomed= false;
  396. }
  397. return result;
  398. }
  399. #endregion
  400. #region Home
  401. /// <summary>
  402. /// HomeAll
  403. /// </summary>
  404. /// <param name="param"></param>
  405. /// <returns></returns>
  406. private bool HomeAll(object[] param)
  407. {
  408. _isHomed = false;
  409. bool result= _homeAllRoutine.Start() == RState.Running;
  410. if(result)
  411. {
  412. _currentRoutine = _homeAllRoutine;
  413. }
  414. return result;
  415. }
  416. /// <summary>
  417. /// Home超时
  418. /// </summary>
  419. /// <param name="param"></param>
  420. /// <returns></returns>
  421. private bool HomingTimeout(object[] param)
  422. {
  423. RState ret = _homeAllRoutine.Monitor();
  424. if (ret == RState.Failed || ret == RState.Timeout)
  425. {
  426. _currentRoutine = null;
  427. PostMsg(PUFMSG.Error);
  428. _isHomed = false;
  429. return false;
  430. }
  431. bool result = ret == RState.End;
  432. if (result)
  433. {
  434. _currentRoutine = null;
  435. _isHomed = true;
  436. }
  437. return result;
  438. }
  439. #endregion
  440. #region Calibrate
  441. private bool Calibrate(object[] param)
  442. {
  443. _calibrateRoutine.Start(param);
  444. return true;
  445. }
  446. private bool CalibrateTimeout(object[] param)
  447. {
  448. RState ret = _calibrateRoutine.Monitor();
  449. if (ret == RState.Failed || ret == RState.Timeout)
  450. {
  451. return true;
  452. }
  453. return ret == RState.End;
  454. }
  455. #endregion
  456. #region Pick
  457. private bool PickFromLoader(object[] param)
  458. {
  459. bool result= _pickFromLoaderRoutine.Start(param)==RState.Running;
  460. if(result)
  461. {
  462. _currentRoutine = _pickFromLoaderRoutine;
  463. }
  464. return result;
  465. }
  466. private bool PickTimeout(object[] param)
  467. {
  468. //RState ret = _pufNoWaferPickRoutine.Monitor();
  469. RState ret = _pickFromLoaderRoutine.Monitor();
  470. if (ret == RState.Failed || ret == RState.Timeout)
  471. {
  472. PostMsg(PUFMSG.Error);
  473. return false;
  474. }
  475. bool result = ret == RState.End;
  476. if(result)
  477. {
  478. _currentRoutine = null;
  479. }
  480. return result;
  481. }
  482. #endregion
  483. #region Place
  484. /// <summary>
  485. /// 放片至Loader
  486. /// </summary>
  487. /// <param name="param"></param>
  488. /// <returns></returns>
  489. private bool PlaceToLoader(object[] param)
  490. {
  491. bool result = _placeToLoaderRoutine.Start(param) == RState.Running;
  492. if(result)
  493. {
  494. _currentRoutine = _placeToLoaderRoutine;
  495. }
  496. return result;
  497. }
  498. /// <summary>
  499. /// 监控放片至Loader
  500. /// </summary>
  501. /// <param name="param"></param>
  502. /// <returns></returns>
  503. private bool PlaceToLoaderMonitor(object[] param)
  504. {
  505. //RState ret = _pufNoWaferPickRoutine.Monitor();
  506. RState ret = _placeToLoaderRoutine.Monitor();
  507. if (ret == RState.Failed || ret == RState.Timeout)
  508. {
  509. _currentRoutine = null;
  510. PostMsg(PUFMSG.Error);
  511. return false;
  512. }
  513. bool result = ret == RState.End;
  514. if(result)
  515. {
  516. _currentRoutine = null;
  517. }
  518. return result;
  519. }
  520. #endregion
  521. #region GotoRobotPositionForPlace
  522. /// <summary>
  523. /// Goto Robot Position For Place
  524. /// </summary>
  525. /// <param name="param"></param>
  526. /// <returns></returns>
  527. private bool GotoRobotPositionForPlace(object[] param)
  528. {
  529. bool result= _gotoRobotForPlaceRoutine.Start(param)==RState.Running;
  530. if(result)
  531. {
  532. _currentRoutine = _gotoRobotForPlaceRoutine;
  533. }
  534. return result;
  535. }
  536. /// <summary>
  537. /// Goto Robot Position For Place监控
  538. /// </summary>
  539. /// <param name="param"></param>
  540. /// <returns></returns>
  541. private bool GotoRobotPositionForPlaceMonitor(object[] param)
  542. {
  543. RState ret = _gotoRobotForPlaceRoutine.Monitor();
  544. if (ret == RState.Failed || ret == RState.Timeout)
  545. {
  546. _currentRoutine = null;
  547. PostMsg(PUFMSG.Error);
  548. return false;
  549. }
  550. bool result= ret == RState.End;
  551. if(result)
  552. {
  553. _currentRoutine = null;
  554. }
  555. return result;
  556. }
  557. #endregion
  558. #region GotoRobotPositionForPick
  559. /// <summary>
  560. /// Goto Robot Position For Pick
  561. /// </summary>
  562. /// <param name="param"></param>
  563. /// <returns></returns>
  564. private bool GotoRobotPositionForPick(object[] param)
  565. {
  566. bool result= _gotoRobotForPickRoutine.Start(param) == RState.Running;
  567. if(result)
  568. {
  569. _currentRoutine = _gotoRobotForPickRoutine;
  570. }
  571. return result;
  572. }
  573. /// <summary>
  574. /// Goto Robot Position For Pick监控
  575. /// </summary>
  576. /// <param name="param"></param>
  577. /// <returns></returns>
  578. private bool GotoRobotPositionForPickMonitor(object[] param)
  579. {
  580. RState ret = _gotoRobotForPickRoutine.Monitor();
  581. if (ret == RState.Failed || ret == RState.Timeout)
  582. {
  583. _currentRoutine = null;
  584. PostMsg(PUFMSG.Error);
  585. return false;
  586. }
  587. bool result = ret == RState.End;
  588. if(result)
  589. {
  590. _currentRoutine = null;
  591. }
  592. return result;
  593. }
  594. #endregion
  595. #region ReadyForRobotPlace
  596. /// <summary>
  597. /// Ready For Robot Place
  598. /// </summary>
  599. /// <param name="param"></param>
  600. /// <returns></returns>
  601. private bool ReadyForRobotPlace(object[] param)
  602. {
  603. bool result = _readyForRobotPlaceRoutine.Start(param)==RState.Running;
  604. if(result)
  605. {
  606. _currentRoutine = _readyForRobotPlaceRoutine;
  607. }
  608. return result;
  609. }
  610. /// <summary>
  611. /// Ready For Robot Place
  612. /// </summary>
  613. /// <param name="param"></param>
  614. /// <returns></returns>
  615. private bool RetryReadyForRobotPlace(object[] param)
  616. {
  617. int stepIndex = (int)param[0];
  618. bool result = _readyForRobotPlaceRoutine.Retry(stepIndex) == RState.Running;
  619. if (result)
  620. {
  621. _currentRoutine = _readyForRobotPlaceRoutine;
  622. }
  623. return result;
  624. }
  625. /// <summary>
  626. /// ReadyForRobotPlace监控
  627. /// </summary>
  628. /// <param name="param"></param>
  629. /// <returns></returns>
  630. private bool ReadyForRobotPlaceMonitor(object[] param)
  631. {
  632. RState ret = _readyForRobotPlaceRoutine.Monitor();
  633. if (ret == RState.Failed || ret == RState.Timeout)
  634. {
  635. _currentRoutine = null;
  636. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  637. {
  638. AlarmList alarmList = new AlarmList(Module.ToString(), ((PUFSTATE)fsm.State).ToString(), (int)PUFMSG.ReadyForRobotPlace, _readyForRobotPlaceRoutine.ErrorMsg, _readyForRobotPlaceRoutine.ErrorStep, (int)AlarmType.Error);
  639. AlarmListManager.Instance.AddAlarm(alarmList);
  640. }
  641. PostMsg(PUFMSG.Error);
  642. return false;
  643. }
  644. bool result= ret == RState.End;
  645. if(result)
  646. {
  647. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), PUFSTATE.WaitForRobotPlacing.ToString());
  648. _currentRoutine = null;
  649. }
  650. return result;
  651. }
  652. /// <summary>
  653. /// 确认ReadyForRobotPlace
  654. /// </summary>
  655. /// <param name="param"></param>
  656. /// <returns></returns>
  657. private bool ConfirmReadyForRobotPlace(object[] param)
  658. {
  659. bool result = _readyForRobotPlaceRoutine.CheckCompleteCondition();
  660. if (!result)
  661. {
  662. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  663. {
  664. AlarmList alarmList = new AlarmList(Module.ToString(), ((PUFSTATE)fsm.State).ToString(), (int)PUFMSG.ReadyForRobotPlace,
  665. _readyForRobotPlaceRoutine.ErrorMsg, _readyForRobotPlaceRoutine.ErrorStep, (int)AlarmType.Error);
  666. AlarmListManager.Instance.AddAlarm(alarmList);
  667. }
  668. PostMsg(PUFMSG.Error);
  669. }
  670. else
  671. {
  672. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  673. {
  674. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), PUFSTATE.WaitForRobotPlacing.ToString());
  675. }
  676. }
  677. return result;
  678. }
  679. #endregion
  680. #region Ready for Swap
  681. /// <summary>
  682. /// Ready For Swap
  683. /// </summary>
  684. /// <param name="param"></param>
  685. /// <returns></returns>
  686. private bool ReadyForSwap(object[] param)
  687. {
  688. bool result= _readyForSwapRoutine.Start(param)==RState.Running;
  689. if(result)
  690. {
  691. _currentRoutine = _readyForSwapRoutine;
  692. }
  693. return result;
  694. }
  695. /// <summary>
  696. /// Retry Ready For Swap
  697. /// </summary>
  698. /// <param name="param"></param>
  699. /// <returns></returns>
  700. private bool RetryReadyForSwap(object[] param)
  701. {
  702. int stepIndex = (int)param[0];
  703. bool result = _readyForSwapRoutine.Retry(stepIndex) == RState.Running;
  704. if (result)
  705. {
  706. _currentRoutine = _readyForSwapRoutine;
  707. }
  708. return result;
  709. }
  710. /// <summary>
  711. /// Ready For Swap 监控
  712. /// </summary>
  713. /// <param name="param"></param>
  714. /// <returns></returns>
  715. private bool ReadyForSwapMonitor(object[] param)
  716. {
  717. RState ret = _readyForSwapRoutine.Monitor();
  718. if (ret == RState.Failed || ret == RState.Timeout)
  719. {
  720. _currentRoutine = null;
  721. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  722. {
  723. AlarmList alarmList = new AlarmList(Module.ToString(), ((PUFSTATE)fsm.State).ToString(), (int)PUFMSG.ReadyForSwap,
  724. _readyForSwapRoutine.ErrorMsg, _readyForSwapRoutine.ErrorStep, (int)AlarmType.Error);
  725. AlarmListManager.Instance.AddAlarm(alarmList);
  726. }
  727. PostMsg(PUFMSG.Error);
  728. return false;
  729. }
  730. bool result= ret == RState.End;
  731. if(result)
  732. {
  733. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), PUFSTATE.WaitForSwaping.ToString());
  734. _currentRoutine = null;
  735. }
  736. return result;
  737. }
  738. /// <summary>
  739. /// 确认Ready For Swap
  740. /// </summary>
  741. /// <param name="param"></param>
  742. /// <returns></returns>
  743. private bool ConfirmReadyForSwap(object[] param)
  744. {
  745. bool result = _readyForSwapRoutine.CheckCompleteCondition();
  746. if (!result)
  747. {
  748. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  749. {
  750. AlarmList alarmList = new AlarmList(Module.ToString(), ((PUFSTATE)fsm.State).ToString(), (int)PUFMSG.ReadyForSwap,
  751. _readyForSwapRoutine.ErrorMsg, _readyForSwapRoutine.ErrorStep, (int)AlarmType.Error);
  752. AlarmListManager.Instance.AddAlarm(alarmList);
  753. }
  754. PostMsg(PUFMSG.Error);
  755. }
  756. else
  757. {
  758. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  759. {
  760. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), PUFSTATE.WaitForSwaping.ToString());
  761. }
  762. }
  763. return result;
  764. }
  765. #endregion
  766. #region Swap
  767. /// <summary>
  768. /// Swap
  769. /// </summary>
  770. /// <param name="param"></param>
  771. /// <returns></returns>
  772. private bool Swap(object[] param)
  773. {
  774. bool result= _swapRoutine.Start(param)==RState.Running;
  775. if(result)
  776. {
  777. _currentRoutine = _swapRoutine;
  778. }
  779. return result;
  780. }
  781. /// <summary>
  782. /// Retry Swap
  783. /// </summary>
  784. /// <param name="param"></param>
  785. /// <returns></returns>
  786. private bool RetrySwap(object[] param)
  787. {
  788. int stepIndex = (int)param[0];
  789. bool result = _swapRoutine.Retry(stepIndex) == RState.Running;
  790. if (result)
  791. {
  792. _currentRoutine = _swapRoutine;
  793. }
  794. return result;
  795. }
  796. /// <summary>
  797. /// Swap监控
  798. /// </summary>
  799. /// <param name="param"></param>
  800. /// <returns></returns>
  801. private bool SwapMonitor(object[] param)
  802. {
  803. RState ret = _swapRoutine.Monitor();
  804. if (ret == RState.Failed || ret == RState.Timeout)
  805. {
  806. _currentRoutine = null;
  807. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  808. {
  809. AlarmList alarmList = new AlarmList(Module.ToString(), ((PUFSTATE)fsm.State).ToString(), (int)PUFMSG.Swap,
  810. _swapRoutine.ErrorMsg, _swapRoutine.ErrorStep, (int)AlarmType.Error);
  811. AlarmListManager.Instance.AddAlarm(alarmList);
  812. }
  813. PostMsg(PUFMSG.Error);
  814. return false;
  815. }
  816. bool result = ret == RState.End;
  817. if(result)
  818. {
  819. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), PUFSTATE.Swaping.ToString());
  820. _currentRoutine = null;
  821. }
  822. return result;
  823. }
  824. /// <summary>
  825. /// 确认ReadyForRobotPick
  826. /// </summary>
  827. /// <param name="param"></param>
  828. /// <returns></returns>
  829. private bool ConfirmSwap(object[] param)
  830. {
  831. bool result = _swapRoutine.CheckCompleteCondition();
  832. if (!result)
  833. {
  834. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  835. {
  836. AlarmList alarmList = new AlarmList(Module.ToString(), ((PUFSTATE)fsm.State).ToString(), (int)PUFMSG.Swap,
  837. _readyForRobotPickRoutine.ErrorMsg, _readyForRobotPickRoutine.ErrorStep, (int)AlarmType.Error);
  838. AlarmListManager.Instance.AddAlarm(alarmList);
  839. }
  840. PostMsg(PUFMSG.Error);
  841. }
  842. else
  843. {
  844. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  845. {
  846. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), PUFSTATE.Swaping.ToString());
  847. }
  848. }
  849. return result;
  850. }
  851. #endregion
  852. #region ReadyForRobotPIck
  853. /// <summary>
  854. /// Ready For Robot Pick
  855. /// </summary>
  856. /// <param name="param"></param>
  857. /// <returns></returns>
  858. private bool ReadyForRobotPick(object[] param)
  859. {
  860. bool result= _readyForRobotPickRoutine.Start(param) == RState.Running;
  861. if(result)
  862. {
  863. _currentRoutine = _readyForRobotPickRoutine;
  864. }
  865. return result;
  866. }
  867. /// <summary>
  868. /// retry Ready For Robot Pick
  869. /// </summary>
  870. /// <param name="param"></param>
  871. /// <returns></returns>
  872. private bool RetryReadyForRobotPick(object[] param)
  873. {
  874. int stepIndex = (int)param[0];
  875. bool result = _readyForRobotPickRoutine.Retry(stepIndex) == RState.Running;
  876. if (result)
  877. {
  878. _currentRoutine = _readyForRobotPickRoutine;
  879. }
  880. return result;
  881. }
  882. /// <summary>
  883. /// ReadyForRobotPick监控
  884. /// </summary>
  885. /// <param name="param"></param>
  886. /// <returns></returns>
  887. private bool ReadyForRobotPickMonitor(object[] param)
  888. {
  889. RState ret = _readyForRobotPickRoutine.Monitor();
  890. if (ret == RState.Failed || ret == RState.Timeout)
  891. {
  892. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  893. {
  894. AlarmList alarmList = new AlarmList(Module.ToString(), ((PUFSTATE)fsm.State).ToString(), (int)PUFMSG.ReadyForRobotPick,
  895. _readyForRobotPickRoutine.ErrorMsg, _readyForRobotPickRoutine.ErrorStep, (int)AlarmType.Error);
  896. AlarmListManager.Instance.AddAlarm(alarmList);
  897. }
  898. PostMsg(PUFMSG.Error);
  899. _currentRoutine = _readyForRobotPickRoutine;
  900. return false;
  901. }
  902. bool result= ret == RState.End;
  903. if(result)
  904. {
  905. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), PUFSTATE.WaitForRobotPicking.ToString());
  906. _currentRoutine = null;
  907. }
  908. return result;
  909. }
  910. /// <summary>
  911. /// 确认ReadyForRobotPick
  912. /// </summary>
  913. /// <param name="param"></param>
  914. /// <returns></returns>
  915. private bool ConfirmReadyForRobotPick(object[] param)
  916. {
  917. bool result = _readyForRobotPickRoutine.CheckCompleteCondition();
  918. if (!result)
  919. {
  920. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  921. {
  922. AlarmList alarmList = new AlarmList(Module.ToString(), ((PUFSTATE)fsm.State).ToString(), (int)PUFMSG.ReadyForRobotPick,
  923. _readyForRobotPickRoutine.ErrorMsg, _readyForRobotPickRoutine.ErrorStep, (int)AlarmType.Error);
  924. AlarmListManager.Instance.AddAlarm(alarmList);
  925. }
  926. PostMsg(PUFMSG.Error);
  927. }
  928. else
  929. {
  930. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  931. {
  932. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), PUFSTATE.ConfirmCompleting.ToString());
  933. }
  934. }
  935. return result;
  936. }
  937. #endregion
  938. #region BackToParkStation
  939. /// <summary>
  940. /// Back to park station
  941. /// </summary>
  942. /// <param name="param"></param>
  943. /// <returns></returns>
  944. private bool BackToParkStation(object[] param)
  945. {
  946. bool result= _backToParkRoutine.Start(param) == RState.Running;
  947. if(result)
  948. {
  949. _currentRoutine = _backToParkRoutine;
  950. }
  951. return true;
  952. }
  953. /// <summary>
  954. /// Retry Back to park station
  955. /// </summary>
  956. /// <param name="param"></param>
  957. /// <returns></returns>
  958. private bool RetryBackToParkStation(object[] param)
  959. {
  960. int stepIdex = (int)param[0];
  961. bool result = _backToParkRoutine.Retry(stepIdex) == RState.Running;
  962. if (result)
  963. {
  964. _currentRoutine = _backToParkRoutine;
  965. }
  966. return true;
  967. }
  968. /// <summary>
  969. /// BackToParkStation监控
  970. /// </summary>
  971. /// <param name="param"></param>
  972. /// <returns></returns>
  973. private bool BackToParkStationMonitor(object[] param)
  974. {
  975. RState ret = _backToParkRoutine.Monitor();
  976. if (ret == RState.Failed || ret == RState.Timeout)
  977. {
  978. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  979. {
  980. AlarmList alarmList = new AlarmList(Module.ToString(), ((PUFSTATE)fsm.State).ToString(), (int)PUFMSG.RobotPickComplete,
  981. _backToParkRoutine.ErrorMsg, _backToParkRoutine.ErrorStep, (int)AlarmType.Error);
  982. AlarmListManager.Instance.AddAlarm(alarmList);
  983. }
  984. PostMsg(PUFMSG.Error);
  985. _currentRoutine = null;
  986. return false;
  987. }
  988. bool result= ret == RState.End;
  989. if(result)
  990. {
  991. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), PUFSTATE.BackToPackStationing.ToString());
  992. _currentRoutine = null;
  993. }
  994. return result;
  995. }
  996. /// <summary>
  997. /// 确认BackToParkStation
  998. /// </summary>
  999. /// <param name="param"></param>
  1000. /// <returns></returns>
  1001. private bool ConfirmBackToParkStation(object[] param)
  1002. {
  1003. bool result = _backToParkRoutine.CheckCompleteCondition();
  1004. if (!result)
  1005. {
  1006. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  1007. {
  1008. AlarmList alarmList = new AlarmList(Module.ToString(), ((PUFSTATE)fsm.State).ToString(), (int)PUFMSG.RobotPickComplete,
  1009. _backToParkRoutine.ErrorMsg, _backToParkRoutine.ErrorStep, (int)AlarmType.Error);
  1010. AlarmListManager.Instance.AddAlarm(alarmList);
  1011. }
  1012. PostMsg(PUFMSG.Error);
  1013. }
  1014. else
  1015. {
  1016. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  1017. {
  1018. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), PUFSTATE.BackToPackStationing.ToString());
  1019. }
  1020. }
  1021. return result;
  1022. }
  1023. #endregion
  1024. #region Retry
  1025. /// <summary>
  1026. /// Retry
  1027. /// </summary>
  1028. /// <param name="param"></param>
  1029. /// <returns></returns>
  1030. private bool PufRetry(object[] param)
  1031. {
  1032. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  1033. if (alarmList != null)
  1034. {
  1035. CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(), alarmList.ModuleCmd,
  1036. alarmList.ModuleStep);
  1037. }
  1038. return false;
  1039. }
  1040. #endregion
  1041. #region ConfirmComplete
  1042. /// <summary>
  1043. /// 确认是否完成
  1044. /// </summary>
  1045. /// <param name="param"></param>
  1046. /// <returns></returns>
  1047. private bool ConfirmComplete(object[] param)
  1048. {
  1049. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  1050. if (alarmList != null)
  1051. {
  1052. if (alarmList.ModuleState == PUFSTATE.WaitForRobotPlacing.ToString())
  1053. {
  1054. CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(), (int)PUFMSG.ReadyForRobotPlace);
  1055. }
  1056. else if (alarmList.ModuleState == PUFSTATE.WaitForSwaping.ToString())
  1057. {
  1058. CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(), (int)PUFMSG.ReadyForSwap);
  1059. }
  1060. else if (alarmList.ModuleState == PUFSTATE.WaitForRobotPicking.ToString())
  1061. {
  1062. CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(), (int)PUFMSG.ReadyForRobotPick);
  1063. }
  1064. else if (alarmList.ModuleState == PUFSTATE.BackToPackStationing.ToString())
  1065. {
  1066. CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(), (int)PUFMSG.RobotPickComplete);
  1067. }
  1068. else if (alarmList.ModuleState == PUFSTATE.Swaping.ToString())
  1069. {
  1070. CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(), (int)PUFMSG.Swap);
  1071. }
  1072. else
  1073. {
  1074. PostMsg(PUFMSG.Error);
  1075. LOG.WriteLog(eEvent.ERR_PUF, Module.ToString(), $"error state {alarmList.ModuleState},cannot ConfirmComplete");
  1076. }
  1077. }
  1078. return false;
  1079. }
  1080. /// <summary>
  1081. /// 清除报警
  1082. /// </summary>
  1083. /// <param name="param"></param>
  1084. /// <returns></returns>
  1085. private bool ClearModuleAlarm(object[] param)
  1086. {
  1087. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  1088. if (alarmList != null)
  1089. {
  1090. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), "");
  1091. }
  1092. return true;
  1093. }
  1094. #endregion
  1095. #region FlipSideA
  1096. /// <summary>
  1097. /// Flip SideA
  1098. /// </summary>
  1099. /// <param name="param"></param>
  1100. /// <returns></returns>
  1101. private bool FlipSideA(object[] param)
  1102. {
  1103. return _flipAxis.PositionStation("SideA");
  1104. }
  1105. /// <summary>
  1106. /// Flip SideA监控
  1107. /// </summary>
  1108. /// <param name="param"></param>
  1109. /// <returns></returns>
  1110. private bool FlipSideAMonitor(object[] param)
  1111. {
  1112. RState ret = _flipAxis.Status;
  1113. if (ret == RState.End)
  1114. {
  1115. return true;
  1116. }
  1117. else if (ret == RState.Failed || ret == RState.Timeout)
  1118. {
  1119. PostMsg(PUFMSG.Error);
  1120. }
  1121. return false;
  1122. }
  1123. #endregion
  1124. /// <summary>
  1125. /// 校验Puf vertical/Rotation是否到达Robot位置
  1126. /// </summary>
  1127. /// <returns></returns>
  1128. public bool CheckPufVerticalAndRotationInRobot()
  1129. {
  1130. if (_verticalAxis == null)
  1131. {
  1132. return false;
  1133. }
  1134. if (!_verticalAxis.CheckPositionIsInStation(_verticalAxis.MotionData.MotorPosition, "Robot"))
  1135. {
  1136. return false;
  1137. }
  1138. if (!_rotationAxis.CheckPositionIsInStation(_rotationAxis.MotionData.MotorPosition, "Robot"))
  1139. {
  1140. return false;
  1141. }
  1142. return true;
  1143. }
  1144. public bool Check(int msg, out string reason, params object[] args)
  1145. {
  1146. reason = "";
  1147. return false;
  1148. }
  1149. public bool CheckAcked(int msg)
  1150. {
  1151. return false;
  1152. }
  1153. public int Invoke(string function, params object[] args)
  1154. {
  1155. switch(function)
  1156. {
  1157. case "HomeAll":
  1158. if(IsIdle)
  1159. {
  1160. return (int)FSM_MSG.NONE;
  1161. }
  1162. if (CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(), (int)PUFMSG.HomeAll))
  1163. {
  1164. return (int)FSM_MSG.NONE;
  1165. }
  1166. else
  1167. {
  1168. return (int)FSM_MSG.ALARM;
  1169. }
  1170. case "Abort":
  1171. CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(), (int)PUFMSG.Abort);
  1172. return (int)FSM_MSG.NONE;
  1173. case "Retry":
  1174. if (CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(), (int)PUFMSG.Retry, args))
  1175. {
  1176. return (int)PUFMSG.Retry;
  1177. }
  1178. else
  1179. {
  1180. return (int)FSM_MSG.NONE;
  1181. }
  1182. case "ConfirmComplete":
  1183. if (CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(), (int)PUFMSG.ConfirmComplete, args))
  1184. {
  1185. return (int)PUFMSG.ConfirmComplete;
  1186. }
  1187. else
  1188. {
  1189. return (int)FSM_MSG.NONE;
  1190. }
  1191. default:
  1192. return (int)FSM_MSG.NONE;
  1193. }
  1194. }
  1195. }
  1196. public enum PUFMSG
  1197. {
  1198. HomeAll, // 0
  1199. SwitchOn,
  1200. SwitchOff,
  1201. Calibrate,
  1202. Error,
  1203. ResumeError,
  1204. Abort,
  1205. PickFromLoader,
  1206. PlaceToLoader,
  1207. GoToSavedPosition,
  1208. GotoRobotPositionForPlace,
  1209. GotoRobotPositionForPick,
  1210. ReturnIdle,
  1211. ReturnInit,
  1212. ReadyForRobotPlace,
  1213. ReadyForSwap,
  1214. Swap,
  1215. ReadyForRobotPick,
  1216. RobotPickComplete,
  1217. Retry,
  1218. ConfirmComplete,
  1219. FlipSideA
  1220. }
  1221. }