SRDRunRecipeRoutine.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using CyberX8_Core;
  7. using CyberX8_RT.Devices.AXIS;
  8. using CyberX8_RT.Devices.Facilities;
  9. using CyberX8_RT.Devices.SRD;
  10. using MECF.Framework.Common.Beckhoff.AxisProvider;
  11. using MECF.Framework.Common.RecipeCenter;
  12. using MECF.Framework.Common.Routine;
  13. using MECF.Framework.Common.Utilities;
  14. using System;
  15. namespace CyberX8_RT.Modules.SRD
  16. {
  17. public class SRDRunRecipeRoutine : RoutineBase, IRoutine
  18. {
  19. private enum SRDRunRecipeStep
  20. {
  21. RunRecipe_CloseDoor,
  22. RunRecipe_CheckOtherSRD,
  23. RunRecipe_CheckWaterPressure,
  24. RunRecipe_WaterOn,
  25. RunRecipe_CheckWaterFlow,
  26. RunRecipe_StartRotation,
  27. RunRecipe_MonitorWaterFlow,
  28. RunRecipe_WashingFinished,
  29. RunRecipe_ChangeDrySpeed,
  30. RunRecipe_Drying,
  31. RunRecipe_StopRotation,
  32. RunRecipe_CheckRotationStopped,
  33. RunRecipe_CheckRotationHomed,
  34. End
  35. }
  36. #region 常量
  37. /// <summary>
  38. /// 旋转增加时长
  39. /// </summary>
  40. private const int ROTATION_PLUS_TIME = 10;
  41. /// <summary>
  42. /// ROTATION电机转速比例
  43. /// </summary>
  44. private const int SPEED_RATIO = 1;
  45. #endregion
  46. #region 内部变量
  47. /// <summary>
  48. /// Rotation Axis
  49. /// </summary>
  50. private JetAxisBase _rotationAxis;
  51. /// <summary>
  52. /// SRD Common
  53. /// </summary>
  54. private SrdCommonDevice _srdCommon;
  55. /// <summary>
  56. /// Total SRD
  57. /// </summary>
  58. private TotalSRDDevice _totalSRDDevice;
  59. /// <summary>
  60. /// 另外SRD实例
  61. /// </summary>
  62. private SRDEntity _otherSrdEntity;
  63. /// <summary>
  64. /// Loader Common
  65. /// </summary>
  66. private SystemFacilities _systemFacilities;
  67. /// <summary>
  68. /// 是否正在用水
  69. /// </summary>
  70. private bool _isUsingWater;
  71. /// <summary>
  72. /// Recipe
  73. /// </summary>
  74. private SrdRecipe _srdRecipe;
  75. /// <summary>
  76. /// SRD rotation Provider对象
  77. /// </summary>
  78. private BeckhoffProviderAxis _rotationProviderAxis;
  79. /// <summary>
  80. /// enterTime
  81. /// </summary>
  82. private int _enterTime;
  83. /// <summary>
  84. /// 转换增加的时间
  85. /// </summary>
  86. private int _rotationPlusSecond = ROTATION_PLUS_TIME;
  87. /// <summary>
  88. /// Dry速度
  89. /// </summary>
  90. private int _drySpeed;
  91. #endregion
  92. #region 属性
  93. /// <summary>
  94. /// 是否正在用水
  95. /// </summary>
  96. public bool IsUsingWater { get { return _isUsingWater; } }
  97. #endregion
  98. /// <summary>
  99. /// 构造函数
  100. /// </summary>
  101. /// <param name="module"></param>
  102. public SRDRunRecipeRoutine(string module) : base(module)
  103. {
  104. }
  105. /// <summary>
  106. /// 中止
  107. /// </summary>
  108. public void Abort()
  109. {
  110. Runner.Stop("SRD Run Recipe Abort");
  111. }
  112. /// <summary>
  113. /// 监控
  114. /// </summary>
  115. /// <returns></returns>
  116. public RState Monitor()
  117. {
  118. Runner.Run(SRDRunRecipeStep.RunRecipe_CloseDoor, CloseDoor, CheckDoorClosedEndStatus, CheckDoorClosedStopStatus)
  119. .Wait(SRDRunRecipeStep.RunRecipe_CheckOtherSRD, CheckOtherSRD, _delay_60s)
  120. .Run(SRDRunRecipeStep.RunRecipe_CheckWaterPressure, CheckWaterPressure, _delay_1ms)
  121. .Run(SRDRunRecipeStep.RunRecipe_WaterOn, WaterOn, _delay_1ms)
  122. .WaitWithStopCondition(SRDRunRecipeStep.RunRecipe_CheckWaterFlow, CheckFlowEndStatus, CheckFlowStopStatus)
  123. .Run(SRDRunRecipeStep.RunRecipe_StartRotation, StartRotation, _delay_1ms)
  124. .WaitWithStopCondition(SRDRunRecipeStep.RunRecipe_MonitorWaterFlow, MonitorWaterFlowEndStatus, MonitorWaterFlowStopStatus)
  125. .Run(SRDRunRecipeStep.RunRecipe_WashingFinished, WashingFinished, _delay_1ms)
  126. .Run(SRDRunRecipeStep.RunRecipe_ChangeDrySpeed, ChangeSpeed, _delay_1ms)
  127. .Delay(SRDRunRecipeStep.RunRecipe_Drying, _srdRecipe.DryTime * 1000)
  128. .Run(SRDRunRecipeStep.RunRecipe_StopRotation, StopRotation, _delay_1ms)
  129. .Wait(SRDRunRecipeStep.RunRecipe_CheckRotationStopped, CheckRotationStopEndStatus, _delay_10s)
  130. .WaitWithStopCondition(SRDRunRecipeStep.RunRecipe_CheckRotationHomed, CheckRotationHomeEndStatus, CheckRotationHomedStopStatus)
  131. .End(SRDRunRecipeStep.End, NullFun, _delay_1ms);
  132. return Runner.Status;
  133. }
  134. /// <summary>
  135. /// 启动
  136. /// </summary>
  137. /// <param name="objs"></param>
  138. /// <returns></returns>
  139. public RState Start(params object[] objs)
  140. {
  141. _srdRecipe = (SrdRecipe)objs[0];
  142. if (_srdRecipe == null)
  143. {
  144. NotifyError(eEvent.ERR_SRD, "srd recipe is null", 0);
  145. return RState.Failed;
  146. }
  147. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Rotation");
  148. _srdCommon = DEVICE.GetDevice<SrdCommonDevice>($"{Module}.Common");
  149. _totalSRDDevice = DEVICE.GetDevice<TotalSRDDevice>("SRD");
  150. _systemFacilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  151. string otherSRD = Module == "SRD1" ? "SRD2" : "SRD1";
  152. _otherSrdEntity = Singleton<RouteManager>.Instance.GetModule<SRDEntity>(otherSRD);
  153. _rotationProviderAxis = BeckhoffAxisProviderManager.Instance.GetAxisProvider($"{Module}.Rotation");
  154. if (_rotationProviderAxis == null)
  155. {
  156. NotifyError(eEvent.ERR_SRD, $"{Module}.Rotation Provider is not exist", 0);
  157. return RState.Failed;
  158. }
  159. if (!CheckPreCondition())
  160. {
  161. return RState.Failed;
  162. }
  163. return Runner.Start(Module, "SRD Run Recipe Start");
  164. }
  165. /// <summary>
  166. /// Check Pre Condition
  167. /// </summary>
  168. /// <returns></returns>
  169. private bool CheckPreCondition()
  170. {
  171. //Check Rotation Home
  172. if (!_rotationAxis.IsHomed)
  173. {
  174. NotifyError(eEvent.ERR_SRD, "Rotation is not homed", 0);
  175. return false;
  176. }
  177. //Check LiftUp
  178. if (_srdCommon.CommonData.LiftUp)
  179. {
  180. NotifyError(eEvent.ERR_SRD, "LiftUp is on", 0);
  181. return false;
  182. }
  183. //Check LiftUp Status
  184. if (_srdCommon.CommonData.LiftUpStatus)
  185. {
  186. NotifyError(eEvent.ERR_SRD, "LiftUp sensor is on", 0);
  187. return false;
  188. }
  189. //Check Wafer Present
  190. if (!_srdCommon.CommonData.WaferPresent)
  191. {
  192. NotifyError(eEvent.ERR_SRD, "WaferPresent sensor is off", 0);
  193. return false;
  194. }
  195. //Check LoaderDI
  196. if (!_systemFacilities.LoaderDiEnable)
  197. {
  198. NotifyError(eEvent.ERR_SRD, "Load DI Is Disable", 0);
  199. return false;
  200. }
  201. //Check Vacuum
  202. int vacuumOnLimit = SC.GetValue<int>("SRD.ChuckVacuumOnLimit");
  203. if (!_srdCommon.CommonData.ChuckVacuum)
  204. {
  205. if (_srdCommon.CommonData.VacuumValue >= vacuumOnLimit)
  206. {
  207. LOG.WriteLog(eEvent.ERR_SRD, Module, $"VacuumValue:{_srdCommon.CommonData.VacuumValue}, VacuumOn Limit:{vacuumOnLimit}");
  208. return false;
  209. }
  210. }
  211. else
  212. {
  213. LOG.WriteLog(eEvent.ERR_SRD, Module, $"Chuck Vacuum is off");
  214. return false;
  215. }
  216. //Check Flippers
  217. if (_srdCommon.CommonData.FlippersIn150 || _srdCommon.CommonData.FlippersIn200) //|| _srdCommon.CommonData.FlippersIn100
  218. {
  219. NotifyError(eEvent.ERR_SRD, "FlippersIn is on", 0);
  220. return false;
  221. }
  222. if (!_srdCommon.CommonData.Flipper1Out150Status || !_srdCommon.CommonData.Flipper2Out150Status || !_srdCommon.CommonData.Flipper3Out150Status
  223. || !_srdCommon.CommonData.Flipper1Out200Status || !_srdCommon.CommonData.Flipper2Out200Status || !_srdCommon.CommonData.Flipper3Out200Status)
  224. //|| !_srdCommon.CommonData.Flipper1Out100Status || !_srdCommon.CommonData.Flipper2Out100Status || !_srdCommon.CommonData.Flipper3Out100Status
  225. {
  226. NotifyError(eEvent.ERR_SRD, "Flippers are at In position", 0);
  227. return false;
  228. }
  229. return true;
  230. }
  231. /// <summary>
  232. /// Close Door
  233. /// </summary>
  234. /// <param name="param"></param>
  235. /// <returns></returns>
  236. private bool CloseDoor()
  237. {
  238. if (_srdCommon.CommonData.DoorOpened)
  239. {
  240. bool result = _srdCommon.DoorCloseAction("", null);
  241. if (!result)
  242. {
  243. NotifyError(eEvent.ERR_SRD, "Door Close Action is failed", 0);
  244. return result;
  245. }
  246. }
  247. return true;
  248. }
  249. /// <summary>
  250. /// 检验DoorClosed结束状态
  251. /// </summary>
  252. /// <param name="param"></param>
  253. /// <returns></returns>
  254. private bool CheckDoorClosedEndStatus()
  255. {
  256. return _srdCommon.Status == RState.End && _srdCommon.CommonData.DoorClosed;
  257. }
  258. /// <summary>
  259. /// 检验DoorClosed结束状态
  260. /// </summary>
  261. /// <param name="param"></param>
  262. /// <returns></returns>
  263. private bool CheckDoorClosedStopStatus()
  264. {
  265. if (_srdCommon.Status == RState.Failed || _srdCommon.Status == RState.Timeout)
  266. {
  267. NotifyError(eEvent.ERR_SRD, "Check Door Closed is failed", 0);
  268. return true;
  269. }
  270. return false;
  271. }
  272. /// <summary>
  273. /// 检验另外一个SRD是否在用水
  274. /// </summary>
  275. /// <param name="param"></param>
  276. /// <returns></returns>
  277. private bool CheckOtherSRD()
  278. {
  279. return (_otherSrdEntity == null || !_otherSrdEntity.IsUsingWater);
  280. }
  281. /// <summary>
  282. /// CheckWaterPressure
  283. /// </summary>
  284. /// <returns></returns>
  285. private bool CheckWaterPressure()
  286. {
  287. if (_srdRecipe.MinWaterPressure == 0 && _srdRecipe.MaxWaterPressure == 0) return true;
  288. if (_srdCommon.CommonData.WaterPressure < _srdRecipe.MinWaterPressure)
  289. {
  290. NotifyError(eEvent.ERR_SRD, $"Water Pressure {_srdCommon.CommonData.WaterPressure} is less than recipe's MinWaterPressure {_srdRecipe.MinWaterPressure}", 0);
  291. return false;
  292. }
  293. else if(_srdCommon.CommonData.WaterPressure > _srdRecipe.MaxWaterPressure)
  294. {
  295. NotifyError(eEvent.ERR_SRD, $"Water Pressure {_srdCommon.CommonData.WaterPressure} is over recipe's MaxWaterPressure {_srdRecipe.MaxWaterPressure}", 0);
  296. return false;
  297. }
  298. return true;
  299. }
  300. /// <summary>
  301. /// Water On
  302. /// </summary>
  303. /// <param name="param"></param>
  304. /// <returns></returns>
  305. private bool WaterOn()
  306. {
  307. if (_srdRecipe.RinseTime > 0)
  308. {
  309. if (!_srdCommon.CommonData.WaterOn)
  310. {
  311. bool result = _srdCommon.WaterOn();
  312. if (result)
  313. {
  314. LOG.WriteLog(eEvent.INFO_SRD, Module, "Water On");
  315. _isUsingWater = true;
  316. _enterTime = Environment.TickCount;
  317. }
  318. else
  319. {
  320. NotifyError(eEvent.ERR_SRD, "Water On is failed", 0);
  321. }
  322. return result;
  323. }
  324. return true;
  325. }
  326. return true;
  327. }
  328. /// <summary>
  329. /// Check Flow End
  330. /// </summary>
  331. /// <returns></returns>
  332. private bool CheckFlowEndStatus()
  333. {
  334. if (_srdRecipe.FlowCheckDelay == 0)
  335. {
  336. return true;
  337. }
  338. int ticks = Environment.TickCount - _enterTime;
  339. if (ticks >= _srdRecipe.FlowCheckDelay * 1000)
  340. {
  341. if (WaterFlowCheck()) return true;
  342. }
  343. return false;
  344. }
  345. /// <summary>
  346. /// Check Flow Stop
  347. /// </summary>
  348. /// <param name="param"></param>
  349. /// <returns></returns>
  350. private bool CheckFlowStopStatus()
  351. {
  352. int ticks = Environment.TickCount - _enterTime;
  353. if (ticks >= _srdRecipe.FlowCheckDelay * 1000)
  354. {
  355. if (!WaterFlowCheck()) return true;
  356. }
  357. return false;
  358. }
  359. /// <summary>
  360. /// WaterFlow检测
  361. /// </summary>
  362. /// <returns></returns>
  363. private bool WaterFlowCheck()
  364. {
  365. if (_srdRecipe.MaxSRDWaterFlow == 0 && _srdRecipe.MinSRDWaterFlow == 0) return true;
  366. if (_srdCommon.CommonData.WaterFlow > _srdRecipe.MaxSRDWaterFlow)
  367. {
  368. NotifyError(eEvent.ERR_SRD, $"{Module} Water Flow:{_srdCommon.CommonData.WaterFlow} is over recipe's MaxSRDWaterFlow:{_srdRecipe.MaxSRDWaterFlow}", 0);
  369. return false;
  370. }
  371. else if (_srdCommon.CommonData.WaterFlow < _srdRecipe.MinSRDWaterFlow)
  372. {
  373. NotifyError(eEvent.ERR_SRD, $"{Module} Water Flow:{_srdCommon.CommonData.WaterFlow} is less than recipe's MinSRDWaterFlow:{_srdRecipe.MinSRDWaterFlow}", 0);
  374. return false;
  375. }
  376. return true;
  377. }
  378. /// <summary>
  379. /// 开始旋转
  380. /// </summary>
  381. /// <param name="param"></param>
  382. /// <returns></returns>
  383. private bool StartRotation()
  384. {
  385. if (!_srdCommon.RotationInterLock())
  386. {
  387. return false;
  388. }
  389. double _scale = _rotationProviderAxis.ScaleFactor;
  390. //rinse 目标位置
  391. double rinsePosition = _srdRecipe.RinseTime * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_srdRecipe.RinseSpeed);
  392. //dry目标位置
  393. double dryPosition = BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_srdRecipe.DrySpeed) * _srdRecipe.DryTime;
  394. //为了让 rotation 不停止,增加了旋转时间(覆盖Arm运动时间)
  395. double plusPosition = BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_srdRecipe.DrySpeed) * _rotationPlusSecond;
  396. int targetPosition = (int)Math.Round((rinsePosition + dryPosition + plusPosition) * _scale, 0);
  397. int rotationSpeed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_srdRecipe.RinseSpeed), 0);
  398. _drySpeed = (int)Math.Round(_scale * BeckhoffVelocityUtil.ConvertVelocityToDegPerSecondByRPM(_srdRecipe.DrySpeed * SPEED_RATIO), 0);
  399. bool result = _rotationAxis.ProfilePosition(targetPosition, rotationSpeed * SPEED_RATIO, 0, 0);
  400. if (!result)
  401. {
  402. NotifyError(eEvent.ERR_SRD, "Start Rotation is failed", 0);
  403. return false;
  404. }
  405. LOG.WriteLog(eEvent.INFO_SRD, Module, "Start Rotation");
  406. //Rinse开始时间
  407. _enterTime = Environment.TickCount;
  408. return true;
  409. }
  410. /// <summary>
  411. /// WaterFlow End Monitor
  412. /// </summary>
  413. /// <returns></returns>
  414. private bool MonitorWaterFlowEndStatus()
  415. {
  416. int ticks = Environment.TickCount - _enterTime;
  417. if (ticks >= _srdRecipe.RinseTime * 1000)
  418. {
  419. return true;
  420. }
  421. return false;
  422. }
  423. /// <summary>
  424. /// WaterFlow Stop Monitor
  425. /// </summary>
  426. /// <returns></returns>
  427. private bool MonitorWaterFlowStopStatus()
  428. {
  429. int ticks = Environment.TickCount - _enterTime;
  430. if (ticks < _srdRecipe.RinseTime * 1000)
  431. {
  432. if (!WaterFlowCheck()) return true;
  433. }
  434. return false;
  435. }
  436. /// <summary>
  437. /// Washing Finished
  438. /// </summary>
  439. /// <returns></returns>
  440. private bool WashingFinished()
  441. {
  442. if (_srdCommon.CommonData.WaterOn)
  443. {
  444. if (!_srdCommon.WaterOff())
  445. {
  446. NotifyError(eEvent.ERR_SRD, "Water Off is failed", 0);
  447. return false;
  448. }
  449. }
  450. _isUsingWater = false;
  451. return true;
  452. }
  453. /// <summary>
  454. /// change Dry speed
  455. /// </summary>
  456. /// <returns></returns>
  457. private bool ChangeSpeed()
  458. {
  459. //调整速度为 drySpeed
  460. bool result = _rotationAxis.WriteSpeed(_drySpeed);
  461. if (!result)
  462. {
  463. NotifyError(eEvent.ERR_SRD, "Change Speed to Dry Speed is failed", 0);
  464. return false;
  465. }
  466. return true;
  467. }
  468. /// <summary>
  469. /// 停止旋转
  470. /// </summary>
  471. /// <returns></returns>
  472. private bool StopRotation()
  473. {
  474. bool result = _rotationAxis.StopPositionOperation();
  475. LOG.WriteLog(eEvent.INFO_SRD, Module, "Stop Rotation is done");
  476. return result;
  477. }
  478. /// <summary>
  479. /// 检验Rotation是否停止
  480. /// </summary>
  481. /// <returns></returns>
  482. private bool CheckRotationStopEndStatus()
  483. {
  484. if (!_rotationAxis.IsRun && _rotationAxis.Status == RState.End)
  485. {
  486. bool homeResult = _rotationAxis.Home();
  487. if (!homeResult)
  488. {
  489. NotifyError(eEvent.ERR_SRD, $"{Module}.Rotation home action is failed", 0);
  490. return false;
  491. }
  492. return true;
  493. }
  494. return false;
  495. }
  496. /// <summary>
  497. /// 检验RotationHome是否完成
  498. /// </summary>
  499. /// <returns></returns>
  500. private bool CheckRotationHomeEndStatus()
  501. {
  502. if (_rotationAxis.IsHomed && _rotationAxis.Status == RState.End)
  503. {
  504. return true;
  505. }
  506. return false;
  507. }
  508. /// <summary>
  509. /// 检验Rotation Home 停止状态
  510. /// </summary>
  511. /// <returns></returns>
  512. private bool CheckRotationHomedStopStatus()
  513. {
  514. if(_rotationAxis.Status == RState.Failed || _rotationAxis.Status == RState.Timeout)
  515. {
  516. NotifyError(eEvent.ERR_SRD, $"{Module}.Rotation home is failed", 0);
  517. return true;
  518. }
  519. return false;
  520. }
  521. }
  522. }