WaferRobotHome.cs 18 KB

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