InitRoutine2Step.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. using System;
  2. using System.Collections.Generic;
  3. using Aitex.Core.Common;
  4. using Aitex.Core.RT.Device;
  5. using Aitex.Core.RT.Device.Unit;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.RT.Routine;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Core.Util;
  10. using EFEM.RT.Devices;
  11. using Aitex.Sorter.Common;
  12. using EFEMSC;
  13. using MECF.Framework.Common.Equipment;
  14. using MECF.Framework.Common.SubstrateTrackings;
  15. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  16. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  17. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  18. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  19. namespace EFEM.RT.Routines
  20. {
  21. public class InitRoutine2Step : CommonRoutine, IRoutine, IEfemRoutine
  22. {
  23. enum Home
  24. {
  25. DeviceReset,
  26. RobotClear,
  27. RobotInit,
  28. WaitingRobotInit,
  29. RobotArmHome,
  30. WaitingRobotArmHome,
  31. AxisClearAlarm,
  32. AxisServon,
  33. AxisServonDelay,
  34. AxisSetConfig,
  35. AxisSetConfigDelay,
  36. AxisHomeStep1,
  37. RobotHome,
  38. WaitingRobotHome,
  39. RobotSet,
  40. AxisHomeStep2,
  41. AlignClear,
  42. AlignerInit,
  43. WaitingAlignerInit,
  44. AlignerHome,
  45. WaitingAlignerHome,
  46. AlignerMoveUp,
  47. WaitingAlignerUp,
  48. Coolingbuffer1Home,
  49. Coolingbuffer2Home,
  50. CloseAtmShutterDoor,
  51. CloseVtmShutterDoor,
  52. LoadportAClear,
  53. LoadportAHome,
  54. WaitingLoadportAHome,
  55. LoadportBClear,
  56. LoadportBHome,
  57. WaitingLoadportBHome,
  58. LoadportCClear,
  59. LoadportCHome,
  60. WaitingLoadportCHome,
  61. LoadportDClear,
  62. LoadportDHome,
  63. WaitingLoadportDHome,
  64. LoadportEClear,
  65. LoadportEHome,
  66. WaitingLoadportEHome,
  67. LoadportFClear,
  68. LoadportFHome,
  69. WaitingLoadportFHome,
  70. LoadportGClear,
  71. LoadportGHome,
  72. WaitingLoadportGHome,
  73. LoadportHClear,
  74. LoadportHHome,
  75. WaitingLoadportHHome,
  76. LoadportIClear,
  77. LoadportIHome,
  78. WaitingLoadportIHome,
  79. LoadportJClear,
  80. LoadportJHome,
  81. WaitingLoadportJHome
  82. }
  83. private SetSpeedRoutine RbSetRoutine = null;
  84. private bool _scanBuffer = true;
  85. private SCConfigItem _scRobotHomeTimeout = null;
  86. private int _timeoutaligner = 0;
  87. private int _timeoutLoadport = 0;
  88. private int _timeoutBuffer = 0;
  89. private int _timeoutRobot = 0;
  90. private int initIndex = 0;
  91. public InitRoutine2Step(string module, string name)
  92. {
  93. Module = module;
  94. Name = name;
  95. RbSetRoutine = new SetSpeedRoutine(module, name);
  96. }
  97. public bool Initalize()
  98. {
  99. RbSetRoutine.Initalize();
  100. _scRobotHomeTimeout = SC.GetConfigItem(SorterCommon.ScPathName.Robot_TimeLimitRobotHome);
  101. return true;
  102. }
  103. public void Terminate()
  104. {
  105. RbSetRoutine.Terminate();
  106. }
  107. public Result Start(params object[] objs)
  108. {
  109. Name = "Init";
  110. Reset();
  111. _timeoutRobot = _scRobotHomeTimeout.IntValue;
  112. _timeoutaligner = SC.GetValue<int>(ScPathName.Aligner_TimeLimitAlignerHome);
  113. _timeoutLoadport = SC.GetValue<int>(ScPathName.LoadPort_TimeLimitLoadportHome);
  114. _timeoutBuffer = SC.GetValue<int>(ScPathName.Coolbuffer_DownTimeout);
  115. RbSetRoutine.Speed = SC.GetValue<int>(SorterCommon.ScPathName.Robot_RobotSpeed);
  116. EV.PostMessage(ModuleName.System.ToString(), EventEnum.HomeBegins, ModuleName.System.ToString());
  117. robot = DEVICE.GetDevice<RobotBaseDevice>(DeviceName.Robot);
  118. _scanBuffer = true;
  119. WaferSensorResetCreate();
  120. initIndex = 0;
  121. return Result.RUN;
  122. }
  123. public Result Monitor()
  124. {
  125. try
  126. {
  127. DeviceReset((int)Home.DeviceReset, "Device Reset", 1, Notify, Stop);
  128. if (RobotTypeDefine == "NXC100")
  129. {
  130. // RobotInit((int)Home.RobotInit,robot, "Robot initialize",Notify,Stop);
  131. // WaitRobotMotion((int)Home.WaitingRobotInit, robot, "Robot initializing...", _timeoutRobot, Notify, Stop);
  132. RobotArmHome((int)Home.RobotArmHome, robot, "Robot arm home", Notify, Stop);
  133. WaitRobotMotion((int)Home.WaitingRobotArmHome, robot, "Robot arm homing...", _timeoutRobot, Notify, Stop);
  134. RobotHome((int)Home.RobotHome, robot, "Robot home", Notify, Stop);
  135. WaitRobotMotion((int)Home.WaitingRobotHome, robot, "Robot homing...", _timeoutRobot, Notify, Stop);
  136. WaitRobotSet((int)Home.RobotSet, "Robot参数设置", RbSetRoutine, Notify, Stop);
  137. if (HaveAligner)
  138. {
  139. AlignerReset((int) Home.AlignClear, aligner, "Aligner reset", _timeoutRobot, Notify, Stop);
  140. AlignerInit((int) Home.AlignerInit, aligner, "Aligner initialize", Notify, Stop);
  141. WaitAlignerMotion((int) Home.WaitingAlignerInit, aligner, "Aligner initializing...",
  142. _timeoutRobot, Notify, Stop);
  143. AlignerHome((int) Home.AlignerHome, aligner, "Aligner home", Notify, Stop);
  144. WaitAlignerMotion((int) Home.WaitingAlignerHome, aligner, "Aligner homing...", _timeoutaligner,
  145. Notify, Stop);
  146. if (AlignerNeedMoveUpCommand)
  147. {
  148. AlignerMoveUp((int) Home.AlignerMoveUp, aligner, "Aligner move up", Notify, Stop);
  149. WaitAlignerMotion((int) Home.WaitingAlignerUp, aligner, "Aligner moving up",
  150. _timeoutaligner, Notify, Stop);
  151. }
  152. }
  153. }
  154. else
  155. {
  156. RobotReset((int) Home.RobotClear, robot, "Robot reset", _timeoutRobot, Notify, Stop);
  157. RobotHome((int) Home.RobotHome, robot, "Robot home", Notify, Stop);
  158. WaitRobotMotion((int) Home.WaitingRobotHome, robot, "Robot homing...", _timeoutRobot, Notify, Stop);
  159. WaitRobotSet((int) Home.RobotSet, "Robot参数设置", RbSetRoutine, Notify, Stop);
  160. if (HaveAligner)
  161. {
  162. AlignerReset((int) Home.AlignClear, aligner, "Aligner reset", _timeoutRobot, Notify, Stop);
  163. AlignerInit((int) Home.AlignerInit, aligner, "Aligner initialize", Notify, Stop);
  164. WaitAlignerMotion((int) Home.WaitingAlignerInit, aligner, "Aligner initializing...", _timeoutRobot, Notify, Stop);
  165. AlignerHome((int) Home.AlignerHome, aligner, "Aligner home", Notify, Stop);
  166. WaitAlignerMotion((int) Home.WaitingAlignerHome, aligner, "Aligner homing...", _timeoutaligner, Notify, Stop);
  167. if (AlignerNeedMoveUpCommand)
  168. {
  169. AlignerMoveUp((int) Home.AlignerMoveUp, aligner, "Aligner move up", Notify, Stop);
  170. WaitAlignerMotion((int) Home.WaitingAlignerUp, aligner, "Aligner moving up",
  171. _timeoutaligner, Notify, Stop);
  172. }
  173. }
  174. }
  175. if (DeviceDefineManager.Instance.GetValue<bool>("CoolingBufferInstalled") ?? false)
  176. {
  177. CooingbufferHome((int)Home.Coolingbuffer1Home, buffer1, "Cooling buffer1 moving down",
  178. _timeoutBuffer, Notify, Stop);
  179. CooingbufferHome((int)Home.Coolingbuffer2Home, buffer1, "Cooling buffer2 moving down",
  180. _timeoutBuffer, Notify, Stop);
  181. }
  182. if (LoadLockDoorControlByStation)
  183. {
  184. LoadLockCloseAtmDoor((int)Home.CloseAtmShutterDoor, DEVICE.GetDevice<LoadLockDevice>(ModuleName.LL1.ToString()), "Wait Atm Door Close", _timeoutRobot, Notify, Stop);
  185. LoadLockCloseVtmDoor((int)Home.CloseVtmShutterDoor, DEVICE.GetDevice<LoadLockDevice>(ModuleName.LL1.ToString()), "Wait Vtm Door Close", _timeoutRobot, Notify, Stop);
  186. }
  187. if (initIndex < LoadPortQuantity)
  188. {
  189. LoadportReset((int)Home.LoadportAClear+initIndex*3, DEVICE.GetDevice<LoadPortBaseDevice>($"LP{initIndex+1}"), $"LP{initIndex+1} reset", _timeoutRobot, Notify, Stop);
  190. LoadportInit((int)Home.LoadportAHome+initIndex*3, DEVICE.GetDevice<LoadPortBaseDevice>($"LP{initIndex+1}"), $"LP{initIndex+1} home", Notify, Stop);
  191. WaitLoadportMotion((int)Home.WaitingLoadportAHome+initIndex*3, DEVICE.GetDevice<LoadPortBaseDevice>($"LP{initIndex+1}"), $"LP{initIndex+1} homing...", _timeoutLoadport, Notify, Stop);
  192. initIndex++;
  193. return Result.RUN;
  194. }
  195. }
  196. catch (RoutineBreakException)
  197. {
  198. return Result.RUN;
  199. }
  200. catch (RoutineFaildException)
  201. {
  202. return Result.FAIL;
  203. }
  204. EV.PostMessage(ModuleName.System.ToString(), EventEnum.HomeEnds, ModuleName.System.ToString());
  205. return Result.DONE;
  206. }
  207. protected void WaitRobotSet(int id, string name, IRoutine routines, Action<string> notify, Action<string> error)
  208. {
  209. Tuple<bool, Result> ret = ExecuteAndWait(id, routines);
  210. if (ret.Item1)
  211. {
  212. if (ret.Item2 == Result.FAIL)
  213. {
  214. error(name);
  215. throw (new RoutineFaildException());
  216. }
  217. else if (ret.Item2 == Result.RUN)
  218. {
  219. throw (new RoutineBreakException());
  220. }
  221. }
  222. }
  223. protected void DeviceReset(int id, string name, int time, Action<string> notify, Action<string> error)
  224. {
  225. Tuple<bool, Result> ret = Delay(id, () =>
  226. {
  227. notify(String.Format("Device reset"));
  228. Singleton<DeviceEntity>.Instance.PostMsg( DeviceEntity.MSG.RESET);
  229. return true;
  230. }, time * 1000);
  231. if (ret.Item1)
  232. {
  233. if (ret.Item2 == Result.RUN)
  234. {
  235. throw (new RoutineBreakException());
  236. }
  237. }
  238. }
  239. #region aligner
  240. public void AlignerReset(int id, Aligner device, string name, int time, Action<string> notify, Action<string> error)
  241. {
  242. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  243. {
  244. notify(String.Format("{0} clear error", device.Name));
  245. string reason = string.Empty;
  246. return device.Clear(out reason);
  247. }, () =>
  248. {
  249. if (device.Busy == false)
  250. {
  251. return true;
  252. }
  253. return false;
  254. }, time * 1000);
  255. if (ret.Item1)
  256. {
  257. if (ret.Item2 == Result.FAIL)
  258. {
  259. throw (new RoutineFaildException());
  260. }
  261. else if (ret.Item2 == Result.TIMEOUT) //timeout
  262. {
  263. error(String.Format("{0} timeout, than {1} seconds", name, time));
  264. throw (new RoutineFaildException());
  265. }
  266. else
  267. throw (new RoutineBreakException());
  268. }
  269. }
  270. public void AlignerInit(int id, Aligner device, string name, Action<string> notify, Action<string> error)
  271. {
  272. Tuple<bool, Result> ret = Execute(id, () =>
  273. {
  274. notify(String.Format("{0} Home", device.Name));
  275. string reason = string.Empty;
  276. return device.Init(out reason);
  277. });
  278. if (ret.Item1)
  279. {
  280. if (ret.Item2 == Result.FAIL)
  281. {
  282. throw (new RoutineFaildException());
  283. }
  284. }
  285. }
  286. public void AlignerHome(int id, Aligner device, string name, Action<string> notify, Action<string> error)
  287. {
  288. Tuple<bool, Result> ret = Execute(id, () =>
  289. {
  290. notify(String.Format("{0} Home", device.Name));
  291. string reason = string.Empty;
  292. return device.Home(out reason);
  293. });
  294. if (ret.Item1)
  295. {
  296. if (ret.Item2 == Result.FAIL)
  297. {
  298. throw (new RoutineFaildException());
  299. }
  300. }
  301. }
  302. public void AlignerMoveUp(int id, Aligner device, string name, Action<string> notify, Action<string> error)
  303. {
  304. Tuple<bool, Result> ret = Execute(id, () =>
  305. {
  306. notify(String.Format("{0} Lift up", device.Name));
  307. string reason = string.Empty;
  308. return device.LiftUp(out reason);
  309. });
  310. if (ret.Item1)
  311. {
  312. if (ret.Item2 == Result.FAIL)
  313. {
  314. throw (new RoutineFaildException());
  315. }
  316. }
  317. }
  318. #endregion
  319. #region Loadport
  320. ///等待 Loadport
  321. public void QueryLoadportState(int id, LoadPort device, string name, int time, Action<string> notify, Action<string> error)
  322. {
  323. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  324. {
  325. notify(String.Format("{0} query state", device.Name));
  326. string reason = string.Empty;
  327. device.QueryState(out reason);
  328. return true;
  329. }, () =>
  330. {
  331. if (!device.IsBusy)
  332. {
  333. return true;
  334. }
  335. return false;
  336. }, time * 1000);
  337. if (ret.Item1)
  338. {
  339. if (ret.Item2 == Result.FAIL)
  340. {
  341. throw (new RoutineFaildException());
  342. }
  343. else if (ret.Item2 == Result.TIMEOUT) //timeout
  344. {
  345. error(String.Format("{0} query timeout, than {1} seconds", name, time));
  346. throw (new RoutineFaildException());
  347. }
  348. else
  349. throw (new RoutineBreakException());
  350. }
  351. }
  352. #endregion
  353. void WaferSensorResetCreate()
  354. {
  355. if(!_scanBuffer) return;
  356. var sensors = new List<bool>
  357. {
  358. DeviceModel.SensorCoolingStageSLOT1WaferON != null ? DeviceModel.SensorCoolingStageSLOT1WaferON.Value : true,
  359. DeviceModel.SensorCoolingStageSLOT2WaferON != null ? DeviceModel.SensorCoolingStageSLOT2WaferON.Value : true,
  360. DeviceModel.SensorCoolingStageSLOT3WaferON != null ? DeviceModel.SensorCoolingStageSLOT3WaferON.Value : true,
  361. DeviceModel.SensorCoolingStageSLOT4WaferON != null ? DeviceModel.SensorCoolingStageSLOT4WaferON.Value : true,
  362. DeviceModel.SensorCoolingStageSLOT5WaferON != null ? DeviceModel.SensorCoolingStageSLOT5WaferON.Value : true,
  363. DeviceModel.SensorCoolingStageSLOT6WaferON != null ? DeviceModel.SensorCoolingStageSLOT6WaferON.Value : true,
  364. };
  365. var index = 0;
  366. foreach (var sensor in sensors)
  367. {
  368. if (!sensor && WaferManager.Instance.CheckNoWafer(ModuleName.Buffer, index))
  369. {
  370. WaferManager.Instance.CreateWafer(ModuleName.Buffer, index, WaferStatus.Normal);
  371. }
  372. else if(sensor && WaferManager.Instance.CheckHasWafer(ModuleName.Buffer,index))
  373. {
  374. WaferManager.Instance.DeleteWafer(ModuleName.Buffer, index);
  375. }
  376. index++;
  377. }
  378. var robotSensors = new List<bool>
  379. {
  380. DeviceModel.SensorRBlowerArmhavewafer != null ? DeviceModel.SensorRBlowerArmhavewafer.Value : true,
  381. DeviceModel.SensorRBupperArmhavewafer != null ? DeviceModel.SensorRBupperArmhavewafer.Value : true,
  382. };
  383. index = 0;
  384. foreach (var sensor in robotSensors)
  385. {
  386. if (!sensor && WaferManager.Instance.CheckNoWafer(ModuleName.Robot, index))
  387. {
  388. WaferManager.Instance.CreateWafer(ModuleName.Robot, index, WaferStatus.Normal);
  389. }
  390. else if(sensor && WaferManager.Instance.CheckHasWafer(ModuleName.Robot,index))
  391. {
  392. WaferManager.Instance.DeleteWafer(ModuleName.Robot, index);
  393. }
  394. index++;
  395. }
  396. if (DeviceModel.SensorPreAlignerWaferOn !=null && !DeviceModel.SensorPreAlignerWaferOn.Value && WaferManager.Instance.CheckNoWafer(ModuleName.Aligner, 0))
  397. {
  398. WaferManager.Instance.CreateWafer(ModuleName.Aligner, 0, WaferStatus.Normal);
  399. }
  400. else
  401. {
  402. if(DeviceDefineManager.Instance.GetValue<bool>("AlignerInstalled") ?? false)
  403. WaferManager.Instance.DeleteWafer(ModuleName.Aligner, 0);
  404. }
  405. _scanBuffer = false;
  406. }
  407. public void CooingbufferHome(int id, IoCoolingBuffer device, string name, int time, Action<string> notify, Action<string> error)
  408. {
  409. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  410. {
  411. notify(String.Format("{0} clear error", device.Name));
  412. string reason = string.Empty;
  413. return device.Home(out reason);
  414. }, () =>
  415. {
  416. if (device.Busy == false)
  417. {
  418. return true;
  419. }
  420. return false;
  421. }, time * 1000);
  422. if (ret.Item1)
  423. {
  424. if (ret.Item2 == Result.FAIL)
  425. {
  426. throw (new RoutineFaildException());
  427. }
  428. else if (ret.Item2 == Result.TIMEOUT) //timeout
  429. {
  430. error(String.Format("{0} timeout, than {1} seconds", name, time));
  431. throw (new RoutineFaildException());
  432. }
  433. else
  434. throw (new RoutineBreakException());
  435. }
  436. }
  437. protected override void Notify(string message)
  438. {
  439. EV.PostMessage(Module, EventEnum.GeneralInfo, String.Format("Home sequence :{0}", message));
  440. }
  441. /// <summary>
  442. /// prepare process failed
  443. /// </summary>
  444. /// <param name="failReason"></param>
  445. /// <param name="reactor"></param>
  446. protected override void Stop(string failReason)
  447. {
  448. string reason = String.Empty;
  449. EV.PostMessage(Module, EventEnum.HomeFailed, failReason);
  450. }
  451. }
  452. }