RunWaferRecipeStateMachine.cs 54 KB

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