CarrierRobotHome.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. using Aitex.Core.RT.Event;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.RT.SCCore;
  4. using Aitex.Sorter.Common;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.Common.SubstrateTrackings;
  7. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  8. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  9. using System;
  10. namespace FurnaceRT.Equipments.CarrierRobots
  11. {
  12. public class CarrierRobotHome : ModuleRoutine, IRoutine
  13. {
  14. enum RoutineStep
  15. {
  16. SetCommunication,
  17. RobotReset,
  18. RobotSetServoOn,
  19. SetLoadArm1,
  20. SetLoadArm2,
  21. Home,
  22. DoorClose,
  23. CheckLoad,
  24. SetSpeed,
  25. RobotRequestCassettePresent,
  26. UpdateWaferInfoByRobotSensor,
  27. Delay,
  28. CheckRobotIsReady,
  29. }
  30. private CarrierRobotModule _cassetteRobotModule;
  31. private int _timeout = 0;
  32. private int _speed = 1;
  33. public CarrierRobotHome(CarrierRobotModule cassetteModule)
  34. {
  35. _cassetteRobotModule = cassetteModule;
  36. Module = cassetteModule.Module;
  37. Name = "Home";
  38. }
  39. public Result Start(params object[] objs)
  40. {
  41. Reset();
  42. _timeout = SC.GetValue<int>($"{Module}.HomeTimeout");
  43. _speed = SC.GetValue<int>($"{Module}.RobotSpeed");
  44. _cassetteRobotModule.RobotHomeFailAlarm.RetryMessage = (int)CarrierRobotModule.MSG.Home;
  45. _cassetteRobotModule.RobotHomeTimeoutAlarm.RetryMessage = (int)CarrierRobotModule.MSG.Home;
  46. _cassetteRobotModule.SetSpeedFailAlarm.RetryMessage = (int)CarrierRobotModule.MSG.Home;
  47. _cassetteRobotModule.SetSpeedTimeoutAlarm.RetryMessage = (int)CarrierRobotModule.MSG.Home;
  48. _cassetteRobotModule.RequestCassettePresentFailAlarm.RetryMessage = (int)CarrierRobotModule.MSG.Home;
  49. _cassetteRobotModule.RequestCassettePresentTimeoutAlarm.RetryMessage = (int)CarrierRobotModule.MSG.Home;
  50. _cassetteRobotModule.ShutterCloseTimeoutAlarm.RetryMessage = (int)CarrierRobotModule.MSG.Home;
  51. Notify($"Start");
  52. return Result.RUN;
  53. }
  54. public void Abort()
  55. {
  56. }
  57. public override Result Monitor()
  58. {
  59. try
  60. {
  61. PauseRountine(_cassetteRobotModule.CarrierRobotDevice.IsPause);
  62. if (_cassetteRobotModule.CarrierRobotDevice.IsPause)
  63. return Result.RUN;
  64. //RobotReset((int)RoutineStep.RobotReset, _timeout);
  65. //RobotSetServoOn((int)RoutineStep.RobotSetServoOn, true, _timeout);
  66. RobotHome((int)RoutineStep.Home, _timeout);
  67. SaferDoorOpen((int)RoutineStep.DoorClose, false, _timeout);
  68. //RobotCheckLoad((int)RoutineStep.CheckLoad, Hand.Blade1, _timeout);
  69. RobotSetSpeed((int)RoutineStep.SetSpeed, _speed, _timeout);
  70. RobotRequestCassettePresent((int)RoutineStep.RobotRequestCassettePresent, Hand.Blade1, _timeout);
  71. UpdateCassetteInfoByRobotSensor((int)RoutineStep.UpdateWaferInfoByRobotSensor);
  72. CheckRobotIsReady((int)RoutineStep.CheckRobotIsReady, _timeout);
  73. if (SC.ContainsItem("System.AddRobotDelay") && SC.ContainsItem("System.RobotDelayTime") && SC.GetValue<bool>("System.AddRobotDelay"))
  74. Delay((int)RoutineStep.Delay, float.Parse(SC.GetStringValue("System.RobotDelayTime")));
  75. }
  76. catch (RoutineBreakException)
  77. {
  78. return Result.RUN;
  79. }
  80. catch (RoutineFaildException ex)
  81. {
  82. return Result.FAIL;
  83. }
  84. _cassetteRobotModule.ResetRobotActionCommand();
  85. Notify("Finished");
  86. return Result.DONE;
  87. }
  88. private void CheckRobotIsReady(int id, int timeout)
  89. {
  90. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  91. {
  92. return true;
  93. }, () =>
  94. {
  95. int count = 0;
  96. while (count < 3)
  97. {
  98. if (_cassetteRobotModule.CarrierRobotDevice.IsReady() && !_cassetteRobotModule.CarrierRobotDevice.IsError)
  99. count++;
  100. }
  101. if (count == 3)
  102. return true;
  103. return false;
  104. }, timeout * 1000);
  105. if (ret.Item1)
  106. {
  107. if (ret.Item2 == Result.FAIL)
  108. {
  109. throw (new RoutineFaildException());
  110. }
  111. else if (ret.Item2 == Result.TIMEOUT) //timeout
  112. {
  113. throw (new RoutineFaildException());
  114. }
  115. else
  116. throw (new RoutineBreakException());
  117. }
  118. }
  119. private void RobotReset(int id, int timeout)
  120. {
  121. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  122. {
  123. Notify($"Set robot reset");
  124. _cassetteRobotModule.SetCassetteRobotReset();
  125. return true;
  126. }, () =>
  127. {
  128. if (_cassetteRobotModule.CarrierRobotDevice.IsReady())
  129. {
  130. return true;
  131. }
  132. return false;
  133. }, timeout * 1000);
  134. if (ret.Item1)
  135. {
  136. if (ret.Item2 == Result.FAIL)
  137. {
  138. throw (new RoutineFaildException());
  139. }
  140. else if (ret.Item2 == Result.TIMEOUT) //timeout
  141. {
  142. _cassetteRobotModule.RobotHomeTimeoutAlarm.Set($"timeout over {timeout} seconds");
  143. throw (new RoutineFaildException());
  144. }
  145. else
  146. throw (new RoutineBreakException());
  147. }
  148. }
  149. private void RobotSetServoOn(int id, Robot robot, bool isOn, int timeout)
  150. {
  151. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  152. {
  153. Notify($"Set servo {(isOn ? "on" : "off")}");
  154. if (!robot.SetServoOnOff(isOn, out string reason))
  155. {
  156. //_cassetteRobotModule.SetServoOnFailAlarm.Description = reason;
  157. _cassetteRobotModule.SetServoOnFailAlarm.Set(reason);
  158. return false;
  159. }
  160. return true;
  161. }, () =>
  162. {
  163. if (!robot.Busy)
  164. {
  165. return true;
  166. }
  167. return false;
  168. }, timeout * 1000);
  169. if (ret.Item1)
  170. {
  171. if (ret.Item2 == Result.FAIL)
  172. {
  173. throw (new RoutineFaildException());
  174. }
  175. else if (ret.Item2 == Result.TIMEOUT) //timeout
  176. {
  177. //_cassetteRobotModule.CheckLoadTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  178. _cassetteRobotModule.CheckLoadTimeoutAlarm.Set($"timeout over {timeout} seconds");
  179. throw (new RoutineFaildException());
  180. }
  181. else
  182. throw (new RoutineBreakException());
  183. }
  184. }
  185. public void RobotSetCommunication(int id, Robot robot, int timeout)
  186. {
  187. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  188. {
  189. Notify("Set default communication");
  190. if (!robot.SetCommunication(out string reason))
  191. {
  192. Stop(reason);
  193. return false;
  194. }
  195. return true;
  196. }, () =>
  197. {
  198. if (!robot.Busy)
  199. {
  200. return true;
  201. }
  202. return false;
  203. }, timeout * 1000);
  204. if (ret.Item1)
  205. {
  206. if (ret.Item2 == Result.FAIL)
  207. {
  208. throw (new RoutineFaildException());
  209. }
  210. else if (ret.Item2 == Result.TIMEOUT) //timeout
  211. {
  212. Stop($"timeout over {timeout} seconds");
  213. throw (new RoutineFaildException());
  214. }
  215. else
  216. throw (new RoutineBreakException());
  217. }
  218. }
  219. public void RobotSetLoad(int id, Robot robot, Hand hand, int timeout)
  220. {
  221. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  222. {
  223. Notify($"Set default load {hand}");
  224. if (!robot.SetLoad(hand, out string reason))
  225. {
  226. Stop(reason);
  227. return false;
  228. }
  229. return true;
  230. }, () =>
  231. {
  232. if (!robot.Busy)
  233. {
  234. return true;
  235. }
  236. return false;
  237. }, timeout * 1000);
  238. if (ret.Item1)
  239. {
  240. if (ret.Item2 == Result.FAIL)
  241. {
  242. throw (new RoutineFaildException());
  243. }
  244. else if (ret.Item2 == Result.TIMEOUT) //timeout
  245. {
  246. Stop($"timeout over {timeout} seconds");
  247. throw (new RoutineFaildException());
  248. }
  249. else
  250. throw (new RoutineBreakException());
  251. }
  252. }
  253. public void RobotHome(int id, int timeout)
  254. {
  255. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  256. {
  257. Notify("Execute home");
  258. if (!_cassetteRobotModule.SetCassetteRobotHome(out string reason))
  259. {
  260. //_cassetteRobotModule.RobotHomeFailAlarm.Description = reason;
  261. _cassetteRobotModule.RobotHomeFailAlarm.Set(reason);
  262. return false;
  263. }
  264. return true;
  265. }, () =>
  266. {
  267. if (_cassetteRobotModule.CarrierRobotDevice.IsReady() && !_cassetteRobotModule.CarrierRobotDevice.IsError)
  268. {
  269. return true;
  270. }
  271. return false;
  272. }, timeout * 1000);
  273. if (ret.Item1)
  274. {
  275. if (ret.Item2 == Result.FAIL)
  276. {
  277. throw (new RoutineFaildException());
  278. }
  279. else if (ret.Item2 == Result.TIMEOUT) //timeout
  280. {
  281. //_cassetteRobotModule.RobotHomeTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  282. _cassetteRobotModule.RobotHomeTimeoutAlarm.Set($"timeout over {timeout} seconds");
  283. throw (new RoutineFaildException());
  284. }
  285. else
  286. throw (new RoutineBreakException());
  287. }
  288. }
  289. private void UpdateCassetteInfoByRobotSensor(int id)
  290. {
  291. Tuple<bool, Result> ret = Execute(id, () => {
  292. Notify($"Update cassette info by robot cassette present sensor");
  293. if (SC.GetValue<bool>("System.IsSimulatorMode"))
  294. return true;
  295. if (_cassetteRobotModule.CarrierRobotDevice.IsWaferPresenceOnBlade1 && !CarrierManager.Instance.CheckHasCarrier(ModuleHelper.Converter(_cassetteRobotModule.Module), 0))
  296. {
  297. EV.PostInfoLog(Module, "Cassette Robot sensor found cassette on blade 1");
  298. CarrierManager.Instance.CreateCarrier(_cassetteRobotModule.Module);
  299. }
  300. if (!_cassetteRobotModule.CarrierRobotDevice.IsWaferPresenceOnBlade1 && !CarrierManager.Instance.CheckNoCarrier(ModuleHelper.Converter(_cassetteRobotModule.Module), 0))
  301. {
  302. EV.PostInfoLog(Module, "Cassette Robot sensor no cassette on blade 1");
  303. CarrierManager.Instance.DeleteCarrier(_cassetteRobotModule.Module);
  304. }
  305. return true;
  306. });
  307. if (ret.Item1)
  308. {
  309. throw (new RoutineBreakException());
  310. }
  311. }
  312. public void RobotSetSpeed(int id, int speed, int timeout)
  313. {
  314. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  315. {
  316. if (speed > 100)
  317. speed = 100;
  318. if (speed < 1)
  319. speed = 1;
  320. Notify($"set speed to {speed}");
  321. if (!_cassetteRobotModule.SetSpeed(speed, out string reason))
  322. {
  323. //_cassetteRobotModule.SetSpeedFailAlarm.Description = reason;
  324. _cassetteRobotModule.SetSpeedFailAlarm.Set(reason);
  325. return false;
  326. }
  327. return true;
  328. }, () =>
  329. {
  330. if (_cassetteRobotModule.CarrierRobotDevice.IsReady() && !_cassetteRobotModule.CarrierRobotDevice.IsError)
  331. {
  332. return true;
  333. }
  334. return false;
  335. }, timeout * 1000);
  336. if (ret.Item1)
  337. {
  338. if (ret.Item2 == Result.FAIL)
  339. {
  340. throw (new RoutineFaildException());
  341. }
  342. else if (ret.Item2 == Result.TIMEOUT) //timeout
  343. {
  344. //_cassetteRobotModule.SetSpeedTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  345. _cassetteRobotModule.SetSpeedTimeoutAlarm.Set($"timeout over {timeout} seconds");
  346. throw (new RoutineFaildException());
  347. }
  348. else
  349. throw (new RoutineBreakException());
  350. }
  351. }
  352. private void RobotRequestCassettePresent(int id, Hand hand, int timeout)
  353. {
  354. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  355. {
  356. Notify("request cassette present");
  357. if (!_cassetteRobotModule.RequestCassettePresent(hand, out string reason))
  358. {
  359. //_cassetteRobotModule.RequestCassettePresentFailAlarm.Description = reason;
  360. _cassetteRobotModule.RequestCassettePresentFailAlarm.Set(reason);
  361. return false;
  362. }
  363. return true;
  364. }, () =>
  365. {
  366. if (_cassetteRobotModule.CarrierRobotDevice.IsReady() && !_cassetteRobotModule.CarrierRobotDevice.IsError)
  367. {
  368. return true;
  369. }
  370. return false;
  371. }, timeout * 1000);
  372. if (ret.Item1)
  373. {
  374. if (ret.Item2 == Result.FAIL)
  375. {
  376. throw (new RoutineFaildException());
  377. }
  378. else if (ret.Item2 == Result.TIMEOUT) //timeout
  379. {
  380. //_cassetteRobotModule.RequestCassettePresentTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  381. _cassetteRobotModule.RequestCassettePresentTimeoutAlarm.Set($"timeout over {timeout} seconds");
  382. throw (new RoutineFaildException());
  383. }
  384. else
  385. throw (new RoutineBreakException());
  386. }
  387. }
  388. protected void CheckCassetteInfoByRobotSensor(int id, RobotBaseDevice robot, Hand hand, bool isAfterPick)
  389. {
  390. Tuple<bool, Result> ret = Execute(id, () =>
  391. {
  392. Notify($"check wafer info by robot RQ present");
  393. if (SC.GetValue<bool>("System.IsSimulatorMode"))
  394. return true;
  395. if (hand == Hand.Blade1 || hand == Hand.Both)
  396. {
  397. if (!isAfterPick && robot.IsWaferPresenceOnBlade1)
  398. {
  399. EV.PostWarningLog(Module, "Cassette Robot sensor found cassette on blade 1");
  400. return false;
  401. }
  402. if (isAfterPick && !robot.IsWaferPresenceOnBlade1)
  403. {
  404. EV.PostInfoLog(Module, "Cassette Robot sensor no cassette on blade 1");
  405. return false;
  406. }
  407. }
  408. if (hand == Hand.Blade2 || hand == Hand.Both)
  409. {
  410. if (!isAfterPick && robot.IsWaferPresenceOnBlade2)
  411. {
  412. EV.PostWarningLog(Module, "Cassette Robot sensor found cassette on blade 2");
  413. return false;
  414. }
  415. if (isAfterPick && !robot.IsWaferPresenceOnBlade2)
  416. {
  417. EV.PostInfoLog(Module, "Cassette Robot sensor no cassette on blade 2");
  418. return false;
  419. }
  420. }
  421. return true;
  422. });
  423. if (ret.Item1)
  424. {
  425. if (ret.Item2 == Result.FAIL)
  426. {
  427. Stop($"check cassette info failed.");
  428. throw (new RoutineFaildException());
  429. }
  430. else
  431. throw (new RoutineBreakException());
  432. }
  433. }
  434. private void SaferDoorOpen(int id, bool isOpen, int timeout)
  435. {
  436. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  437. {
  438. Notify($"Shutter Door {(isOpen ? "Open" : "Close")}");
  439. if (isOpen)
  440. _cassetteRobotModule.DoorDevice.Open();
  441. else
  442. _cassetteRobotModule.DoorDevice.Close();
  443. return true;
  444. }, () =>
  445. {
  446. return isOpen ? _cassetteRobotModule.DoorDevice.OpenCloseStatus == Devices.DeviceStatus.Open : _cassetteRobotModule.DoorDevice.OpenCloseStatus == Devices.DeviceStatus.Close;
  447. }, timeout * 1000);
  448. if (ret.Item1)
  449. {
  450. if (ret.Item2 == Result.FAIL)
  451. {
  452. throw new RoutineFaildException();
  453. }
  454. else if (ret.Item2 == Result.TIMEOUT) //timeout
  455. {
  456. if (isOpen)
  457. _cassetteRobotModule.ShutterOpenTimeoutAlarm.Set($"timeout over {timeout} seconds");
  458. else
  459. _cassetteRobotModule.ShutterCloseTimeoutAlarm.Set($"timeout over {timeout} seconds");
  460. throw (new RoutineFaildException());
  461. }
  462. else
  463. throw new RoutineBreakException();
  464. }
  465. }
  466. }
  467. }