BoatMove.cs 19 KB

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