BoatMove.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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. return true;
  178. }, () =>
  179. {
  180. var pm = (Singleton<EquipmentManager>.Instance.Modules[ModuleName.PM1] as PMModule);
  181. var isCheckO2Enbale = pm.CheckBoatMoveIsNeedOxygenPressure(boatMoveN2Purge, pm.IsProcessing, out var o2LimtData);
  182. if (!isCheckO2Enbale)
  183. return true;
  184. _filterChecker.Monitor(pm.GetN2PurgeUnder20PPMStatus(o2LimtData));
  185. if (_filterChecker.Trig)
  186. {
  187. pm.IsWait = false;
  188. LOG.Info($"{boatMoveN2Purge} Check O2Desity,TransferRoomO2DensityCheckEnable={isCheckO2Enbale},LA LimtData={o2LimtData},Wait {boatMoveN2Purge}。A");
  189. _filterChecker.Restart();
  190. return true;
  191. }
  192. if (!pm.IsWait)
  193. {
  194. pm.IsWait = true;
  195. }
  196. return false; ;
  197. }, timeout * 1000);
  198. if (ret.Item1)
  199. {
  200. if (ret.Item2 == Result.FAIL)
  201. {
  202. throw (new RoutineFaildException());
  203. }
  204. else if (ret.Item2 == Result.TIMEOUT) //timeout
  205. {
  206. _boatModule.BoatZAxisMoveFailedForInterlock.Set($"{boatMoveN2Purge} CheckO2Desity timeout={timeout}");
  207. throw (new RoutineFaildException());
  208. }
  209. else
  210. throw (new RoutineBreakException());
  211. }
  212. }
  213. private void CheckPrepareMove(int id, int timeout)
  214. {
  215. var reason = "";
  216. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  217. {
  218. Notify($"Check boat move enable");
  219. return true;
  220. }, () =>
  221. {
  222. return _boatModule.CheckPrepareMove(out reason);
  223. }, timeout * 2 * 1000);
  224. if (ret.Item1)
  225. {
  226. if (ret.Item2 == Result.FAIL)
  227. {
  228. throw (new RoutineFaildException());
  229. }
  230. else if (ret.Item2 == Result.TIMEOUT) //timeout
  231. {
  232. _boatModule.BoatZAxisMoveFailedForInterlock.Set($"{reason} is not OK, can not complete in {timeout} seconds");
  233. throw (new RoutineFaildException());
  234. }
  235. else
  236. throw (new RoutineBreakException());
  237. }
  238. }
  239. private void AutoShutterOpen(int id, bool isOpen, int timeout)
  240. {
  241. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  242. {
  243. Notify($"shutter {(isOpen ? "open" : "close")}");
  244. string reason;
  245. if (!_boatModule.ShutterDevice.SetOpen(isOpen, out reason))
  246. {
  247. _boatModule.ShutterDevice.AutoShutterMoveFailedForInterlock.Set();
  248. return false;
  249. }
  250. return true;
  251. }, () =>
  252. {
  253. return isOpen ? _boatModule.ShutterDevice.OpenCloseStatus == DeviceStatus.Open : _boatModule.ShutterDevice.OpenCloseStatus == DeviceStatus.Close;
  254. }, timeout * 1000);
  255. if (ret.Item1)
  256. {
  257. if (ret.Item2 == Result.FAIL)
  258. {
  259. throw (new RoutineFaildException());
  260. }
  261. else if (ret.Item2 == Result.TIMEOUT) //timeout
  262. {
  263. if (isOpen)
  264. {
  265. _boatModule.ShutterDevice.AutoShutterOpenTimeOut.Set($"can not complete in {timeout} seconds");
  266. }
  267. else
  268. {
  269. _boatModule.ShutterDevice.AutoShutterCloseTimeOut.Set($"can not complete in {timeout} seconds");
  270. }
  271. throw (new RoutineFaildException());
  272. }
  273. else
  274. throw (new RoutineBreakException());
  275. }
  276. }
  277. private void SetBoatZAxisMove(int id, BoatPosition position, float speed, int timeout)
  278. {
  279. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  280. {
  281. Notify($"Boat ZAxis movet to {position}");
  282. string reason;
  283. if (!_boatModule.ZAxisDevice.SetServoMoveTo(position.ToString(), out reason, speed))
  284. {
  285. //_boatModule.BoatDevice.BoatRAxisMoveFailedForInterlock.Description = reason;
  286. _boatModule.BoatZAxisMoveFailedForInterlock.Set(reason);
  287. }
  288. return true;
  289. }, () =>
  290. {
  291. if (_boatModule.ZAxisDevice.IsError)
  292. return null;
  293. return _boatModule.ZAxisDevice.CheckServoAtPosition(position.ToString());
  294. }, timeout * 2 * 1000);
  295. if (ret.Item1)
  296. {
  297. if (ret.Item2 == Result.FAIL)
  298. {
  299. _boatModule.ZAxisDevice.ServoStop();
  300. throw (new RoutineFaildException());
  301. }
  302. else if (ret.Item2 == Result.TIMEOUT) //timeout
  303. {
  304. _boatModule.ZAxisDevice.ServoStop();
  305. _boatModule.BoatZAxisMoveTimeOut.Set($"can not complete in {timeout} seconds");
  306. throw (new RoutineFaildException());
  307. }
  308. else
  309. throw (new RoutineBreakException());
  310. }
  311. }
  312. private void SetBoatZAxisMoveStop(int id)
  313. {
  314. Tuple<bool, Result> ret = Execute(id, () =>
  315. {
  316. Notify($"Set ZAxis boat stop");
  317. _boatModule.ZAxisDevice.ServoStop();
  318. return true;
  319. });
  320. if (ret.Item1)
  321. {
  322. if (ret.Item2 == Result.FAIL)
  323. {
  324. throw (new RoutineFaildException());
  325. }
  326. else
  327. throw (new RoutineBreakException());
  328. }
  329. }
  330. private void SetBoatRAxisMoveStop(int id)
  331. {
  332. Tuple<bool, Result> ret = Execute(id, () =>
  333. {
  334. Notify($"Set RAxis boat stop");
  335. _boatModule.RAxisDevice.ServoStop();
  336. return true;
  337. });
  338. if (ret.Item1)
  339. {
  340. if (ret.Item2 == Result.FAIL)
  341. {
  342. throw (new RoutineFaildException());
  343. }
  344. else
  345. throw (new RoutineBreakException());
  346. }
  347. }
  348. private void SetBoatRAxisHome(int id, int timeout)
  349. {
  350. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  351. {
  352. Notify($"Boat RAxis home");
  353. if (!_boatModule.RAxisDevice.SetServoHome())
  354. {
  355. _boatModule.BoatRAxisHomeFailed.Set();
  356. }
  357. return true;
  358. }, () =>
  359. {
  360. if (_boatModule.RAxisDevice.IsError)
  361. return null;
  362. return _boatModule.RAxisDevice.IsHomeDone && _boatModule.RAxisDevice.IsReady;
  363. }, timeout * 1000);
  364. if (ret.Item1)
  365. {
  366. if (ret.Item2 == Result.FAIL)
  367. {
  368. _boatModule.RAxisDevice.ServoStop();
  369. throw (new RoutineFaildException());
  370. }
  371. else if (ret.Item2 == Result.TIMEOUT) //timeout
  372. {
  373. _boatModule.RAxisDevice.ServoStop();
  374. _boatModule.BoatRAxisHomeTimeout.Set($"can not complete in {timeout} seconds");
  375. throw (new RoutineFaildException());
  376. }
  377. else
  378. throw (new RoutineBreakException());
  379. }
  380. }
  381. private void SetBoatRAxisMove(int id, BoatRotationDirection direction, float speed, int timeout)
  382. {
  383. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  384. {
  385. Notify($"Boat RAxis {direction}");
  386. string reason;
  387. if (!_boatModule.RAxisDevice.SetServoMoveTo(direction.ToString(), out reason, speed))
  388. {
  389. //_boatModule.BoatDevice.BoatRAxisMoveFailedForInterlock.Description = reason;
  390. _boatModule.BoatRAxisMoveFailedForInterlock.Set(reason);
  391. }
  392. return true;
  393. }, () =>
  394. {
  395. if (_boatModule.RAxisDevice.IsError)
  396. return null;
  397. return _boatModule.RAxisDevice.IsMoving;
  398. }, timeout * 2 * 1000);
  399. if (ret.Item1)
  400. {
  401. if (ret.Item2 == Result.FAIL)
  402. {
  403. _boatModule.RAxisDevice.ServoStop();
  404. throw (new RoutineFaildException());
  405. }
  406. else if (ret.Item2 == Result.TIMEOUT) //timeout
  407. {
  408. _boatModule.RAxisDevice.ServoStop();
  409. _boatModule.BoatRAxisMoveTimeOut.Set($"can not complete in {timeout} seconds");
  410. throw (new RoutineFaildException());
  411. }
  412. else
  413. throw (new RoutineBreakException());
  414. }
  415. }
  416. }
  417. }