BoatMove.cs 20 KB

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