RunWaferRecipeStateMachine.cs 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Fsm;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using Aitex.Core.Utilities;
  7. using MECF.Framework.Common.Beckhoff.AxisProvider;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.RecipeCenter;
  10. using MECF.Framework.Common.Utilities;
  11. using PunkHPX8_Core;
  12. using PunkHPX8_RT.Backends;
  13. using PunkHPX8_RT.Devices.AXIS;
  14. using PunkHPX8_RT.Devices.Facilities;
  15. using PunkHPX8_RT.Devices.SRD;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Reflection;
  20. using System.Text;
  21. using System.Threading;
  22. using System.Threading.Tasks;
  23. using System.Timers;
  24. using System.Windows.Threading;
  25. using Aitex.Core.RT.Routine;
  26. namespace PunkHPX8_RT.Modules.SRD
  27. {
  28. /// <summary>
  29. /// RunWafer状态机
  30. /// </summary>
  31. public class RunWaferRecipeStateMachine : Entity, IEntity
  32. {
  33. #region 常量
  34. private const int MAX_ARM_HOME_RETRIES = 3;
  35. /// <summary>
  36. /// 旋转增加时长
  37. /// </summary>
  38. private const int ROTATION_PLUS_TIME = 10;
  39. /// <summary>
  40. /// ROTATION电机转速比例
  41. /// </summary>
  42. private const int SPEED_RATIO = 10;
  43. #endregion
  44. #region 内部变量
  45. /// <summary>
  46. /// 模块名称
  47. /// </summary>
  48. private string _module;
  49. /// <summary>
  50. /// Arm Axis
  51. /// </summary>
  52. private JetAxisBase _armAxis;
  53. /// <summary>
  54. /// Rotation Axis
  55. /// </summary>
  56. private JetAxisBase _rotationAxis;
  57. /// <summary>
  58. /// SRD Common
  59. /// </summary>
  60. private SrdCommonDevice _srdCommon;
  61. /// <summary>
  62. /// Total SRD
  63. /// </summary>
  64. private TotalSRDDevice _totalSRDDevice;
  65. /// <summary>
  66. /// 另外SRD实例
  67. /// </summary>
  68. private SRDEntity _otherSrdEntity;
  69. /// <summary>
  70. /// Loader Common
  71. /// </summary>
  72. private SystemFacilities _systemFacilities;
  73. /// <summary>
  74. /// Arm是否Home
  75. /// </summary>
  76. private bool _armIsHomed;
  77. /// <summary>
  78. /// Arm重试次数
  79. /// </summary>
  80. private int _armRetryTimes = 0;
  81. /// <summary>
  82. /// ARM正在执行Home
  83. /// </summary>
  84. private bool _armHoming = false;
  85. /// <summary>
  86. /// 是否正在用水
  87. /// </summary>
  88. private bool _isUsingWater = false;
  89. /// <summary>
  90. /// Recipe
  91. /// </summary>
  92. private SrdRecipe _srdRecipe;
  93. /// <summary>
  94. /// 记时
  95. /// </summary>
  96. private int _enterTime;
  97. /// <summary>
  98. /// Diverting Flow时长
  99. /// </summary>
  100. private int _divertingFlowCheckTimeSpan;
  101. /// <summary>
  102. /// Pooling Flow时长
  103. /// </summary>
  104. private int _poolingFlowCheckTimeSpan;
  105. /// <summary>
  106. /// Washing Flow时长
  107. /// </summary>
  108. private int _washingFlowCheckTimeSpan;
  109. /// <summary>
  110. /// SRD rotation Provider对象
  111. /// </summary>
  112. private BeckhoffProviderAxis _rotationProviderAxis;
  113. /// <summary>
  114. /// SRD arm Provider对象
  115. /// </summary>
  116. private BeckhoffProviderAxis _armProviderAxis;
  117. /// <summary>
  118. /// 转换增加的时间
  119. /// </summary>
  120. private int _rotationPlusSecond = ROTATION_PLUS_TIME;
  121. /// <summary>
  122. /// N2 Enabled
  123. /// </summary>
  124. private bool _n2Enabled = false;
  125. /// <summary>
  126. /// Dry速度
  127. /// </summary>
  128. private int _drySpeed;
  129. /// <summary>
  130. /// exhaust进入时间
  131. /// </summary>
  132. private int _exhaustFanTime;
  133. /// <summary>
  134. /// 旋转停止时间
  135. /// </summary>
  136. private int _rotationStopTime;
  137. /// <summary>
  138. /// 是否执行Rotation Stop
  139. /// </summary>
  140. private bool _isExecuteRotationStop;
  141. /// <summary>
  142. /// Wafer Presence Accel/Decel比例
  143. /// </summary>
  144. private int _waferPresenceCheckAccelDecelPercentage;
  145. /// <summary>
  146. /// Wafer Presence Speed
  147. /// </summary>
  148. private int _waferPresenceSpeedInRPMs;
  149. /// <summary>
  150. /// Wafer Presence distance
  151. /// </summary>
  152. private int _waferPresenceDistance;
  153. /// <summary>
  154. /// 状态机进入时间
  155. /// </summary>
  156. private int _startTime;
  157. /// <summary>
  158. /// Wafer Presence Test功能是否启用
  159. /// </summary>
  160. private bool _presenceTestEnabled;
  161. /// <summary>
  162. /// PresenceTest记录次数
  163. /// </summary>
  164. private int _presenceTestCount;
  165. /// <summary>
  166. /// 当前次数
  167. /// </summary>
  168. private int _currentCount;
  169. /// <summary>
  170. /// Rinse时间=Max(FrontRinseTime, BackRinseTime) 单位s
  171. /// </summary>
  172. private double _rinseTime;
  173. /// <summary>
  174. /// Rinse中另一个水阀开关状态
  175. /// </summary>
  176. private bool _isAnotherWaterOn;
  177. /// <summary>
  178. /// PresenceTest是否完成
  179. /// </summary>
  180. private bool _isTestComplete = true;
  181. /// <summary>
  182. /// Rotation是否执行Position
  183. /// </summary>
  184. private bool _isRotationExecutePosition = false;
  185. /// <summary>
  186. /// PresenceTest进入时间
  187. /// </summary>
  188. private int _presenceTestEnterTime;
  189. #endregion
  190. #region 属性
  191. /// <summary>
  192. /// 状态
  193. /// </summary>
  194. public string State { get { return ((RunWaferState)fsm.State).ToString(); } }
  195. #endregion
  196. /// <summary>
  197. /// 构造函数
  198. /// </summary>
  199. /// <param name="name"></param>
  200. public RunWaferRecipeStateMachine(string module)
  201. {
  202. _module = module;
  203. this.fsm = new StateMachine($"{module}_RunWaferStateMachine", (int)RunWaferState.RunWafer_Complete, 10);
  204. fsm.EnableRepeatedMsg(true);
  205. AnyStateTransition(RunWaferMsg.Init, EnterRunWaferStart, RunWaferState.RunWafer_Start);
  206. AnyStateTransition(RunWaferMsg.Error, EnterError, RunWaferState.Error);
  207. Transition(RunWaferState.RunWafer_Start, RunWaferMsg.RunWafer_Start, RunWaferStartCheckStatus, RunWaferState.RunWafer_CheckFacilities);
  208. Transition(RunWaferState.RunWafer_CheckFacilities, FSM_MSG.TIMER, CheckFacilities, RunWaferState.RunWafer_PreparingExhaustOff);
  209. Transition(RunWaferState.RunWafer_PreparingExhaustOff, FSM_MSG.TIMER, PreparingExhaustOff, RunWaferState.RunWafer_WaitExhaustOff);
  210. Transition(RunWaferState.RunWafer_WaitExhaustOff, FSM_MSG.TIMER, WaitExhaustOff, RunWaferState.RunWafer_EngageChuckVacuum);
  211. Transition(RunWaferState.RunWafer_EngageChuckVacuum, FSM_MSG.TIMER, EngageChuckVacuum, RunWaferState.RunWafer_CheckVacuum);
  212. Transition(RunWaferState.RunWafer_CheckVacuum, FSM_MSG.TIMER, CheckVacuum, RunWaferState.RunWafer_CloseTheDoor);
  213. Transition(RunWaferState.RunWafer_CloseTheDoor, FSM_MSG.TIMER,CloseDoor,RunWaferState.RunWafer_CheckDoorClosed);
  214. Transition(RunWaferState.RunWafer_CheckDoorClosed, FSM_MSG.TIMER, CheckDoorClosed, RunWaferState.RunWafer_ArmToHome);
  215. Transition(RunWaferState.RunWafer_ArmToHome, FSM_MSG.TIMER,ArmToHome, RunWaferState.RunWafer_Diverting_CheckArmHome);
  216. Transition(RunWaferState.RunWafer_Diverting_CheckArmHome, FSM_MSG.TIMER, CheckArmHome, RunWaferState.RunWafer_Diverting_CheckOtherSRD);
  217. Transition(RunWaferState.RunWafer_Diverting_CheckOtherSRD, FSM_MSG.TIMER, CheckOtherSRD, RunWaferState.RunWafer_Diverting_WaterOn);
  218. Transition(RunWaferState.RunWafer_Diverting_WaterOn, FSM_MSG.TIMER, WaterOn, RunWaferState.RunWafer_Diverting_WithFlowCheck);
  219. Transition(RunWaferState.RunWafer_Diverting_WithFlowCheck, FSM_MSG.TIMER, CheckFlow, RunWaferState.RunWafer_Washing_ArmToCenter);
  220. Transition(RunWaferState.RunWafer_Washing_ArmToCenter, FSM_MSG.TIMER, ArmToCenter, RunWaferState.RunWafer_Washing_CheckArmCenter);
  221. Transition(RunWaferState.RunWafer_Washing_CheckArmCenter, FSM_MSG.TIMER, CheckArmToCenter, RunWaferState.RunWafer_Washing_PoolingFrontSide);
  222. Transition(RunWaferState.RunWafer_Washing_PoolingFrontSide, FSM_MSG.TIMER, PoolingFrontSideWaterOn, RunWaferState.RunWafer_Washing_PoolingWithFlowCheck);
  223. Transition(RunWaferState.RunWafer_Washing_PoolingWithFlowCheck, FSM_MSG.TIMER, PoolingCheckFlow, RunWaferState.RunWafer_Washing_StartRotation);
  224. Transition(RunWaferState.RunWafer_Washing_StartRotation, FSM_MSG.TIMER, StartRotation, RunWaferState.RunWafer_Washing_PreFlowCheck);
  225. Transition(RunWaferState.RunWafer_Washing_PreFlowCheck, FSM_MSG.TIMER, WashingPreFlowCheck, RunWaferState.RunWafer_Washing_Finished);
  226. Transition(RunWaferState.RunWafer_Washing_Finished, FSM_MSG.TIMER, WashingFinished, RunWaferState.RunWafer_Drying_PreN2Time);
  227. Transition(RunWaferState.RunWafer_Drying_PreN2Time, FSM_MSG.TIMER, CheckArmMotion, RunWaferState.RunWafer_Drying_ExhaustFanDelay);
  228. Transition(RunWaferState.RunWafer_Drying_ExhaustFanDelay, FSM_MSG.TIMER, ExhaustFanDelay, RunWaferState.RunWafer_Drying_N2On);
  229. Transition(RunWaferState.RunWafer_Drying_N2On, FSM_MSG.TIMER, N2On, RunWaferState.RunWafer_Drying_PreWaferPresenceCheck);
  230. Transition(RunWaferState.RunWafer_Drying_PreWaferPresenceCheck, FSM_MSG.TIMER, PreWaferPresenceCheck, RunWaferState.RunWafer_Drying_WaferPresenceCheck);
  231. Transition(RunWaferState.RunWafer_Drying_WaferPresenceCheck, FSM_MSG.TIMER, WaferPresenceCheck, RunWaferState.RunWafer_Drying_PostN2Time);
  232. Transition(RunWaferState.RunWafer_Drying_PostN2Time, FSM_MSG.TIMER, PostN2Time, RunWaferState.RunWafer_Drying_CheckRotationFinished);
  233. Transition(RunWaferState.RunWafer_Drying_CheckRotationFinished, FSM_MSG.TIMER, CheckRotationFinished, RunWaferState.RunWafer_CheckArmHome);
  234. Transition(RunWaferState.RunWafer_CheckArmHome, FSM_MSG.TIMER, LastCheckArmHomed, RunWaferState.RunWafer_Complete);
  235. //PresenceTest
  236. Transition(RunWaferState.RunWafer_Complete, RunWaferMsg.PreWaferPresenceCheck, RunWaferStartCheckStatus, RunWaferState.RunWafer_Drying_PreWaferPresenceCheck);
  237. EnumLoop<RunWaferState>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  238. EnumLoop<RunWaferMsg>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  239. }
  240. private bool EnterError(object param)
  241. {
  242. //关闭风扇
  243. if (_srdCommon.CommonData.ExhaustOn)
  244. {
  245. bool result = _srdCommon.N2OffAction("", null);
  246. if (!result)
  247. {
  248. LOG.WriteLog(eEvent.ERR_SRD, _module, "EnterError: Exhaust Off is failed");
  249. }
  250. }
  251. //关闭WaterAbove
  252. if (_srdCommon.CommonData.WaterAbove)
  253. {
  254. bool result = _srdCommon.WaterAboveOff();
  255. if (!result)
  256. {
  257. LOG.WriteLog(eEvent.INFO_SRD, _module, "EnterError: Water Above Off is failed");
  258. }
  259. }
  260. //关闭WaterBelow
  261. if (_srdCommon.CommonData.WaterBelow)
  262. {
  263. bool result = _srdCommon.WaterBelowOff();
  264. if (!result)
  265. {
  266. LOG.WriteLog(eEvent.INFO_SRD, _module, "EnterError: Water Below Off is failed");
  267. }
  268. }
  269. return true;
  270. }
  271. private bool EnterRunWaferStart(object param)
  272. {
  273. _isRotationExecutePosition = false;
  274. return true;
  275. }
  276. #region 状态方法
  277. /// <summary>
  278. /// 启动
  279. /// </summary>
  280. /// <param name="param"></param>
  281. /// <returns></returns>
  282. private bool RunWaferStartCheckStatus(object param)
  283. {
  284. _startTime = Environment.TickCount;
  285. if(param!=null)
  286. {
  287. object[] parameters= (object[])param;
  288. _srdRecipe=(SrdRecipe)parameters[0];
  289. }
  290. if(_srdRecipe==null)
  291. {
  292. PostMsg(RunWaferMsg.Error);
  293. LOG.WriteLog(eEvent.ERR_SRD, _module, "srd recipe is null");
  294. return false;
  295. }
  296. _armAxis = DEVICE.GetDevice<JetAxisBase>($"{_module}.Arm");
  297. if(!_armAxis.IsHomed)
  298. {
  299. PostMsg(RunWaferMsg.Error);
  300. LOG.WriteLog(eEvent.ERR_SRD, _module, "Arm is not homed");
  301. return false;
  302. }
  303. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{_module}.Rotation");
  304. if (!_rotationAxis.IsHomed)
  305. {
  306. PostMsg(RunWaferMsg.Error);
  307. LOG.WriteLog(eEvent.ERR_SRD, _module, "Rotation is not homed");
  308. return false;
  309. }
  310. _srdCommon = DEVICE.GetDevice<SrdCommonDevice>($"{_module}.Common");
  311. _totalSRDDevice = DEVICE.GetDevice<TotalSRDDevice>("SRD");
  312. if (_srdCommon.IsWaferPresence)
  313. {
  314. if (_srdCommon.WaferPresence != "WellPlaced")
  315. {
  316. PostMsg(RunWaferMsg.Error);
  317. LOG.WriteLog(eEvent.ERR_SRD, _module, "Wafer Presence is not WellPlaced");
  318. return false;
  319. }
  320. }
  321. else
  322. {
  323. LOG.WriteLog(eEvent.INFO_SRD, _module, "Wafer Presence Test has been ignored");
  324. }
  325. if(SC.ContainsItem("SRD.SRDRotationPlusSecond"))
  326. {
  327. _rotationPlusSecond = SC.GetValue<int>("SRD.SRDRotationPlusSecond");
  328. }
  329. if(SC.ContainsItem("SRD.N2Enabled"))
  330. {
  331. _n2Enabled = SC.GetValue<bool>("SRD.N2Enabled");
  332. }
  333. //Wafer Presence Test
  334. if (SC.ContainsItem($"SRD.{_module}EnablePresenceCheckvalue"))
  335. {
  336. _presenceTestEnabled = SC.GetValue<bool>($"SRD.{_module}EnablePresenceCheckvalue");
  337. }
  338. _systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  339. string otherSRD = _module == "SRD1" ? "SRD2" : "SRD1";
  340. _otherSrdEntity = Singleton<RouteManager>.Instance.GetModule<SRDEntity>(otherSRD);
  341. _rotationProviderAxis = BeckhoffAxisProviderManager.Instance.GetAxisProvider($"{_module}.Rotation");
  342. if (_rotationProviderAxis == null)
  343. {
  344. PostMsg(RunWaferMsg.Error);
  345. LOG.WriteLog(eEvent.ERR_SRD, _module, $"{_module}.Rotation Provider is not exist");
  346. return false;
  347. }
  348. _armProviderAxis = BeckhoffAxisProviderManager.Instance.GetAxisProvider($"{_module}.Arm");
  349. if (_armProviderAxis == null)
  350. {
  351. PostMsg(RunWaferMsg.Error);
  352. LOG.WriteLog(eEvent.ERR_SRD, _module, $"{_module}.Arm Provider is not exist");
  353. return false;
  354. }
  355. _waferPresenceCheckAccelDecelPercentage = SC.GetValue<int>("SRD.WaferPresenceCheckAccelDecelPercentage");
  356. _waferPresenceSpeedInRPMs = SC.GetValue<int>("SRD.WaferPresenceCheckSpeedInRPMs");
  357. _waferPresenceDistance = SC.GetValue<int>("SRD.WaferPresenceCheckDistanceInDegrees");
  358. return true;
  359. }
  360. /// <summary>
  361. /// 检查Facilities
  362. /// </summary>
  363. /// <param name="param"></param>
  364. /// <returns></returns>
  365. private bool CheckFacilities(object param)
  366. {
  367. if (_srdCommon.CommonData.FluidContainment)
  368. {
  369. LOG.WriteLog(eEvent.ERR_SRD, _module, "Fluid Containment sensor is On");
  370. PostMsg(RunWaferMsg.Error);
  371. return false;
  372. }
  373. if(!_systemFacilities.LoaderDiEnable)
  374. {
  375. LOG.WriteLog(eEvent.ERR_SRD, _module, "Load DI Is Disable");
  376. PostMsg(RunWaferMsg.Error);
  377. return false;
  378. }
  379. return true;
  380. }
  381. /// <summary>
  382. /// 关闭Exhaust风机
  383. /// </summary>
  384. /// <param name="param"></param>
  385. /// <returns></returns>
  386. private bool PreparingExhaustOff(object param)
  387. {
  388. bool result = _srdCommon.N2OffAction("", null);
  389. if (!result)
  390. {
  391. LOG.WriteLog(eEvent.ERR_SRD, _module, "Preparing Exhaust Off is failed");
  392. PostMsg(RunWaferMsg.Error);
  393. return false;
  394. }
  395. return true;
  396. }
  397. /// <summary>
  398. /// 等待Exhaust风机关闭状态
  399. /// </summary>
  400. /// <param name="param"></param>
  401. /// <returns></returns>
  402. private bool WaitExhaustOff(object param)
  403. {
  404. if (_srdCommon.Status==RState.Failed||_srdCommon.Status==RState.Timeout)
  405. {
  406. LOG.WriteLog(eEvent.ERR_SRD, _module, "Waiting Exhaust Off is failed");
  407. PostMsg(RunWaferMsg.Error);
  408. return false;
  409. }
  410. return _srdCommon.Status == RState.End && !_srdCommon.CommonData.ExhaustOn;
  411. }
  412. /// <summary>
  413. /// Chuck Vacuum
  414. /// </summary>
  415. /// <param name="param"></param>
  416. /// <returns></returns>
  417. private bool EngageChuckVacuum(object param)
  418. {
  419. if (_srdCommon.IsWaferPresence)
  420. {
  421. bool result = _srdCommon.ChuckVacuumOnAction("", null);
  422. if (!result)
  423. {
  424. LOG.WriteLog(eEvent.ERR_SRD, _module, "Chuck Vacuum On Action is failed");
  425. PostMsg(RunWaferMsg.Error);
  426. }
  427. return result;
  428. }
  429. else
  430. {
  431. LOG.WriteLog(eEvent.INFO_SRD, _module, "EngageChuckVacuum has been ignored");
  432. return true;
  433. }
  434. }
  435. /// <summary>
  436. /// 检查真空状态
  437. /// </summary>
  438. /// <param name="param"></param>
  439. /// <returns></returns>
  440. private bool CheckVacuum(object param)
  441. {
  442. if (_srdCommon.IsWaferPresence)
  443. {
  444. if (_srdCommon.Status == RState.Failed || _srdCommon.Status == RState.Timeout)
  445. {
  446. LOG.WriteLog(eEvent.ERR_SRD, _module, "Check Vacuum is failed");
  447. PostMsg(RunWaferMsg.Error);
  448. return false;
  449. }
  450. return _srdCommon.Status == RState.End && !_srdCommon.CommonData.ChuckVacuum;
  451. }
  452. else
  453. {
  454. LOG.WriteLog(eEvent.INFO_SRD, _module, "CheckVacuum has been ignored");
  455. return true;
  456. }
  457. }
  458. /// <summary>
  459. /// Close Door
  460. /// </summary>
  461. /// <param name="param"></param>
  462. /// <returns></returns>
  463. private bool CloseDoor(object param)
  464. {
  465. if (_srdCommon.CommonData.DoorOpened)
  466. {
  467. bool result = _srdCommon.DoorCloseAction("", null);
  468. if (!result)
  469. {
  470. LOG.WriteLog(eEvent.ERR_SRD, _module, "Door Close Action is failed");
  471. PostMsg(RunWaferMsg.Error);
  472. return result;
  473. }
  474. }
  475. return true;
  476. }
  477. /// <summary>
  478. /// 检验DoorClosed
  479. /// </summary>
  480. /// <param name="param"></param>
  481. /// <returns></returns>
  482. private bool CheckDoorClosed(object param)
  483. {
  484. if (_srdCommon.Status == RState.Failed || _srdCommon.Status == RState.Timeout)
  485. {
  486. LOG.WriteLog(eEvent.ERR_SRD, _module, "Check Door Closed is failed");
  487. PostMsg(RunWaferMsg.Error);
  488. return false;
  489. }
  490. return _srdCommon.Status == RState.End && _srdCommon.CommonData.DoorClosed;
  491. }
  492. /// <summary>
  493. /// Arm To Home
  494. /// </summary>
  495. /// <returns></returns>
  496. private bool ArmToHome(object param)
  497. {
  498. if (!_armHoming)
  499. {
  500. _armAxis.Home(false);
  501. _armHoming = true;
  502. return false;
  503. }
  504. else
  505. {
  506. if(_armAxis.Status != RState.End)
  507. {
  508. return false;
  509. }
  510. }
  511. _armHoming = false;
  512. _armIsHomed = _armAxis.IsHomed;
  513. return true;
  514. }
  515. /// <summary>
  516. /// 检验ARM,发现失败,则重试
  517. /// </summary>
  518. /// <param name="param"></param>
  519. /// <returns></returns>
  520. private bool CheckArmHome(object param)
  521. {
  522. if (_armIsHomed)
  523. {
  524. return true;
  525. }
  526. else
  527. {
  528. if(_armRetryTimes<MAX_ARM_HOME_RETRIES)
  529. {
  530. if (!_armHoming)
  531. {
  532. LOG.WriteLog(eEvent.INFO_SRD, _module, $"Arm Home Retry Home {_armRetryTimes + 1} times");
  533. bool result = _armAxis.Home(false);
  534. if (result)
  535. {
  536. _armHoming = true;
  537. }
  538. _armRetryTimes++;
  539. return false;
  540. }
  541. else
  542. {
  543. if(_armAxis.IsHomed&&_armAxis.Status==RState.End)
  544. {
  545. _armRetryTimes = 0;
  546. _armHoming = false;
  547. return true;
  548. }
  549. return false;
  550. }
  551. }
  552. else
  553. {
  554. LOG.WriteLog(eEvent.ERR_SRD, _module, $"Arm Home Retry Home {_armRetryTimes + 1} times is over {MAX_ARM_HOME_RETRIES}");
  555. PostMsg(RunWaferMsg.Error);
  556. return false;
  557. }
  558. }
  559. }
  560. /// <summary>
  561. /// 检验另外一个SRD是否在用水
  562. /// </summary>
  563. /// <param name="param"></param>
  564. /// <returns></returns>
  565. private bool CheckOtherSRD(object param)
  566. {
  567. if (_otherSrdEntity == null)
  568. {
  569. return true;
  570. }
  571. return !_otherSrdEntity.IsUsingWater;
  572. }
  573. /// <summary>
  574. /// 打开Above water
  575. /// </summary>
  576. /// <param name="param"></param>
  577. /// <returns></returns>
  578. private bool WaterOn(object param)
  579. {
  580. if (_srdRecipe.FrontDivertTime>0)
  581. {
  582. if(_srdRecipe.FrontDivertTime>_srdRecipe.DivertPlusPoolDelay)
  583. {
  584. _divertingFlowCheckTimeSpan = _srdRecipe.DivertPlusPoolDelay * 1000;
  585. }
  586. else
  587. {
  588. _divertingFlowCheckTimeSpan = _srdRecipe.FrontDivertTime*1000;
  589. }
  590. if (!_srdCommon.CommonData.WaterAbove)
  591. {
  592. bool result = _srdCommon.WaterAboveOn();
  593. if (result)
  594. {
  595. LOG.WriteLog(eEvent.INFO_SRD, _module, "Water Above On");
  596. _isUsingWater = true;
  597. _enterTime = Environment.TickCount;
  598. }
  599. else
  600. {
  601. LOG.WriteLog(eEvent.ERR_SRD, _module, "Water Above On is failed");
  602. PostMsg(RunWaferMsg.Error);
  603. }
  604. return result;
  605. }
  606. return false;
  607. }
  608. else
  609. {
  610. return true;
  611. }
  612. }
  613. /// <summary>
  614. /// 检验水压
  615. /// </summary>
  616. /// <param name="param"></param>
  617. /// <returns></returns>
  618. private bool CheckFlow(object param)
  619. {
  620. if (_srdRecipe.FrontDivertTime==0)
  621. {
  622. return true;
  623. }
  624. else
  625. {
  626. int ticks = Environment.TickCount - _enterTime;
  627. if(ticks<=_divertingFlowCheckTimeSpan)
  628. {
  629. if(_totalSRDDevice.WaterPressure>_srdRecipe.MaxDivertPlusPoolPressure)
  630. {
  631. LOG.WriteLog(eEvent.ERR_SRD, _module,$"Water Pressure {_totalSRDDevice} is over {_srdRecipe.MaxDivertPlusPoolPressure}");
  632. PostMsg(RunWaferMsg.Error);
  633. return false;
  634. }
  635. }
  636. else
  637. {
  638. if (ticks >= _srdRecipe.FrontDivertTime*1000)
  639. {
  640. if (_srdCommon.CommonData.WaterAbove)
  641. {
  642. bool result = _srdCommon.WaterAboveOff();
  643. if (result)
  644. {
  645. LOG.WriteLog(eEvent.INFO_SRD, _module, "Water Above off");
  646. }
  647. else
  648. {
  649. LOG.WriteLog(eEvent.ERR_SRD, _module, "Water Above On is failed");
  650. PostMsg(RunWaferMsg.Error);
  651. }
  652. return result;
  653. }
  654. }
  655. }
  656. }
  657. return false;
  658. }
  659. /// <summary>
  660. /// Arm运动至Center
  661. /// </summary>
  662. /// <param name="param"></param>
  663. /// <returns></returns>
  664. private bool ArmToCenter(object param)
  665. {
  666. bool result= _armAxis.PositionStation("Center");
  667. if(!result)
  668. {
  669. LOG.WriteLog(eEvent.ERR_SRD, _module, "Arm to Center is failed");
  670. PostMsg(RunWaferMsg.Error);
  671. }
  672. return result;
  673. }
  674. /// <summary>
  675. /// check Arm是否运动至Center
  676. /// </summary>
  677. /// <param name="param"></param>
  678. /// <returns></returns>
  679. private bool CheckArmToCenter(object param)
  680. {
  681. if (_armAxis.Status==RState.End)
  682. {
  683. return true;
  684. }
  685. else if(_armAxis.Status==RState.Failed)
  686. {
  687. LOG.WriteLog(eEvent.ERR_SRD, _module, "Check Arm to Center is failed");
  688. PostMsg(RunWaferMsg.Error);
  689. return false;
  690. }
  691. return false;
  692. }
  693. /// <summary>
  694. /// 打开Above water
  695. /// </summary>
  696. /// <param name="param"></param>
  697. /// <returns></returns>
  698. private bool PoolingFrontSideWaterOn(object param)
  699. {
  700. if (_srdRecipe.FrontPoolTime > 0)
  701. {
  702. if (_srdRecipe.FrontPoolTime > _srdRecipe.DivertPlusPoolDelay)
  703. {
  704. _poolingFlowCheckTimeSpan = _srdRecipe.DivertPlusPoolDelay * 1000;
  705. }
  706. else
  707. {
  708. _poolingFlowCheckTimeSpan = _srdRecipe.FrontDivertTime * 1000;
  709. }
  710. if (!_srdCommon.CommonData.WaterAbove)
  711. {
  712. bool result = _srdCommon.WaterAboveOn();
  713. if (result)
  714. {
  715. LOG.WriteLog(eEvent.INFO_SRD, _module, "Water Above On");
  716. _enterTime = Environment.TickCount;
  717. if (_isUsingWater)
  718. {
  719. _isUsingWater = true;
  720. }
  721. }
  722. else
  723. {
  724. LOG.WriteLog(eEvent.ERR_SRD, _module, "Water Above On is failed");
  725. PostMsg((int)RunWaferMsg.Error);
  726. }
  727. return result;
  728. }
  729. return true;
  730. }
  731. else
  732. {
  733. return true;
  734. }
  735. }
  736. /// <summary>
  737. /// 检验水压
  738. /// </summary>
  739. /// <param name="param"></param>
  740. /// <returns></returns>
  741. private bool PoolingCheckFlow(object param)
  742. {
  743. if (_srdRecipe.FrontPoolTime == 0)
  744. {
  745. return true;
  746. }
  747. else
  748. {
  749. int ticks = Environment.TickCount - _enterTime;
  750. if (ticks <= _poolingFlowCheckTimeSpan)
  751. {
  752. if (_totalSRDDevice.WaterPressure > _srdRecipe.MaxWashPressure)
  753. {
  754. LOG.WriteLog(eEvent.ERR_SRD, _module, $"Water Pressure {_totalSRDDevice.WaterPressure} is over {_srdRecipe.MaxWashPressure}");
  755. PostMsg((int)RunWaferMsg.Error);
  756. return false;
  757. }
  758. if (_totalSRDDevice.WaterPressure < _srdRecipe.MinWaterPressure)
  759. {
  760. LOG.WriteLog(eEvent.ERR_SRD, _module, $"Water Pressure {_totalSRDDevice.WaterPressure} is less {_srdRecipe.MinWaterPressure}");
  761. PostMsg((int)RunWaferMsg.Error);
  762. return false;
  763. }
  764. }
  765. else
  766. {
  767. if (ticks >= _srdRecipe.FrontPoolTime * 1000)
  768. {
  769. return true;
  770. }
  771. }
  772. }
  773. return false;
  774. }
  775. /// <summary>
  776. /// 开始旋转
  777. /// </summary>
  778. /// <param name="param"></param>
  779. /// <returns></returns>
  780. private bool StartRotation(object param)
  781. {
  782. if (_srdCommon.CommonData.DoorOpened)
  783. {
  784. LOG.WriteLog(eEvent.ERR_SRD, _module, "Door is not closed. Can't do rotation");
  785. PostMsg(RunWaferMsg.Error);
  786. return false;
  787. }
  788. double _scale = _rotationProviderAxis.ScaleFactor;
  789. bool above = _srdRecipe.FrontRinseTime > _srdRecipe.BackRinseTime;
  790. int timespan = above ? _srdRecipe.FrontRinseTime : _srdRecipe.BackRinseTime;
  791. //rinse 目标位置
  792. double rinsePosition = timespan * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_srdRecipe.RinseSpeed);
  793. //dry目标位置
  794. double dryPosition = BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_srdRecipe.DrySpeed) * _srdRecipe.BackN2DryTime;
  795. //为了让 rotation 不停止,增加了旋转时间(覆盖Arm运动时间)
  796. double plusPosition = BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_srdRecipe.DrySpeed) * _rotationPlusSecond;
  797. int targetPosition = (int)Math.Round((rinsePosition + dryPosition + plusPosition) * _scale, 0);
  798. int rotationSpeed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_srdRecipe.RinseSpeed),0);
  799. _drySpeed= (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_srdRecipe.DrySpeed * SPEED_RATIO), 0);
  800. bool result= _rotationAxis.ProfilePosition(targetPosition, rotationSpeed * SPEED_RATIO, 0, 0);
  801. if(!result)
  802. {
  803. LOG.WriteLog(eEvent.ERR_SRD, _module, "Start Rotation is failed");
  804. PostMsg(RunWaferMsg.Error);
  805. return false;
  806. }
  807. LOG.WriteLog(eEvent.INFO_SRD, _module, "Start Rotation");
  808. //如果BackRinseTime大,则先开WaterBelow后开WaterAbove
  809. if (_srdRecipe.BackRinseTime>_srdRecipe.FrontRinseTime)
  810. {
  811. _rinseTime = _srdRecipe.BackRinseTime;
  812. //关闭WaterAbove
  813. if (_srdCommon.CommonData.WaterAbove)
  814. {
  815. if (!_srdCommon.WaterAboveOff())
  816. {
  817. LOG.WriteLog(eEvent.ERR_SRD, _module, "Water Above Off is failed");
  818. PostMsg((int)RunWaferMsg.Error);
  819. return false;
  820. }
  821. LOG.WriteLog(eEvent.INFO_SRD, _module, "Water Above Off");
  822. }
  823. //打开WaterBelow
  824. if (!_srdCommon.CommonData.WaterBelow)
  825. {
  826. if (!_srdCommon.WaterBelowOn())
  827. {
  828. LOG.WriteLog(eEvent.ERR_SRD, _module, "Water Below On is failed");
  829. PostMsg((int)RunWaferMsg.Error);
  830. return false;
  831. }
  832. LOG.WriteLog(eEvent.INFO_SRD, _module, "Water Below On");
  833. }
  834. //Rinse开始时间
  835. _enterTime = Environment.TickCount;
  836. //另一个水阀状态变为未开(即WaterAbove)
  837. _isAnotherWaterOn = false;
  838. //计算水压检测滞后时间
  839. if (_srdRecipe.BackRinseTime > _srdRecipe.FlowCheckDelay)
  840. {
  841. _washingFlowCheckTimeSpan = _srdRecipe.FlowCheckDelay * 1000;
  842. }
  843. else
  844. {
  845. _washingFlowCheckTimeSpan = _srdRecipe.BackRinseTime * 1000;
  846. }
  847. return true;
  848. }
  849. else
  850. {
  851. _rinseTime = _srdRecipe.FrontRinseTime;
  852. //如果FrontRinseTime大,则先开WaterAbove后开WaterBelow
  853. //打开WaterAbove
  854. if (!_srdCommon.CommonData.WaterAbove)
  855. {
  856. if (!_srdCommon.WaterAboveOn())
  857. {
  858. LOG.WriteLog(eEvent.ERR_SRD, _module, "Water Above Off is failed");
  859. PostMsg((int)RunWaferMsg.Error);
  860. return false;
  861. }
  862. LOG.WriteLog(eEvent.INFO_SRD, _module, "Water Above On");
  863. }
  864. //关闭WaterBelow
  865. if (_srdCommon.CommonData.WaterBelow)
  866. {
  867. //打开WaterBelow
  868. if (!_srdCommon.WaterBelowOff())
  869. {
  870. LOG.WriteLog(eEvent.ERR_SRD, _module, "Water Below On is failed");
  871. PostMsg((int)RunWaferMsg.Error);
  872. return false;
  873. }
  874. LOG.WriteLog(eEvent.INFO_SRD, _module, "Water Below Off");
  875. }
  876. //另一个水阀状态变为未开(即WaterBelow)
  877. _isAnotherWaterOn = false;
  878. //Rinse开始时间
  879. _enterTime = Environment.TickCount;
  880. //计算水压检测滞后时间
  881. if (_srdRecipe.FrontRinseTime > _srdRecipe.FlowCheckDelay)
  882. {
  883. _washingFlowCheckTimeSpan = _srdRecipe.FlowCheckDelay * 1000;
  884. }
  885. else
  886. {
  887. _washingFlowCheckTimeSpan = _srdRecipe.BackRinseTime * 1000;
  888. }
  889. return true;
  890. }
  891. }
  892. /// <summary>
  893. /// 检验水压
  894. /// </summary>
  895. /// <param name="param"></param>
  896. /// <returns></returns>
  897. private bool WashingPreFlowCheck(object param)
  898. {
  899. int ticks = Environment.TickCount - _enterTime;
  900. //打开另一个未开的水阀
  901. if(!_isAnotherWaterOn)
  902. {
  903. //延迟abs(BackRinseTime - FrontRinseTime)秒打开另一个水阀
  904. if (_srdRecipe.BackRinseTime > _srdRecipe.FrontRinseTime)
  905. {
  906. //若BackRinseTime > FrontRinseTime,则延迟BackRinseTime - FrontRinseTime秒打开Water Above
  907. if (ticks >= _rinseTime*1000 - _srdRecipe.FrontRinseTime*1000 && !_srdCommon.CommonData.WaterAbove)
  908. {
  909. bool result = _srdCommon.WaterAboveOn();
  910. if (!result)
  911. {
  912. LOG.WriteLog(eEvent.ERR_SRD, _module, "Water Above Off is failed");
  913. PostMsg((int)RunWaferMsg.Error);
  914. return false;
  915. }
  916. _isAnotherWaterOn = true;
  917. LOG.WriteLog(eEvent.INFO_SRD, _module, "Water Above On");
  918. }
  919. }
  920. else
  921. {
  922. //若FrontRinseTime > BackRinseTime,则延迟FrontRinseTime - BackRinseTime秒打开Water Below
  923. if (ticks >= _rinseTime * 1000 - _srdRecipe.BackRinseTime * 1000 && !_srdCommon.CommonData.WaterBelow)
  924. {
  925. bool result = _srdCommon.WaterBelowOn();
  926. if (!result)
  927. {
  928. LOG.WriteLog(eEvent.ERR_SRD, _module, "Water Below On is failed");
  929. PostMsg((int)RunWaferMsg.Error);
  930. return false;
  931. }
  932. LOG.WriteLog(eEvent.INFO_SRD, _module, "Water Below On");
  933. }
  934. }
  935. }
  936. if (ticks >= _rinseTime * 1000)
  937. {
  938. //达到RinseTime完成Wash
  939. return true;
  940. }
  941. else if (ticks > _washingFlowCheckTimeSpan)
  942. {
  943. if (_totalSRDDevice.WaterPressure > _srdRecipe.MaxWashPressure)
  944. {
  945. LOG.WriteLog(eEvent.ERR_SRD, _module, $"Water Pressure {_totalSRDDevice.WaterPressure} is over {_srdRecipe.MaxWashPressure}");
  946. PostMsg((int)RunWaferMsg.Error);
  947. return false;
  948. }
  949. if (_totalSRDDevice.WaterPressure < _srdRecipe.MinWaterPressure)
  950. {
  951. LOG.WriteLog(eEvent.ERR_SRD, _module, $"Water Pressure {_totalSRDDevice.WaterPressure} is less {_srdRecipe.MinWaterPressure}");
  952. PostMsg((int)RunWaferMsg.Error);
  953. return false;
  954. }
  955. }
  956. else
  957. {
  958. return false;
  959. }
  960. return false;
  961. }
  962. /// <summary>
  963. /// Washing结束
  964. /// </summary>
  965. /// <param name="param"></param>
  966. /// <returns></returns>
  967. private bool WashingFinished(object param)
  968. {
  969. if (_srdCommon.CommonData.WaterAbove)
  970. {
  971. if(!_srdCommon.WaterAboveOff())
  972. {
  973. LOG.WriteLog(eEvent.ERR_SRD, _module, "Water Above Off is failed");
  974. PostMsg(RunWaferMsg.Error);
  975. return false;
  976. }
  977. }
  978. if(_srdCommon.CommonData.WaterBelow)
  979. {
  980. if(!_srdCommon.WaterBelowOff())
  981. {
  982. LOG.WriteLog(eEvent.ERR_SRD, _module, "Water Below Off is failed");
  983. PostMsg(RunWaferMsg.Error);
  984. return false;
  985. }
  986. }
  987. _isUsingWater = false;
  988. if(_n2Enabled)
  989. {
  990. bool result= _armAxis.PositionStation("Center");
  991. if(!result)
  992. {
  993. LOG.WriteLog(eEvent.ERR_SRD, _module, "Arm to Center is failed");
  994. PostMsg(RunWaferMsg.Error);
  995. }
  996. return result;
  997. }
  998. else
  999. {
  1000. bool result= _armAxis.PositionStation("Home");
  1001. if (!result)
  1002. {
  1003. LOG.WriteLog(eEvent.ERR_SRD, _module, "Arm To Home is failed");
  1004. PostMsg(RunWaferMsg.Error);
  1005. }
  1006. return result;
  1007. }
  1008. }
  1009. /// <summary>
  1010. /// 检验Arm是否运动到位
  1011. /// </summary>
  1012. /// <returns></returns>
  1013. private bool CheckArmMotion(object param)
  1014. {
  1015. //Arm是否运动到位
  1016. if (_armAxis.Status==RState.End)
  1017. {
  1018. //调整速度为 drySpeed
  1019. bool result= _rotationAxis.ChangeSpeed(_drySpeed);
  1020. if(!result)
  1021. {
  1022. LOG.WriteLog(eEvent.ERR_SRD, _module, "Change Speed to Dry Speed is failed");
  1023. return false;
  1024. }
  1025. if(_n2Enabled)
  1026. {
  1027. //todo 打开N2 Above和N2 Below
  1028. }
  1029. _exhaustFanTime = Environment.TickCount;
  1030. return true;
  1031. }
  1032. else if(_armAxis.Status==RState.Failed)
  1033. {
  1034. LOG.WriteLog(eEvent.ERR_SRD, _module, "Arm Axis Status is in Failed");
  1035. PostMsg(RunWaferMsg.Error);
  1036. return false;
  1037. }
  1038. return false;
  1039. }
  1040. /// <summary>
  1041. /// Exhaust delay
  1042. /// </summary>
  1043. /// <param name="param"></param>
  1044. /// <returns></returns>
  1045. private bool ExhaustFanDelay(object param)
  1046. {
  1047. int ticks = Environment.TickCount - _exhaustFanTime;
  1048. if (ticks >= _srdRecipe.ExhaustFanDelay * 1000)
  1049. {
  1050. bool result = _srdCommon.N2On();
  1051. if(!result)
  1052. {
  1053. LOG.WriteLog(eEvent.ERR_SRD, _module, "Exhaust On failed");
  1054. PostMsg(RunWaferMsg.Error);
  1055. return false;
  1056. }
  1057. _enterTime = Environment.TickCount;
  1058. return true;
  1059. }
  1060. return false;
  1061. }
  1062. /// <summary>
  1063. /// N2 On
  1064. /// </summary>
  1065. /// <param name="param"></param>
  1066. /// <returns></returns>
  1067. private bool N2On(object param)
  1068. {
  1069. if (_n2Enabled)
  1070. {
  1071. //todo 关闭N2Above和N2 Below
  1072. }
  1073. int ticks = Environment.TickCount - _enterTime;
  1074. if(ticks > _srdRecipe.BackN2DryTime * 1000) return true;
  1075. return false;
  1076. }
  1077. /// <summary>
  1078. /// Pre WaferPresence Check
  1079. /// </summary>
  1080. /// <returns></returns>
  1081. private bool PreWaferPresenceCheck(object param)
  1082. {
  1083. if (!_isExecuteRotationStop)
  1084. {
  1085. //停止Rotation
  1086. bool result= _rotationAxis.StopPositionOperation();
  1087. LOG.WriteLog(eEvent.INFO_SRD, _module, "Stop Rotation is done");
  1088. _rotationStopTime = Environment.TickCount;
  1089. _isExecuteRotationStop = true;
  1090. if(!result)
  1091. {
  1092. LOG.WriteLog(eEvent.ERR_SRD, _module, "Stop Rotation is failed");
  1093. PostMsg(RunWaferMsg.Error);
  1094. }
  1095. }
  1096. else
  1097. {
  1098. int ticks=Environment.TickCount-_rotationStopTime;
  1099. if(ticks>=5*1000)//固定时间5秒,确认Rotation是否已经停下
  1100. {
  1101. if(!_rotationAxis.IsRun && _rotationAxis.Status == RState.End)
  1102. {
  1103. _isExecuteRotationStop = false;
  1104. return true;
  1105. }
  1106. else
  1107. {
  1108. LOG.WriteLog(eEvent.ERR_SRD, _module, "SRD Rotation Stop time span is over 5 seconds");
  1109. PostMsg(RunWaferMsg.Error);
  1110. return false;
  1111. }
  1112. }
  1113. }
  1114. return false;
  1115. }
  1116. /// <summary>
  1117. /// Wafer Presence Check
  1118. /// </summary>
  1119. /// <param name="param"></param>
  1120. /// <returns></returns>
  1121. private bool WaferPresenceCheck(object param)
  1122. {
  1123. double scale = _rotationProviderAxis.ScaleFactor;
  1124. int currentRotation = (int)Math.Round(_rotationAxis.MotionData.MotorPosition * scale, 0);
  1125. //Presence Test目标位置(单位为°)
  1126. int targetPosition = (int)Math.Round(scale * _waferPresenceDistance,0)+currentRotation;
  1127. //转速单位转换 RPM(r/min) to degree/s
  1128. double degree = BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_waferPresenceSpeedInRPMs);
  1129. //Presence Test目标转速
  1130. int profileVelocity =(int)Math.Round(scale*degree,0);
  1131. //加速度
  1132. int acceleration = (int)Math.Round(_rotationAxis.ProfileAcceleration * _waferPresenceCheckAccelDecelPercentage / 100, 0);
  1133. //减速度
  1134. int deceleration = (int)Math.Round(_rotationAxis.ProfileDeceleration * _waferPresenceCheckAccelDecelPercentage / 100, 0);
  1135. if (!_isRotationExecutePosition)
  1136. {
  1137. if (_srdCommon.CommonData.DoorOpened)
  1138. {
  1139. LOG.WriteLog(eEvent.ERR_SRD, _module, "Door is not closed. Can't do rotation");
  1140. PostMsg(RunWaferMsg.Error);
  1141. return false;
  1142. }
  1143. bool result = _rotationAxis.ProfilePosition(targetPosition, profileVelocity * SPEED_RATIO, acceleration, deceleration);
  1144. if (!result)
  1145. {
  1146. LOG.WriteLog(eEvent.ERR_SRD, _module, "Start Rotation is failed");
  1147. PostMsg(RunWaferMsg.Error);
  1148. }
  1149. _isRotationExecutePosition = true;
  1150. if (_srdCommon.IsWaferPresence && _presenceTestEnabled)
  1151. {
  1152. //PresenceTest记录次数=(目标位置/目标转速)*1000ms /500ms
  1153. _presenceTestCount = (int)Math.Floor(_waferPresenceDistance / degree * 1000 / 500);
  1154. LOG.WriteLog(eEvent.INFO_SRD, _module, $"Presence Test Count is about {_presenceTestCount} times");
  1155. //当前test次数归零
  1156. _currentCount = 0;
  1157. //开始计时
  1158. _presenceTestEnterTime = Environment.TickCount;
  1159. _isTestComplete = false;
  1160. LOG.WriteLog(eEvent.INFO_SRD, _module, "Presence Test Timer is started");
  1161. }
  1162. return false;
  1163. }
  1164. else
  1165. {
  1166. //PresenceTestEnable开启则进行测试
  1167. if (!_isTestComplete && _srdCommon.IsWaferPresence && _presenceTestEnabled)
  1168. {
  1169. int ticks = Environment.TickCount - _presenceTestEnterTime;
  1170. //500ms检测一次
  1171. if(ticks >= 500)
  1172. {
  1173. if (_srdCommon.WaferPresence == "WellPlaced")
  1174. {
  1175. _currentCount++;
  1176. LOG.WriteLog(eEvent.INFO_SRD, _module, $"The {_currentCount}th Presence Test is successful");
  1177. //更新PresenceTestEnterTime
  1178. _presenceTestEnterTime = Environment.TickCount;
  1179. if(_currentCount >= _presenceTestCount)
  1180. {
  1181. //PresenceTest通过
  1182. _isTestComplete = true;
  1183. LOG.WriteLog(eEvent.INFO_SRD, _module, $"The Presence Test of {_module} is all successful");
  1184. }
  1185. else
  1186. {
  1187. return false;
  1188. }
  1189. }
  1190. else
  1191. {
  1192. LOG.WriteLog(eEvent.ERR_SRD, _module, $"The {_currentCount + 1}th Presence Test is failed");
  1193. LOG.WriteLog(eEvent.ERR_SRD, _module, $"The Presence Test of {_module} is failed");
  1194. PostMsg(RunWaferMsg.Error);
  1195. return false;
  1196. }
  1197. }
  1198. else
  1199. {
  1200. return false;
  1201. }
  1202. }
  1203. if (_rotationAxis.Status!=RState.End)
  1204. {
  1205. return false;
  1206. }
  1207. }
  1208. return true;
  1209. }
  1210. /// <summary>
  1211. /// Post N2 Time(Stop rotation ,home rotation)
  1212. /// </summary>
  1213. /// <param name="param"></param>
  1214. /// <returns></returns>
  1215. private bool PostN2Time(object param)
  1216. {
  1217. bool homeResult = _rotationAxis.Home(false);
  1218. if(!homeResult)
  1219. {
  1220. LOG.WriteLog(eEvent.ERR_SRD, _module, $"{_module}.Arm is not homed");
  1221. PostMsg(RunWaferMsg.Error);
  1222. return false;
  1223. }
  1224. return true;
  1225. }
  1226. /// <summary>
  1227. /// 检验Rotation是否Homed
  1228. /// </summary>
  1229. /// <param name="param"></param>
  1230. /// <returns></returns>
  1231. private bool CheckRotationFinished(object param)
  1232. {
  1233. //关闭排风扇
  1234. if (_srdCommon.CommonData.ExhaustOn && _srdCommon.Status != RState.Running)
  1235. {
  1236. bool result1 = _srdCommon.N2OffAction("", null);
  1237. if (!result1)
  1238. {
  1239. LOG.WriteLog(eEvent.ERR_SRD, _module, "Preparing Exhaust Off is failed");
  1240. PostMsg(RunWaferMsg.Error);
  1241. }
  1242. }
  1243. bool result= _rotationAxis.IsHomed && _rotationAxis.Status == RState.End;
  1244. if(_rotationAxis.Status!=RState.Running)
  1245. {
  1246. if(!_rotationAxis.IsHomed)
  1247. {
  1248. LOG.WriteLog(eEvent.ERR_SRD, _module, $"{_module}.rotation is not homed");
  1249. }
  1250. return true;
  1251. }
  1252. return false;
  1253. }
  1254. /// <summary>
  1255. /// 检验
  1256. /// </summary>
  1257. /// <param name="param"></param>
  1258. /// <returns></returns>
  1259. private bool LastCheckArmHomed(object param)
  1260. {
  1261. string currentLocation = _armAxis.CurrentStation;
  1262. bool armHomed= _armAxis.IsHomed;
  1263. if(!armHomed)
  1264. {
  1265. LOG.WriteLog(eEvent.ERR_SRD, _module, $"{_module}.Arm is not homed");
  1266. PostMsg(RunWaferMsg.Error);
  1267. return false;
  1268. }
  1269. if (!currentLocation.Contains("Home"))
  1270. {
  1271. LOG.WriteLog(eEvent.ERR_SRD, _module, $"{_module}.Arm is not in home station");
  1272. PostMsg(RunWaferMsg.Error);
  1273. return false;
  1274. }
  1275. LOG.WriteLog(eEvent.INFO_SRD, _module, $"Run Wafer State Machine 状态 {RunWaferState.RunWafer_Start}==>{RunWaferState.RunWafer_Complete} Total Time[{Environment.TickCount - _startTime}]");
  1276. return true;
  1277. }
  1278. #endregion
  1279. /// <summary>
  1280. /// 停止
  1281. /// </summary>
  1282. public void Stop()
  1283. {
  1284. base.Terminate();
  1285. }
  1286. public bool Check(int msg, out string reason, params object[] args)
  1287. {
  1288. reason = "";
  1289. return false;
  1290. }
  1291. #region State Msg枚举
  1292. public enum RunWaferState
  1293. {
  1294. None,
  1295. Error,
  1296. RunWafer_Start,
  1297. RunWafer_CheckFacilities,
  1298. RunWafer_PreparingExhaustOff,
  1299. RunWafer_WaitExhaustOff,
  1300. RunWafer_EngageChuckVacuum,
  1301. RunWafer_CheckVacuum,
  1302. RunWafer_CloseTheDoor,
  1303. RunWafer_CheckDoorClosed,
  1304. RunWafer_ArmToHome,
  1305. RunWafer_Diverting_CheckArmHome,
  1306. RunWafer_Diverting_CheckOtherSRD,
  1307. RunWafer_Diverting_WaterOn,
  1308. RunWafer_Diverting_WithFlowCheck,
  1309. RunWafer_Washing_ArmToCenter,
  1310. RunWafer_Washing_CheckArmCenter,
  1311. RunWafer_Washing_PoolingFrontSide,
  1312. RunWafer_Washing_PoolingWithFlowCheck,
  1313. RunWafer_Washing_StartRotation,
  1314. RunWafer_Washing_PreFlowCheck,
  1315. RunWafer_Washing_Finished,
  1316. RunWafer_Drying_PreN2Time,
  1317. RunWafer_Drying_ExhaustFanDelay,
  1318. RunWafer_Drying_N2On,
  1319. RunWafer_Drying_PreWaferPresenceCheck,
  1320. RunWafer_Drying_WaferPresenceCheck,
  1321. RunWafer_Drying_PostN2Time,
  1322. RunWafer_Drying_CheckRotationFinished,
  1323. RunWafer_CheckArmHome,
  1324. RunWafer_Complete
  1325. }
  1326. public enum RunWaferMsg
  1327. {
  1328. Init,
  1329. Error,
  1330. RunWafer_Start,
  1331. CheckFacilities,
  1332. PreparingExhaustOff,
  1333. WaitExhaustOff,
  1334. EngageChuckVacuum,
  1335. CloseTheDoor,
  1336. ArmToHome,
  1337. CheckOtherSRD,
  1338. DivertingWaterAboveOn,
  1339. ArmToCenter,
  1340. PoolingFrontWaterAboveOn,
  1341. StartRotation,
  1342. Washing_Finished,
  1343. N2On,
  1344. PreWaferPresenceCheck,
  1345. WaferPresenceCheck,
  1346. PostN2Time,
  1347. CheckArmHome,
  1348. Abort
  1349. }
  1350. #endregion
  1351. }
  1352. }