InitRoutine2Step.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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. if (!SC.GetValue<bool>("System.CoolingBuffer1Disable"))
  178. CooingbufferHome((int)Home.Coolingbuffer1Home, buffer1, "Cooling buffer1 moving down",
  179. _timeoutBuffer, Notify, Stop);
  180. if (!SC.GetValue<bool>("System.CoolingBuffer2Disable"))
  181. CooingbufferHome((int)Home.Coolingbuffer2Home, buffer1, "Cooling buffer2 moving down",
  182. _timeoutBuffer, Notify, Stop);
  183. }
  184. if (LoadLockDoorControlByStation)
  185. {
  186. LoadLockCloseAtmDoor((int)Home.CloseAtmShutterDoor, DEVICE.GetDevice<LoadLockDevice>(ModuleName.LL1.ToString()), "Wait Atm Door Close", _timeoutRobot, Notify, Stop);
  187. LoadLockCloseVtmDoor((int)Home.CloseVtmShutterDoor, DEVICE.GetDevice<LoadLockDevice>(ModuleName.LL1.ToString()), "Wait Vtm Door Close", _timeoutRobot, Notify, Stop);
  188. }
  189. if (initIndex < LoadPortQuantity)
  190. {
  191. LoadportReset((int)Home.LoadportAClear+initIndex*3, DEVICE.GetDevice<LoadPortBaseDevice>($"LP{initIndex+1}"), $"LP{initIndex+1} reset", _timeoutRobot, Notify, Stop);
  192. LoadportInit((int)Home.LoadportAHome+initIndex*3, DEVICE.GetDevice<LoadPortBaseDevice>($"LP{initIndex+1}"), $"LP{initIndex+1} home", Notify, Stop);
  193. WaitLoadportMotion((int)Home.WaitingLoadportAHome+initIndex*3, DEVICE.GetDevice<LoadPortBaseDevice>($"LP{initIndex+1}"), $"LP{initIndex+1} homing...", _timeoutLoadport, Notify, Stop);
  194. initIndex++;
  195. return Result.RUN;
  196. }
  197. }
  198. catch (RoutineBreakException)
  199. {
  200. return Result.RUN;
  201. }
  202. catch (RoutineFaildException)
  203. {
  204. return Result.FAIL;
  205. }
  206. EV.PostMessage(ModuleName.System.ToString(), EventEnum.HomeEnds, ModuleName.System.ToString());
  207. return Result.DONE;
  208. }
  209. protected void WaitRobotSet(int id, string name, IRoutine routines, Action<string> notify, Action<string> error)
  210. {
  211. Tuple<bool, Result> ret = ExecuteAndWait(id, routines);
  212. if (ret.Item1)
  213. {
  214. if (ret.Item2 == Result.FAIL)
  215. {
  216. error(name);
  217. throw (new RoutineFaildException());
  218. }
  219. else if (ret.Item2 == Result.RUN)
  220. {
  221. throw (new RoutineBreakException());
  222. }
  223. }
  224. }
  225. protected void DeviceReset(int id, string name, int time, Action<string> notify, Action<string> error)
  226. {
  227. Tuple<bool, Result> ret = Delay(id, () =>
  228. {
  229. notify(String.Format("Device reset"));
  230. Singleton<DeviceEntity>.Instance.PostMsg( DeviceEntity.MSG.RESET);
  231. return true;
  232. }, time * 1000);
  233. if (ret.Item1)
  234. {
  235. if (ret.Item2 == Result.RUN)
  236. {
  237. throw (new RoutineBreakException());
  238. }
  239. }
  240. }
  241. #region aligner
  242. public void AlignerReset(int id, Aligner device, string name, int time, Action<string> notify, Action<string> error)
  243. {
  244. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  245. {
  246. notify(String.Format("{0} clear error", device.Name));
  247. string reason = string.Empty;
  248. return device.Clear(out reason);
  249. }, () =>
  250. {
  251. if (device.Busy == false)
  252. {
  253. return true;
  254. }
  255. return false;
  256. }, time * 1000);
  257. if (ret.Item1)
  258. {
  259. if (ret.Item2 == Result.FAIL)
  260. {
  261. throw (new RoutineFaildException());
  262. }
  263. else if (ret.Item2 == Result.TIMEOUT) //timeout
  264. {
  265. error(String.Format("{0} timeout, than {1} seconds", name, time));
  266. throw (new RoutineFaildException());
  267. }
  268. else
  269. throw (new RoutineBreakException());
  270. }
  271. }
  272. public void AlignerInit(int id, Aligner device, string name, Action<string> notify, Action<string> error)
  273. {
  274. Tuple<bool, Result> ret = Execute(id, () =>
  275. {
  276. notify(String.Format("{0} Home", device.Name));
  277. string reason = string.Empty;
  278. return device.Init(out reason);
  279. });
  280. if (ret.Item1)
  281. {
  282. if (ret.Item2 == Result.FAIL)
  283. {
  284. throw (new RoutineFaildException());
  285. }
  286. }
  287. }
  288. public void AlignerHome(int id, Aligner device, string name, Action<string> notify, Action<string> error)
  289. {
  290. Tuple<bool, Result> ret = Execute(id, () =>
  291. {
  292. notify(String.Format("{0} Home", device.Name));
  293. string reason = string.Empty;
  294. return device.Home(out reason);
  295. });
  296. if (ret.Item1)
  297. {
  298. if (ret.Item2 == Result.FAIL)
  299. {
  300. throw (new RoutineFaildException());
  301. }
  302. }
  303. }
  304. public void AlignerMoveUp(int id, Aligner device, string name, Action<string> notify, Action<string> error)
  305. {
  306. Tuple<bool, Result> ret = Execute(id, () =>
  307. {
  308. notify(String.Format("{0} Lift up", device.Name));
  309. string reason = string.Empty;
  310. return device.LiftUp(out reason);
  311. });
  312. if (ret.Item1)
  313. {
  314. if (ret.Item2 == Result.FAIL)
  315. {
  316. throw (new RoutineFaildException());
  317. }
  318. }
  319. }
  320. #endregion
  321. #region Loadport
  322. ///等待 Loadport
  323. public void QueryLoadportState(int id, LoadPort device, string name, int time, Action<string> notify, Action<string> error)
  324. {
  325. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  326. {
  327. notify(String.Format("{0} query state", device.Name));
  328. string reason = string.Empty;
  329. device.QueryState(out reason);
  330. return true;
  331. }, () =>
  332. {
  333. if (!device.IsBusy)
  334. {
  335. return true;
  336. }
  337. return false;
  338. }, time * 1000);
  339. if (ret.Item1)
  340. {
  341. if (ret.Item2 == Result.FAIL)
  342. {
  343. throw (new RoutineFaildException());
  344. }
  345. else if (ret.Item2 == Result.TIMEOUT) //timeout
  346. {
  347. error(String.Format("{0} query timeout, than {1} seconds", name, time));
  348. throw (new RoutineFaildException());
  349. }
  350. else
  351. throw (new RoutineBreakException());
  352. }
  353. }
  354. #endregion
  355. void WaferSensorResetCreate()
  356. {
  357. if(!_scanBuffer) return;
  358. var sensors = new List<bool>
  359. {
  360. DeviceModel.SensorCoolingStageSLOT1WaferON != null ? DeviceModel.SensorCoolingStageSLOT1WaferON.Value : true,
  361. DeviceModel.SensorCoolingStageSLOT2WaferON != null ? DeviceModel.SensorCoolingStageSLOT2WaferON.Value : true,
  362. DeviceModel.SensorCoolingStageSLOT3WaferON != null ? DeviceModel.SensorCoolingStageSLOT3WaferON.Value : true,
  363. DeviceModel.SensorCoolingStageSLOT4WaferON != null ? DeviceModel.SensorCoolingStageSLOT4WaferON.Value : true,
  364. DeviceModel.SensorCoolingStageSLOT5WaferON != null ? DeviceModel.SensorCoolingStageSLOT5WaferON.Value : true,
  365. DeviceModel.SensorCoolingStageSLOT6WaferON != null ? DeviceModel.SensorCoolingStageSLOT6WaferON.Value : true,
  366. };
  367. var index = 0;
  368. foreach (var sensor in sensors)
  369. {
  370. if (!sensor && WaferManager.Instance.CheckNoWafer(ModuleName.Buffer, index))
  371. {
  372. WaferManager.Instance.CreateWafer(ModuleName.Buffer, index, WaferStatus.Normal);
  373. }
  374. else if(sensor && WaferManager.Instance.CheckHasWafer(ModuleName.Buffer,index))
  375. {
  376. WaferManager.Instance.DeleteWafer(ModuleName.Buffer, index);
  377. }
  378. index++;
  379. }
  380. var robotSensors = new List<bool>
  381. {
  382. DeviceModel.SensorRBlowerArmhavewafer != null ? DeviceModel.SensorRBlowerArmhavewafer.Value : true,
  383. DeviceModel.SensorRBupperArmhavewafer != null ? DeviceModel.SensorRBupperArmhavewafer.Value : true,
  384. };
  385. index = 0;
  386. foreach (var sensor in robotSensors)
  387. {
  388. if (!sensor && WaferManager.Instance.CheckNoWafer(ModuleName.Robot, index))
  389. {
  390. WaferManager.Instance.CreateWafer(ModuleName.Robot, index, WaferStatus.Normal);
  391. }
  392. else if(sensor && WaferManager.Instance.CheckHasWafer(ModuleName.Robot,index))
  393. {
  394. WaferManager.Instance.DeleteWafer(ModuleName.Robot, index);
  395. }
  396. index++;
  397. }
  398. if (DeviceModel.SensorPreAlignerWaferOn !=null && !DeviceModel.SensorPreAlignerWaferOn.Value && WaferManager.Instance.CheckNoWafer(ModuleName.Aligner, 0))
  399. {
  400. WaferManager.Instance.CreateWafer(ModuleName.Aligner, 0, WaferStatus.Normal);
  401. }
  402. else
  403. {
  404. if(DeviceDefineManager.Instance.GetValue<bool>("AlignerInstalled") ?? false)
  405. WaferManager.Instance.DeleteWafer(ModuleName.Aligner, 0);
  406. }
  407. _scanBuffer = false;
  408. }
  409. public void CooingbufferHome(int id, IoCoolingBuffer device, string name, int time, Action<string> notify, Action<string> error)
  410. {
  411. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  412. {
  413. if (device == null)
  414. {
  415. EV.PostAlarmLog("System", String.Format("{0} Device is Null", name));
  416. return false;
  417. }
  418. notify(String.Format("{0} clear error", device.Name));
  419. string reason = string.Empty;
  420. return device.Home(out reason);
  421. }, () =>
  422. {
  423. if (device.Busy == false)
  424. {
  425. return true;
  426. }
  427. return false;
  428. }, time * 1000);
  429. if (ret.Item1)
  430. {
  431. if (ret.Item2 == Result.FAIL)
  432. {
  433. throw (new RoutineFaildException());
  434. }
  435. else if (ret.Item2 == Result.TIMEOUT) //timeout
  436. {
  437. error(String.Format("{0} timeout, than {1} seconds", name, time));
  438. throw (new RoutineFaildException());
  439. }
  440. else
  441. throw (new RoutineBreakException());
  442. }
  443. }
  444. protected override void Notify(string message)
  445. {
  446. EV.PostMessage(Module, EventEnum.GeneralInfo, String.Format("Home sequence :{0}", message));
  447. }
  448. /// <summary>
  449. /// prepare process failed
  450. /// </summary>
  451. /// <param name="failReason"></param>
  452. /// <param name="reactor"></param>
  453. protected override void Stop(string failReason)
  454. {
  455. string reason = String.Empty;
  456. EV.PostMessage(Module, EventEnum.HomeFailed, failReason);
  457. }
  458. }
  459. }