CarrierRobotHome.cs 18 KB

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