WaferRobotHome.cs 17 KB

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