WaferRobotHome.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. _waferRobotModule.ResetRobotActionCommand();
  89. Notify("Finished");
  90. return Result.DONE;
  91. }
  92. private void RobotReset(int id, int timeout)
  93. {
  94. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  95. {
  96. Notify($"Set robot reset");
  97. _waferRobotModule.SetCassetteRobotReset();
  98. return true;
  99. }, () =>
  100. {
  101. if (_waferRobotModule.WaferRobotDevice.IsReady())
  102. {
  103. return true;
  104. }
  105. return false;
  106. }, timeout * 1000);
  107. if (ret.Item1)
  108. {
  109. if (ret.Item2 == Result.FAIL)
  110. {
  111. throw (new RoutineFaildException());
  112. }
  113. else if (ret.Item2 == Result.TIMEOUT) //timeout
  114. {
  115. _waferRobotModule.RobotHomeTimeoutAlarm.Set($"timeout over {timeout} seconds");
  116. throw (new RoutineFaildException());
  117. }
  118. else
  119. throw (new RoutineBreakException());
  120. }
  121. }
  122. private void RobotSetServoOn(int id, Robot robot, bool isOn, int timeout)
  123. {
  124. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  125. {
  126. Notify($"Set servo {(isOn ? "on":"off")}");
  127. if (!robot.SetServoOnOff(isOn, out string reason))
  128. {
  129. _waferRobotModule.SetServoOnFailAlarm.Description = reason;
  130. _waferRobotModule.SetServoOnFailAlarm.Set();
  131. return false;
  132. }
  133. return true;
  134. }, () =>
  135. {
  136. if (!robot.Busy)
  137. {
  138. return true;
  139. }
  140. return false;
  141. }, timeout * 1000);
  142. if (ret.Item1)
  143. {
  144. if (ret.Item2 == Result.FAIL)
  145. {
  146. throw (new RoutineFaildException());
  147. }
  148. else if (ret.Item2 == Result.TIMEOUT) //timeout
  149. {
  150. _waferRobotModule.SetServoOnTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  151. _waferRobotModule.SetServoOnTimeoutAlarm.Set();
  152. throw (new RoutineFaildException());
  153. }
  154. else
  155. throw (new RoutineBreakException());
  156. }
  157. }
  158. public void RobotSetLoad(int id, Robot robot, Hand hand, int timeout)
  159. {
  160. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  161. {
  162. Notify($"Set default load {hand}");
  163. if (!robot.SetLoad(hand, out string reason))
  164. {
  165. Stop(reason);
  166. return false;
  167. }
  168. return true;
  169. }, () =>
  170. {
  171. if (!robot.Busy)
  172. {
  173. return true;
  174. }
  175. return false;
  176. }, timeout * 1000);
  177. if (ret.Item1)
  178. {
  179. if (ret.Item2 == Result.FAIL)
  180. {
  181. throw (new RoutineFaildException());
  182. }
  183. else if (ret.Item2 == Result.TIMEOUT) //timeout
  184. {
  185. Stop($"timeout over {timeout} seconds");
  186. throw (new RoutineFaildException());
  187. }
  188. else
  189. throw (new RoutineBreakException());
  190. }
  191. }
  192. public void RobotHome(int id, int timeout)
  193. {
  194. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  195. {
  196. Notify("Execute home");
  197. if (!_waferRobotModule.SetWaferRobotHome(out string reason))
  198. {
  199. //_waferRobotModule.RobotHomeFailAlarm.Description = reason;
  200. _waferRobotModule.RobotHomeFailAlarm.Set(reason);
  201. return false;
  202. }
  203. return true;
  204. }, () =>
  205. {
  206. if (_waferRobotModule.WaferRobotDevice.IsReady() && !_waferRobotModule.WaferRobotDevice.IsError)
  207. {
  208. return true;
  209. }
  210. return false;
  211. }, timeout * 1000);
  212. if (ret.Item1)
  213. {
  214. if (ret.Item2 == Result.FAIL)
  215. {
  216. throw (new RoutineFaildException());
  217. }
  218. else if (ret.Item2 == Result.TIMEOUT) //timeout
  219. {
  220. _waferRobotModule.RobotHomeTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  221. _waferRobotModule.RobotHomeTimeoutAlarm.Set();
  222. throw (new RoutineFaildException());
  223. }
  224. else
  225. throw (new RoutineBreakException());
  226. }
  227. }
  228. public void RobotCheckLoad(int id, Robot robot, Hand hand, int timeout)
  229. {
  230. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  231. {
  232. Notify("Check load");
  233. if (!robot.CheckLoad(hand, out string reason))
  234. {
  235. _waferRobotModule.CheckLoadFailAlarm.Description = reason;
  236. _waferRobotModule.CheckLoadFailAlarm.Set();
  237. return false;
  238. }
  239. return true;
  240. }, () =>
  241. {
  242. if (!robot.Busy)
  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.CheckLoadTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  257. _waferRobotModule.CheckLoadTimeoutAlarm.Set();
  258. throw (new RoutineFaildException());
  259. }
  260. else
  261. throw (new RoutineBreakException());
  262. }
  263. }
  264. public void RobotSetSpeed(int id, int speed, int timeout)
  265. {
  266. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  267. {
  268. if (speed > 3 || speed < 1)
  269. speed = 1;
  270. Notify($"set speed to {speed}");
  271. if (!_waferRobotModule.SetSpeed(speed, out string reason))
  272. {
  273. //_waferRobotModule.SetSpeedFailAlarm.Description = reason;
  274. _waferRobotModule.SetSpeedFailAlarm.Set(reason);
  275. return false;
  276. }
  277. return true;
  278. }, () =>
  279. {
  280. if (_waferRobotModule.WaferRobotDevice.IsReady() && !_waferRobotModule.WaferRobotDevice.IsError)
  281. {
  282. return true;
  283. }
  284. return false;
  285. }, timeout * 1000);
  286. if (ret.Item1)
  287. {
  288. if (ret.Item2 == Result.FAIL)
  289. {
  290. throw (new RoutineFaildException());
  291. }
  292. else if (ret.Item2 == Result.TIMEOUT) //timeout
  293. {
  294. //_waferRobotModule.SetSpeedTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  295. _waferRobotModule.SetSpeedTimeoutAlarm.Set($"timeout over {timeout} seconds");
  296. throw (new RoutineFaildException());
  297. }
  298. else
  299. throw (new RoutineBreakException());
  300. }
  301. }
  302. private void RobotRequestWaferPresent(int id, Hand hand, int timeout)
  303. {
  304. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  305. {
  306. Notify("request wafer present");
  307. if (!_waferRobotModule.RequestWaferPresent(hand, out string reason))
  308. {
  309. _waferRobotModule.RequestWaferPresentFailAlarm.Description = reason;
  310. _waferRobotModule.RequestWaferPresentFailAlarm.Set();
  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.RequestWaferPresentTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  331. _waferRobotModule.RequestWaferPresentTimeoutAlarm.Set($"timeout over {timeout} seconds");
  332. throw (new RoutineFaildException());
  333. }
  334. else
  335. throw (new RoutineBreakException());
  336. }
  337. }
  338. protected void UpdateWaferInfoByRobotSensor(int id)
  339. {
  340. Tuple<bool, Result> ret = Execute(id, () => {
  341. Notify($"Update wafer info by robot wafer present");
  342. if (SC.GetValue<bool>("System.IsSimulatorMode"))
  343. return true;
  344. if (_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade1 && WaferManager.Instance.CheckNoWafer(_waferRobotModule.Module, 0))
  345. {
  346. EV.PostInfoLog(Module, "Wafer Robot sensor found wafer on blade 1");
  347. WaferManager.Instance.CreateWafer(ModuleHelper.Converter(_waferRobotModule.Module), 0, WaferStatus.Normal);
  348. }
  349. if (!_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade1 && WaferManager.Instance.CheckHasWafer(_waferRobotModule.Module, 0))
  350. {
  351. EV.PostInfoLog(Module, "Wafer Robot sensor no wafer on blade 1");
  352. WaferManager.Instance.DeleteWafer(ModuleHelper.Converter(_waferRobotModule.Module), 0);
  353. }
  354. if (_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade2 && WaferManager.Instance.CheckNoWafer(_waferRobotModule.Module, 1))
  355. {
  356. EV.PostInfoLog(Module, "Wafer Robot sensor found wafer on blade 2");
  357. WaferManager.Instance.CreateWafer(ModuleHelper.Converter(_waferRobotModule.Module), 1, WaferStatus.Normal);
  358. }
  359. if (!_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade2 && WaferManager.Instance.CheckHasWafer(_waferRobotModule.Module, 1))
  360. {
  361. EV.PostInfoLog(Module, "Wafer Robot sensor no wafer on blade 2");
  362. WaferManager.Instance.DeleteWafer(ModuleHelper.Converter(_waferRobotModule.Module), 1);
  363. }
  364. if (_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade3 && WaferManager.Instance.CheckNoWafer(_waferRobotModule.Module, 2))
  365. {
  366. EV.PostInfoLog(Module, "Wafer Robot sensor found wafer on blade 3");
  367. WaferManager.Instance.CreateWafer(ModuleHelper.Converter(_waferRobotModule.Module), 2, WaferStatus.Normal);
  368. }
  369. if (!_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade3 && WaferManager.Instance.CheckHasWafer(_waferRobotModule.Module, 2))
  370. {
  371. EV.PostInfoLog(Module, "Wafer Robot sensor no wafer on blade 3");
  372. WaferManager.Instance.DeleteWafer(ModuleHelper.Converter(_waferRobotModule.Module), 2);
  373. }
  374. if (_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade4 && WaferManager.Instance.CheckNoWafer(_waferRobotModule.Module, 3))
  375. {
  376. EV.PostInfoLog(Module, "Wafer Robot sensor found wafer on blade 4");
  377. WaferManager.Instance.CreateWafer(ModuleHelper.Converter(_waferRobotModule.Module), 3, WaferStatus.Normal);
  378. }
  379. if (!_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade4 && WaferManager.Instance.CheckHasWafer(_waferRobotModule.Module, 3))
  380. {
  381. EV.PostInfoLog(Module, "Wafer Robot sensor no wafer on blade 4");
  382. WaferManager.Instance.DeleteWafer(ModuleHelper.Converter(_waferRobotModule.Module), 3);
  383. }
  384. if (_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade5 && WaferManager.Instance.CheckNoWafer(_waferRobotModule.Module, 4))
  385. {
  386. EV.PostInfoLog(Module, "Wafer Robot sensor found wafer on blade 5");
  387. WaferManager.Instance.CreateWafer(ModuleHelper.Converter(_waferRobotModule.Module), 4, WaferStatus.Normal);
  388. }
  389. if (!_waferRobotModule.WaferRobotDevice.IsWaferPresenceOnBlade5 && WaferManager.Instance.CheckHasWafer(_waferRobotModule.Module, 4))
  390. {
  391. EV.PostInfoLog(Module, "Wafer Robot sensor no wafer on blade 5");
  392. WaferManager.Instance.DeleteWafer(ModuleHelper.Converter(_waferRobotModule.Module), 4);
  393. }
  394. return true;
  395. });
  396. if (ret.Item1)
  397. {
  398. throw (new RoutineBreakException());
  399. }
  400. }
  401. }
  402. }