CarrierRobotHome.cs 18 KB

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