CarrierRobotHome.cs 18 KB

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