PUFEntity.cs 49 KB

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