BoatMove.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Device.Unit;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Routine;
  5. using Aitex.Core.RT.SCCore;
  6. using Aitex.Core.Util;
  7. using Aitex.Sorter.Common;
  8. using MECF.Framework.Common.Alarms;
  9. using MECF.Framework.Common.Device.Bases;
  10. using MECF.Framework.Common.Equipment;
  11. using MECF.Framework.Common.SubstrateTrackings;
  12. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using FurnaceRT.Equipments.Systems;
  19. using static Aitex.Core.RT.Device.Unit.IoBoat;
  20. using System.Diagnostics;
  21. using FurnaceRT.Devices;
  22. using FurnaceRT.Equipments.PMs;
  23. using MECF.Framework.Common.Tolerance;
  24. using MECF.Framework.Common.CommonData.SorterDefines;
  25. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.PMs;
  26. using Aitex.Core.RT.Log;
  27. namespace FurnaceRT.Equipments.Boats
  28. {
  29. public class BoatMove : ModuleRoutine, IRoutine
  30. {
  31. enum RoutineStep
  32. {
  33. SetBoatSpeed,
  34. SetBoatDirection,
  35. BoatRAxisHome,
  36. BoatRAxisMove,
  37. SetBoatZAxisMoveStop,
  38. SetBoatRAxisMoveStop,
  39. SetBoatInterval,
  40. CheckPrepareMove,
  41. Load,
  42. Unload,
  43. Delay1,
  44. Delay2,
  45. Delay3,
  46. ZMoveToStart,
  47. ZMoveToEnd,
  48. ZMove,
  49. AutoShutterOpen,
  50. AutoShutterClose,
  51. }
  52. private BoatModule _boatModule;
  53. private int _zAxisTimeout = 0;
  54. private int _rAxisTimeout = 0;
  55. private int _shutterTimeout = 0;
  56. private string _command;
  57. private string _position;
  58. private float _speed;
  59. private FilterChecker _filterChecker = new FilterChecker();
  60. public BoatMove(BoatModule boatModule)
  61. {
  62. _boatModule = boatModule;
  63. Module = boatModule.Module;
  64. Name = "Move";
  65. }
  66. public void Init(string command, string position, string speed)
  67. {
  68. _command = command;
  69. _position = position;
  70. float.TryParse(speed, out _speed);
  71. var para = new List<object> { _command, _position, _speed };
  72. _boatModule.BoatZAxisMoveFailedForInterlock.RetryMessage = (int)BoatModule.MSG.BoatMoveRetry;
  73. _boatModule.BoatZAxisMoveFailedForInterlock.RetryMessageParas = para.ToArray();
  74. _boatModule.BoatZAxisMoveFailedForHumanInterlock.RetryMessage = (int)BoatModule.MSG.BoatMoveRetry;
  75. _boatModule.BoatZAxisMoveFailedForHumanInterlock.RetryMessageParas = para.ToArray();
  76. _boatModule.BoatZAxisMoveFailedForWaferRobotArmExtend.RetryMessage = (int)BoatModule.MSG.BoatMoveRetry;
  77. _boatModule.BoatZAxisMoveFailedForWaferRobotArmExtend.RetryMessageParas = para.ToArray();
  78. _boatModule.BoatZAxisMoveTimeOut.RetryMessage = (int)BoatModule.MSG.BoatMoveRetry;
  79. _boatModule.BoatZAxisMoveTimeOut.RetryMessageParas = para.ToArray();
  80. _boatModule.AutoShutterMoveFailedForInterlock.RetryMessage = (int)BoatModule.MSG.BoatMoveRetry;
  81. _boatModule.AutoShutterMoveFailedForInterlock.RetryMessageParas = para.ToArray();
  82. _boatModule.AutoShutterOpenTimeOut.RetryMessage = (int)BoatModule.MSG.BoatMoveRetry;
  83. _boatModule.AutoShutterOpenTimeOut.RetryMessageParas = para.ToArray();
  84. _boatModule.AutoShutterCloseTimeOut.RetryMessage = (int)BoatModule.MSG.BoatMoveRetry;
  85. _boatModule.AutoShutterCloseTimeOut.RetryMessageParas = para.ToArray();
  86. _boatModule.BoatRAxisMoveTimeOut.RetryMessage = (int)BoatModule.MSG.BoatMoveRetry;
  87. _boatModule.BoatRAxisMoveTimeOut.RetryMessageParas = para.ToArray();
  88. }
  89. public Result Start(params object[] objs)
  90. {
  91. Reset();
  92. _zAxisTimeout = SC.GetValue<int>($"{Module}.BoatElevatorServo.MotionTimeout");
  93. _rAxisTimeout = SC.GetValue<int>($"{Module}.BoatRotationServo.MotionTimeout");
  94. _shutterTimeout = SC.GetValue<int>($"{Module}.AutoShutter.MotionTimeout");
  95. var isBeforeShutter = new List<string>() { "boatload", "boatcap2", "boatunload", "boatloaderhome", };
  96. if (!string.IsNullOrEmpty(_command) && isBeforeShutter.Contains(_command))
  97. {
  98. string reason = "";
  99. if (!_boatModule.CheckPrepareMove(out reason, false))
  100. {
  101. _boatModule.BoatZAxisMoveFailedForInterlock.Set(reason);
  102. //return Result.FAIL;
  103. }
  104. }
  105. _filterChecker.CheckInterval = 1;
  106. Notify($"Start");
  107. return Result.RUN;
  108. }
  109. public void Abort()
  110. {
  111. if (_boatModule.CheckPrepareMove(out _, false))
  112. {
  113. _boatModule.ZAxisDevice.ServoStop();
  114. _boatModule.RAxisDevice.ServoStop();
  115. }
  116. }
  117. public override Result Monitor()
  118. {
  119. try
  120. {
  121. PauseRountine(_boatModule.RAxisDevice.IsPause);
  122. if (_boatModule.RAxisDevice.IsPause)
  123. return Result.RUN;
  124. if (_boatModule.RAxisDevice.IsError || _boatModule.ZAxisDevice.IsError)
  125. return Result.FAIL;
  126. switch (_command)
  127. {
  128. case "boatload":
  129. case "boatcap2":
  130. AutoShutterOpen((int)RoutineStep.AutoShutterOpen, true, _shutterTimeout);
  131. CheckBoatMoveO2Desity((int)RoutineStep.Load, _zAxisTimeout, N2PurgeModeEnum.BoatLoad.ToString());
  132. var position = (BoatPosition)Enum.Parse(typeof(BoatPosition), _position);
  133. SetBoatZAxisMove((int)RoutineStep.ZMove, position, _speed, (int)_zAxisTimeout);
  134. break;
  135. case "boatunload":
  136. case "boatloaderhome":
  137. AutoShutterOpen((int)RoutineStep.AutoShutterOpen, true, _shutterTimeout);
  138. CheckBoatMoveO2Desity((int)RoutineStep.Unload, _zAxisTimeout, N2PurgeModeEnum.BoatUnLoad.ToString());
  139. //CheckPrepareMove((int)RoutineStep.CheckPrepareMove, 2);
  140. position = (BoatPosition)Enum.Parse(typeof(BoatPosition), _position);
  141. SetBoatZAxisMove((int)RoutineStep.ZMove, position, _speed, (int)_zAxisTimeout);
  142. AutoShutterOpen((int)RoutineStep.AutoShutterClose, false, _shutterTimeout);
  143. break;
  144. case "boatrotate":
  145. var direction = (BoatRotationDirection)Enum.Parse(typeof(BoatRotationDirection), _position);
  146. SetBoatRAxisMove((int)RoutineStep.BoatRAxisMove, direction, _speed, _rAxisTimeout);
  147. break;
  148. case "boatrotatestop"://r home
  149. SetBoatRAxisMoveStop((int)RoutineStep.SetBoatRAxisMoveStop);
  150. Delay((int)RoutineStep.Delay1, 2);
  151. SetBoatRAxisHome((int)RoutineStep.BoatRAxisHome, _rAxisTimeout);
  152. break;
  153. case "stop(includer-axis)":
  154. SetBoatZAxisMoveStop((int)RoutineStep.SetBoatZAxisMoveStop);
  155. SetBoatRAxisMoveStop((int)RoutineStep.SetBoatRAxisMoveStop);
  156. break;
  157. }
  158. }
  159. catch (RoutineBreakException)
  160. {
  161. return Result.RUN;
  162. }
  163. catch (RoutineFaildException ex)
  164. {
  165. //_boatModule.RAxisDevice.ServoStop();
  166. return Result.FAIL;
  167. }
  168. Notify("Finished");
  169. return Result.DONE;
  170. }
  171. private void CheckBoatMoveO2Desity(int id, int timeout, string boatMoveN2Purge)
  172. {
  173. var reason = "";
  174. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  175. {
  176. Notify($"Check {boatMoveN2Purge} O2Desity");
  177. var pm = (Singleton<EquipmentManager>.Instance.Modules[ModuleName.PM1] as PMModule);
  178. var isCheckO2Enbale = pm.CheckBoatMoveIsNeedOxygenPressure(boatMoveN2Purge, pm.IsProcessing, out var o2LimtData);
  179. if (isCheckO2Enbale)
  180. {
  181. pm.SetN2PurgeValveData(N2PurgeModeEnum.Manual_phase1.ToString());
  182. pm.RestAllN2PrugeRD();
  183. }
  184. return true;
  185. }, () =>
  186. {
  187. var pm = (Singleton<EquipmentManager>.Instance.Modules[ModuleName.PM1] as PMModule);
  188. var isCheckO2Enbale = pm.CheckBoatMoveIsNeedOxygenPressure(boatMoveN2Purge, pm.IsProcessing, out var o2LimtData);
  189. if (!isCheckO2Enbale)
  190. return true;
  191. _filterChecker.Monitor(pm.GetN2PurgeUnder20PPMStatus(o2LimtData)&&pm.CheckIsLASide());
  192. if (_filterChecker.Trig)
  193. {
  194. pm.IsWait = false;
  195. LOG.Info($"{boatMoveN2Purge} Check O2Desity,TransferRoomO2DensityCheckEnable={isCheckO2Enbale},LA LimtData={o2LimtData},Wait {boatMoveN2Purge}。A");
  196. _filterChecker.Restart();
  197. return true;
  198. }
  199. if (!pm.IsWait)
  200. {
  201. pm.IsWait = true;
  202. }
  203. return false; ;
  204. }, timeout * 1000);
  205. if (ret.Item1)
  206. {
  207. if (ret.Item2 == Result.FAIL)
  208. {
  209. throw (new RoutineFaildException());
  210. }
  211. else if (ret.Item2 == Result.TIMEOUT) //timeout
  212. {
  213. _boatModule.BoatZAxisMoveFailedForInterlock.Set($"{boatMoveN2Purge} CheckO2Desity timeout={timeout}");
  214. throw (new RoutineFaildException());
  215. }
  216. else
  217. throw (new RoutineBreakException());
  218. }
  219. }
  220. private void CheckPrepareMove(int id, int timeout)
  221. {
  222. var reason = "";
  223. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  224. {
  225. Notify($"Check boat move enable");
  226. return true;
  227. }, () =>
  228. {
  229. return _boatModule.CheckPrepareMove(out reason);
  230. }, timeout * 2 * 1000);
  231. if (ret.Item1)
  232. {
  233. if (ret.Item2 == Result.FAIL)
  234. {
  235. throw (new RoutineFaildException());
  236. }
  237. else if (ret.Item2 == Result.TIMEOUT) //timeout
  238. {
  239. _boatModule.BoatZAxisMoveFailedForInterlock.Set($"{reason} is not OK, can not complete in {timeout} seconds");
  240. throw (new RoutineFaildException());
  241. }
  242. else
  243. throw (new RoutineBreakException());
  244. }
  245. }
  246. private void AutoShutterOpen(int id, bool isOpen, int timeout)
  247. {
  248. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  249. {
  250. Notify($"shutter {(isOpen ? "open" : "close")}");
  251. string reason;
  252. if (!_boatModule.ShutterDevice.SetOpen(isOpen, out reason))
  253. {
  254. _boatModule.ShutterDevice.AutoShutterMoveFailedForInterlock.Set();
  255. return false;
  256. }
  257. return true;
  258. }, () =>
  259. {
  260. return isOpen ? _boatModule.ShutterDevice.OpenCloseStatus == DeviceStatus.Open : _boatModule.ShutterDevice.OpenCloseStatus == DeviceStatus.Close;
  261. }, timeout * 1000);
  262. if (ret.Item1)
  263. {
  264. if (ret.Item2 == Result.FAIL)
  265. {
  266. throw (new RoutineFaildException());
  267. }
  268. else if (ret.Item2 == Result.TIMEOUT) //timeout
  269. {
  270. if (isOpen)
  271. {
  272. _boatModule.ShutterDevice.AutoShutterOpenTimeOut.Set($"can not complete in {timeout} seconds");
  273. }
  274. else
  275. {
  276. _boatModule.ShutterDevice.AutoShutterCloseTimeOut.Set($"can not complete in {timeout} seconds");
  277. }
  278. throw (new RoutineFaildException());
  279. }
  280. else
  281. throw (new RoutineBreakException());
  282. }
  283. }
  284. private void SetBoatZAxisMove(int id, BoatPosition position, float speed, int timeout)
  285. {
  286. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  287. {
  288. Notify($"Boat ZAxis movet to {position}");
  289. string reason;
  290. if (!_boatModule.ZAxisDevice.SetServoMoveTo(position.ToString(), out reason, speed))
  291. {
  292. //_boatModule.BoatDevice.BoatRAxisMoveFailedForInterlock.Description = reason;
  293. _boatModule.BoatZAxisMoveFailedForInterlock.Set(reason);
  294. }
  295. return true;
  296. }, () =>
  297. {
  298. if (_boatModule.ZAxisDevice.IsError)
  299. return null;
  300. return _boatModule.ZAxisDevice.CheckServoAtPosition(position.ToString());
  301. }, timeout * 2 * 1000);
  302. if (ret.Item1)
  303. {
  304. if (ret.Item2 == Result.FAIL)
  305. {
  306. _boatModule.ZAxisDevice.ServoStop();
  307. throw (new RoutineFaildException());
  308. }
  309. else if (ret.Item2 == Result.TIMEOUT) //timeout
  310. {
  311. _boatModule.ZAxisDevice.ServoStop();
  312. _boatModule.BoatZAxisMoveTimeOut.Set($"can not complete in {timeout} seconds");
  313. throw (new RoutineFaildException());
  314. }
  315. else
  316. throw (new RoutineBreakException());
  317. }
  318. }
  319. private void SetBoatZAxisMoveStop(int id)
  320. {
  321. Tuple<bool, Result> ret = Execute(id, () =>
  322. {
  323. Notify($"Set ZAxis boat stop");
  324. _boatModule.ZAxisDevice.ServoStop();
  325. return true;
  326. });
  327. if (ret.Item1)
  328. {
  329. if (ret.Item2 == Result.FAIL)
  330. {
  331. throw (new RoutineFaildException());
  332. }
  333. else
  334. throw (new RoutineBreakException());
  335. }
  336. }
  337. private void SetBoatRAxisMoveStop(int id)
  338. {
  339. Tuple<bool, Result> ret = Execute(id, () =>
  340. {
  341. Notify($"Set RAxis boat stop");
  342. _boatModule.RAxisDevice.ServoStop();
  343. return true;
  344. });
  345. if (ret.Item1)
  346. {
  347. if (ret.Item2 == Result.FAIL)
  348. {
  349. throw (new RoutineFaildException());
  350. }
  351. else
  352. throw (new RoutineBreakException());
  353. }
  354. }
  355. private void SetBoatRAxisHome(int id, int timeout)
  356. {
  357. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  358. {
  359. Notify($"Boat RAxis home");
  360. if (!_boatModule.RAxisDevice.SetServoHome())
  361. {
  362. _boatModule.BoatRAxisHomeFailed.Set();
  363. }
  364. return true;
  365. }, () =>
  366. {
  367. if (_boatModule.RAxisDevice.IsError)
  368. return null;
  369. return _boatModule.RAxisDevice.IsHomeDone && _boatModule.RAxisDevice.IsReady;
  370. }, timeout * 1000);
  371. if (ret.Item1)
  372. {
  373. if (ret.Item2 == Result.FAIL)
  374. {
  375. _boatModule.RAxisDevice.ServoStop();
  376. throw (new RoutineFaildException());
  377. }
  378. else if (ret.Item2 == Result.TIMEOUT) //timeout
  379. {
  380. _boatModule.RAxisDevice.ServoStop();
  381. _boatModule.BoatRAxisHomeTimeout.Set($"can not complete in {timeout} seconds");
  382. throw (new RoutineFaildException());
  383. }
  384. else
  385. throw (new RoutineBreakException());
  386. }
  387. }
  388. private void SetBoatRAxisMove(int id, BoatRotationDirection direction, float speed, int timeout)
  389. {
  390. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  391. {
  392. Notify($"Boat RAxis {direction}");
  393. string reason;
  394. if (!_boatModule.RAxisDevice.SetServoMoveTo(direction.ToString(), out reason, speed))
  395. {
  396. //_boatModule.BoatDevice.BoatRAxisMoveFailedForInterlock.Description = reason;
  397. _boatModule.BoatRAxisMoveFailedForInterlock.Set(reason);
  398. }
  399. return true;
  400. }, () =>
  401. {
  402. if (_boatModule.RAxisDevice.IsError)
  403. return null;
  404. return _boatModule.RAxisDevice.IsMoving;
  405. }, timeout * 2 * 1000);
  406. if (ret.Item1)
  407. {
  408. if (ret.Item2 == Result.FAIL)
  409. {
  410. _boatModule.RAxisDevice.ServoStop();
  411. throw (new RoutineFaildException());
  412. }
  413. else if (ret.Item2 == Result.TIMEOUT) //timeout
  414. {
  415. _boatModule.RAxisDevice.ServoStop();
  416. _boatModule.BoatRAxisMoveTimeOut.Set($"can not complete in {timeout} seconds");
  417. throw (new RoutineFaildException());
  418. }
  419. else
  420. throw (new RoutineBreakException());
  421. }
  422. }
  423. }
  424. }