CarrierRobotHome.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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. Notify("Check Robot IsReady");
  93. return true;
  94. }, () =>
  95. {
  96. int count = 0;
  97. while (count < 3)
  98. {
  99. if (_cassetteRobotModule.CarrierRobotDevice.IsReady() && !_cassetteRobotModule.CarrierRobotDevice.IsError)
  100. count++;
  101. }
  102. if (count == 3)
  103. return true;
  104. return false;
  105. }, timeout * 1000);
  106. if (ret.Item1)
  107. {
  108. if (ret.Item2 == Result.FAIL)
  109. {
  110. throw (new RoutineFaildException());
  111. }
  112. else if (ret.Item2 == Result.TIMEOUT) //timeout
  113. {
  114. throw (new RoutineFaildException());
  115. }
  116. else
  117. throw (new RoutineBreakException());
  118. }
  119. }
  120. private void RobotReset(int id, int timeout)
  121. {
  122. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  123. {
  124. Notify($"Set robot reset");
  125. _cassetteRobotModule.SetCassetteRobotReset();
  126. return true;
  127. }, () =>
  128. {
  129. if (_cassetteRobotModule.CarrierRobotDevice.IsReady())
  130. {
  131. return true;
  132. }
  133. return false;
  134. }, timeout * 1000);
  135. if (ret.Item1)
  136. {
  137. if (ret.Item2 == Result.FAIL)
  138. {
  139. throw (new RoutineFaildException());
  140. }
  141. else if (ret.Item2 == Result.TIMEOUT) //timeout
  142. {
  143. _cassetteRobotModule.RobotHomeTimeoutAlarm.Set($"timeout over {timeout} seconds");
  144. throw (new RoutineFaildException());
  145. }
  146. else
  147. throw (new RoutineBreakException());
  148. }
  149. }
  150. private void RobotSetServoOn(int id, Robot robot, bool isOn, int timeout)
  151. {
  152. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  153. {
  154. Notify($"Set servo {(isOn ? "on" : "off")}");
  155. if (!robot.SetServoOnOff(isOn, out string reason))
  156. {
  157. //_cassetteRobotModule.SetServoOnFailAlarm.Description = reason;
  158. _cassetteRobotModule.SetServoOnFailAlarm.Set(reason);
  159. return false;
  160. }
  161. return true;
  162. }, () =>
  163. {
  164. if (!robot.Busy)
  165. {
  166. return true;
  167. }
  168. return false;
  169. }, timeout * 1000);
  170. if (ret.Item1)
  171. {
  172. if (ret.Item2 == Result.FAIL)
  173. {
  174. throw (new RoutineFaildException());
  175. }
  176. else if (ret.Item2 == Result.TIMEOUT) //timeout
  177. {
  178. //_cassetteRobotModule.CheckLoadTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  179. _cassetteRobotModule.CheckLoadTimeoutAlarm.Set($"timeout over {timeout} seconds");
  180. throw (new RoutineFaildException());
  181. }
  182. else
  183. throw (new RoutineBreakException());
  184. }
  185. }
  186. public void RobotSetCommunication(int id, Robot robot, int timeout)
  187. {
  188. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  189. {
  190. Notify("Set default communication");
  191. if (!robot.SetCommunication(out string reason))
  192. {
  193. Stop(reason);
  194. return false;
  195. }
  196. return true;
  197. }, () =>
  198. {
  199. if (!robot.Busy)
  200. {
  201. return 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. Stop($"timeout over {timeout} seconds");
  214. throw (new RoutineFaildException());
  215. }
  216. else
  217. throw (new RoutineBreakException());
  218. }
  219. }
  220. public void RobotSetLoad(int id, Robot robot, Hand hand, int timeout)
  221. {
  222. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  223. {
  224. Notify($"Set default load {hand}");
  225. if (!robot.SetLoad(hand, out string reason))
  226. {
  227. Stop(reason);
  228. return false;
  229. }
  230. return true;
  231. }, () =>
  232. {
  233. if (!robot.Busy)
  234. {
  235. return true;
  236. }
  237. return false;
  238. }, timeout * 1000);
  239. if (ret.Item1)
  240. {
  241. if (ret.Item2 == Result.FAIL)
  242. {
  243. throw (new RoutineFaildException());
  244. }
  245. else if (ret.Item2 == Result.TIMEOUT) //timeout
  246. {
  247. Stop($"timeout over {timeout} seconds");
  248. throw (new RoutineFaildException());
  249. }
  250. else
  251. throw (new RoutineBreakException());
  252. }
  253. }
  254. public void RobotHome(int id, int timeout)
  255. {
  256. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  257. {
  258. Notify("Execute home");
  259. if (!_cassetteRobotModule.SetCassetteRobotHome(out string reason))
  260. {
  261. //_cassetteRobotModule.RobotHomeFailAlarm.Description = reason;
  262. _cassetteRobotModule.RobotHomeFailAlarm.Set(reason);
  263. return false;
  264. }
  265. return true;
  266. }, () =>
  267. {
  268. if (_cassetteRobotModule.CarrierRobotDevice.IsReady() && !_cassetteRobotModule.CarrierRobotDevice.IsError)
  269. {
  270. return true;
  271. }
  272. return false;
  273. }, timeout * 1000);
  274. if (ret.Item1)
  275. {
  276. if (ret.Item2 == Result.FAIL)
  277. {
  278. throw (new RoutineFaildException());
  279. }
  280. else if (ret.Item2 == Result.TIMEOUT) //timeout
  281. {
  282. //_cassetteRobotModule.RobotHomeTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  283. _cassetteRobotModule.RobotHomeTimeoutAlarm.Set($"timeout over {timeout} seconds");
  284. throw (new RoutineFaildException());
  285. }
  286. else
  287. throw (new RoutineBreakException());
  288. }
  289. }
  290. private void UpdateCassetteInfoByRobotSensor(int id)
  291. {
  292. Tuple<bool, Result> ret = Execute(id, () => {
  293. Notify($"Update cassette info by robot cassette present sensor");
  294. if (SC.GetValue<bool>("System.IsSimulatorMode"))
  295. return true;
  296. if (_cassetteRobotModule.CarrierRobotDevice.IsWaferPresenceOnBlade1 && !CarrierManager.Instance.CheckHasCarrier(ModuleHelper.Converter(_cassetteRobotModule.Module), 0))
  297. {
  298. EV.PostInfoLog(Module, "Cassette Robot sensor found cassette on blade 1");
  299. CarrierManager.Instance.CreateCarrier(_cassetteRobotModule.Module);
  300. }
  301. if (!_cassetteRobotModule.CarrierRobotDevice.IsWaferPresenceOnBlade1 && !CarrierManager.Instance.CheckNoCarrier(ModuleHelper.Converter(_cassetteRobotModule.Module), 0))
  302. {
  303. EV.PostInfoLog(Module, "Cassette Robot sensor no cassette on blade 1");
  304. CarrierManager.Instance.DeleteCarrier(_cassetteRobotModule.Module);
  305. }
  306. return true;
  307. });
  308. if (ret.Item1)
  309. {
  310. throw (new RoutineBreakException());
  311. }
  312. }
  313. public void RobotSetSpeed(int id, int speed, int timeout)
  314. {
  315. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  316. {
  317. if (speed > 100)
  318. speed = 100;
  319. if (speed < 1)
  320. speed = 1;
  321. Notify($"set speed to {speed}");
  322. if (!_cassetteRobotModule.SetSpeed(speed, out string reason))
  323. {
  324. //_cassetteRobotModule.SetSpeedFailAlarm.Description = reason;
  325. _cassetteRobotModule.SetSpeedFailAlarm.Set(reason);
  326. return false;
  327. }
  328. return true;
  329. }, () =>
  330. {
  331. if (_cassetteRobotModule.CarrierRobotDevice.IsReady() && !_cassetteRobotModule.CarrierRobotDevice.IsError)
  332. {
  333. return true;
  334. }
  335. return false;
  336. }, timeout * 1000);
  337. if (ret.Item1)
  338. {
  339. if (ret.Item2 == Result.FAIL)
  340. {
  341. throw (new RoutineFaildException());
  342. }
  343. else if (ret.Item2 == Result.TIMEOUT) //timeout
  344. {
  345. //_cassetteRobotModule.SetSpeedTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  346. _cassetteRobotModule.SetSpeedTimeoutAlarm.Set($"timeout over {timeout} seconds");
  347. throw (new RoutineFaildException());
  348. }
  349. else
  350. throw (new RoutineBreakException());
  351. }
  352. }
  353. private void RobotRequestCassettePresent(int id, Hand hand, int timeout)
  354. {
  355. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  356. {
  357. Notify("request cassette present");
  358. if (!_cassetteRobotModule.RequestCassettePresent(hand, out string reason))
  359. {
  360. //_cassetteRobotModule.RequestCassettePresentFailAlarm.Description = reason;
  361. _cassetteRobotModule.RequestCassettePresentFailAlarm.Set(reason);
  362. return false;
  363. }
  364. return true;
  365. }, () =>
  366. {
  367. if (_cassetteRobotModule.CarrierRobotDevice.IsReady() && !_cassetteRobotModule.CarrierRobotDevice.IsError)
  368. {
  369. return true;
  370. }
  371. return false;
  372. }, timeout * 1000);
  373. if (ret.Item1)
  374. {
  375. if (ret.Item2 == Result.FAIL)
  376. {
  377. throw (new RoutineFaildException());
  378. }
  379. else if (ret.Item2 == Result.TIMEOUT) //timeout
  380. {
  381. //_cassetteRobotModule.RequestCassettePresentTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  382. _cassetteRobotModule.RequestCassettePresentTimeoutAlarm.Set($"timeout over {timeout} seconds");
  383. throw (new RoutineFaildException());
  384. }
  385. else
  386. throw (new RoutineBreakException());
  387. }
  388. }
  389. protected void CheckCassetteInfoByRobotSensor(int id, RobotBaseDevice robot, Hand hand, bool isAfterPick)
  390. {
  391. Tuple<bool, Result> ret = Execute(id, () =>
  392. {
  393. Notify($"check wafer info by robot RQ present");
  394. if (SC.GetValue<bool>("System.IsSimulatorMode"))
  395. return true;
  396. if (hand == Hand.Blade1 || hand == Hand.Both)
  397. {
  398. if (!isAfterPick && robot.IsWaferPresenceOnBlade1)
  399. {
  400. EV.PostWarningLog(Module, "Cassette Robot sensor found cassette on blade 1");
  401. return false;
  402. }
  403. if (isAfterPick && !robot.IsWaferPresenceOnBlade1)
  404. {
  405. EV.PostInfoLog(Module, "Cassette Robot sensor no cassette on blade 1");
  406. return false;
  407. }
  408. }
  409. if (hand == Hand.Blade2 || hand == Hand.Both)
  410. {
  411. if (!isAfterPick && robot.IsWaferPresenceOnBlade2)
  412. {
  413. EV.PostWarningLog(Module, "Cassette Robot sensor found cassette on blade 2");
  414. return false;
  415. }
  416. if (isAfterPick && !robot.IsWaferPresenceOnBlade2)
  417. {
  418. EV.PostInfoLog(Module, "Cassette Robot sensor no cassette on blade 2");
  419. return false;
  420. }
  421. }
  422. return true;
  423. });
  424. if (ret.Item1)
  425. {
  426. if (ret.Item2 == Result.FAIL)
  427. {
  428. Stop($"check cassette info failed.");
  429. throw (new RoutineFaildException());
  430. }
  431. else
  432. throw (new RoutineBreakException());
  433. }
  434. }
  435. private void SaferDoorOpen(int id, bool isOpen, int timeout)
  436. {
  437. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  438. {
  439. Notify($"Shutter Door {(isOpen ? "Open" : "Close")}");
  440. if (isOpen)
  441. _cassetteRobotModule.DoorDevice.Open();
  442. else
  443. _cassetteRobotModule.DoorDevice.Close();
  444. return true;
  445. }, () =>
  446. {
  447. return isOpen ? _cassetteRobotModule.DoorDevice.OpenCloseStatus == Devices.DeviceStatus.Open : _cassetteRobotModule.DoorDevice.OpenCloseStatus == Devices.DeviceStatus.Close;
  448. }, timeout * 1000);
  449. if (ret.Item1)
  450. {
  451. if (ret.Item2 == Result.FAIL)
  452. {
  453. throw new RoutineFaildException();
  454. }
  455. else if (ret.Item2 == Result.TIMEOUT) //timeout
  456. {
  457. if (isOpen)
  458. _cassetteRobotModule.ShutterOpenTimeoutAlarm.Set($"timeout over {timeout} seconds");
  459. else
  460. _cassetteRobotModule.ShutterCloseTimeoutAlarm.Set($"timeout over {timeout} seconds");
  461. throw (new RoutineFaildException());
  462. }
  463. else
  464. throw new RoutineBreakException();
  465. }
  466. }
  467. }
  468. }