WaferRobotHome.cs 19 KB

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