CycleRobotCycleNewRoutine.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.RT.Routine;
  5. using Aitex.Core.Util;
  6. using CyberX8_Core;
  7. using CyberX8_RT.Devices.AXIS;
  8. using CyberX8_RT.Devices.EFEM;
  9. using CyberX8_RT.Modules.LPs;
  10. using CyberX8_RT.Modules.Rinse;
  11. using MECF.Framework.Common.Equipment;
  12. using MECF.Framework.Common.Routine;
  13. using MECF.Framework.Common.Schedulers;
  14. using MECF.Framework.Common.SubstrateTrackings;
  15. using MECF.Framework.Common.Utilities;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. namespace CyberX8_RT.Modules.EFEM
  22. {
  23. public class CycleRobotCycleNewRoutine : ModuleRoutineBase, IRoutine
  24. {
  25. private enum CycleRobotCycleStep
  26. {
  27. LoopStart,
  28. LoopRunRobotCycle,
  29. LoopRunRobotCycleWait,
  30. LoopEnd,
  31. End
  32. }
  33. /// <summary>
  34. /// Cycle次数
  35. /// </summary>
  36. private int _cycleTimes;
  37. /// <summary>
  38. /// 当前处于第几次Cycle
  39. /// </summary>
  40. private int _currentCycle;
  41. private RobotCycleMoveRoutine _cycleMoveRoutine;
  42. private List<ModuleName> _sequences;
  43. private int _alignerAngle;
  44. private List<EfemCycleAction> _actions;
  45. private int _dummySlotNumber = 25; //当前cycle中的dummy slot 数量
  46. public CycleRobotCycleNewRoutine(EfemBase efem) : base(ModuleName.EfemRobot)
  47. {
  48. _cycleMoveRoutine = new RobotCycleMoveRoutine(efem);
  49. }
  50. public RState Start(params object[] objs)
  51. {
  52. _currentCycle = 0;
  53. string str = objs[0].ToString();
  54. _sequences = new List<ModuleName>();
  55. foreach(string item in str.Split('-'))
  56. {
  57. _sequences.Add((ModuleName)Enum.Parse(typeof(ModuleName), item));
  58. }
  59. if(!CheckRobotCyclePreCondiction(_sequences))
  60. {
  61. return RState.Failed;
  62. }
  63. _cycleTimes=(int)objs[1];
  64. _alignerAngle = (int)objs[2];
  65. _actions = new List<EfemCycleAction>();
  66. GenerateCycleAction();
  67. if (_cycleTimes < 1)
  68. {
  69. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Input Robot Cycle Times{_cycleTimes} error");
  70. return RState.Failed;
  71. }
  72. return Runner.Start(Module, "Start CycleRobotCycleRoutine");
  73. }
  74. private void GenerateCycleAction()
  75. {
  76. if (!ModuleHelper.IsLoadPort(_sequences[0]))
  77. {
  78. return;
  79. }
  80. WaferInfo[] waferInfos = WaferManager.Instance.GetWafers(_sequences[0]);
  81. int count = 0;
  82. foreach (WaferInfo item in waferInfos)
  83. {
  84. if (item.IsEmpty)
  85. {
  86. continue;
  87. }
  88. _actions.AddRange(GenerateCycle(_sequences[0], item.Slot, _sequences[1], ModuleHelper.IsDummy(_sequences[1]) ? count : 0));
  89. for (int i = 1; i < _sequences.Count; i++)
  90. {
  91. if (i == 1)
  92. {
  93. _actions.AddRange(GenerateCycle(_sequences[i], ModuleHelper.IsDummy(_sequences[i]) ? count : 0, _sequences[i + 1],
  94. ModuleHelper.IsDummy(_sequences[i + 1]) ? count : 0));
  95. }
  96. else if (i == _sequences.Count - 1)
  97. {
  98. _actions.AddRange(GenerateCycle(_sequences[i], ModuleHelper.IsDummy(_sequences[i]) ? count : 0, _sequences[0],
  99. item.Slot));
  100. }
  101. if (ModuleHelper.IsDummy(_sequences[i]))
  102. {
  103. WaferInfo[] dummywaferInfos = WaferManager.Instance.GetWafers(_sequences[i]);
  104. if (dummywaferInfos != null)
  105. {
  106. _dummySlotNumber = dummywaferInfos.Length;
  107. }
  108. }
  109. }
  110. count++;
  111. if(count >= _dummySlotNumber)
  112. {
  113. count = 0;
  114. }
  115. }
  116. }
  117. private List<EfemCycleAction> GenerateCycle(ModuleName source,int sourceSlot,ModuleName destModule,int destSlot)
  118. {
  119. List<EfemCycleAction> actions = new List<EfemCycleAction>();
  120. if (source == ModuleName.Aligner1)
  121. {
  122. EfemCycleAction action = new EfemCycleAction();
  123. action.Action = "Align";
  124. action.Parameter = _alignerAngle;
  125. actions.Add(action);
  126. }
  127. EfemCycleAction pick = new EfemCycleAction();
  128. MoveItem pickMoveItem = new MoveItem();
  129. pickMoveItem.SourceModule = source;
  130. pickMoveItem.SourceSlot = sourceSlot;
  131. pick.Parameter = pickMoveItem;
  132. pick.Action = "Pick";
  133. actions.Add(pick);
  134. EfemCycleAction place = new EfemCycleAction();
  135. MoveItem placeMoveItem = new MoveItem();
  136. placeMoveItem.DestinationModule = destModule;
  137. placeMoveItem.DestinationSlot = destSlot;
  138. place.Parameter = placeMoveItem;
  139. place.Action = "Place";
  140. actions.Add(place);
  141. return actions;
  142. }
  143. public RState Monitor()
  144. {
  145. Runner.LoopStart(CycleRobotCycleStep.LoopStart, "Loop StartCycleRobotCycleRoutine", _cycleTimes, NullFun, _delay_1ms)
  146. .LoopRun(CycleRobotCycleStep.LoopRunRobotCycle, () => _cycleMoveRoutine.Start(_actions) == RState.Running,_delay_1ms)
  147. .LoopRunWithStopStatus(CycleRobotCycleStep.LoopRunRobotCycleWait, () => { return CommonFunction.CheckRoutineEndState(_cycleMoveRoutine); },
  148. () => CheckRoutineStopStatus(_cycleMoveRoutine, "CycleRobotCycleRoutine failed"), 86400000)//24小时
  149. .LoopEnd(CycleRobotCycleStep.LoopEnd, UpdateCycleCount, _delay_1ms)
  150. .End(CycleRobotCycleStep.End, AchievedCycleCount, _delay_1ms);
  151. return Runner.Status;
  152. }
  153. private bool CheckRoutineStopStatus(IRoutine routine, string error)
  154. {
  155. bool result = CommonFunction.CheckRoutineStopState(routine);
  156. if (result)
  157. {
  158. Stop($"{error}");
  159. }
  160. return result;
  161. }
  162. /// <summary>
  163. /// Abort
  164. /// </summary>
  165. public void Abort()
  166. {
  167. Runner.Stop("CycleRobotCycleRoutine Abort");
  168. }
  169. /// <summary>
  170. /// 统计完成的Cycle次数
  171. /// </summary>
  172. /// <returns></returns>
  173. private bool UpdateCycleCount()
  174. {
  175. _currentCycle += 1;
  176. return true;
  177. }
  178. /// <summary>
  179. ///
  180. /// </summary>
  181. /// <returns></returns>
  182. private bool AchievedCycleCount()
  183. {
  184. _currentCycle -= 1;
  185. return true;
  186. }
  187. /// <summary>
  188. /// 获取当前Cycle次数
  189. /// </summary>
  190. /// <returns></returns>
  191. public int GetCurrentCycle()
  192. {
  193. return _currentCycle;
  194. }
  195. private bool CheckRobotCyclePreCondiction(List<ModuleName> lists)
  196. {
  197. bool result = true;
  198. //Robot
  199. if (!CheckRobotStatus())
  200. {
  201. return false;
  202. }
  203. //LP
  204. if(lists.Contains(ModuleName.LP1))
  205. {
  206. if (!CheckLoadPortStatus(ModuleName.LP1))
  207. {
  208. return false;
  209. };
  210. }
  211. else if (lists.Contains(ModuleName.LP2))
  212. {
  213. if (!CheckLoadPortStatus(ModuleName.LP2))
  214. {
  215. return false;
  216. };
  217. }
  218. else
  219. {
  220. if (!CheckLoadPortStatus(ModuleName.LP2))
  221. {
  222. return false;
  223. };
  224. }
  225. //Dummy
  226. if (lists.Contains(ModuleName.Dummy1))
  227. {
  228. if (!CheckDummyStatus(ModuleName.Dummy1))
  229. {
  230. return false;
  231. };
  232. }
  233. else if(lists.Contains(ModuleName.Dummy2))
  234. {
  235. if (!CheckDummyStatus(ModuleName.Dummy2))
  236. {
  237. return false;
  238. };
  239. }
  240. //Puf
  241. if (lists.Contains(ModuleName.PUF1) && !CheckPufStatus(ModuleName.PUF1))
  242. {
  243. return false ;
  244. }
  245. //Srd
  246. if (lists.Contains(ModuleName.SRD1))
  247. {
  248. if (!CheckSrdStatus(ModuleName.SRD1))
  249. {
  250. return false;
  251. };
  252. }
  253. else if(lists.Contains(ModuleName.SRD2))
  254. {
  255. if (!CheckSrdStatus(ModuleName.SRD2))
  256. {
  257. return false;
  258. };
  259. }
  260. return result;
  261. }
  262. //检查robot状态
  263. private bool CheckRobotStatus()
  264. {
  265. bool result = true;
  266. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  267. {
  268. Stop($"Efem robot arm already has a wafer, cannot do the RobotCycle action");
  269. result = false;
  270. }
  271. return result;
  272. }
  273. //检查loadport状态
  274. private bool CheckLoadPortStatus(ModuleName loadpoartName)
  275. {
  276. bool result = true;
  277. if (ModuleHelper.IsInstalled(loadpoartName))
  278. {
  279. Loadport loadPort = GetLoadPort(loadpoartName);
  280. if (loadPort == null)
  281. {
  282. Stop($"{loadpoartName} is null");
  283. return false;
  284. }
  285. WaferInfo[] waferInfos = WaferManager.Instance.GetWafers(loadpoartName);
  286. if (waferInfos.Length < 1)
  287. {
  288. Stop($"there is no wafer in {loadpoartName}");
  289. return false;
  290. }
  291. }
  292. else
  293. {
  294. Stop($"{loadpoartName} is not installed");
  295. return false;
  296. }
  297. return result;
  298. }
  299. private Loadport GetLoadPort(ModuleName station)
  300. {
  301. LoadPortModule loadPortModule = Singleton<RouteManager>.Instance.EFEM.GetLoadportModule(station - ModuleName.LP1);
  302. return loadPortModule.LPDevice;
  303. }
  304. //Dummy状态判断
  305. private bool CheckDummyStatus(ModuleName dummyName)
  306. {
  307. bool result = true;
  308. if (!ModuleHelper.IsInstalled(dummyName))
  309. {
  310. Stop($"{dummyName} is not installed");
  311. return false;
  312. }
  313. //若dummy存在wafer,需要人工处理
  314. DummyDevice dummyDevice = Singleton<RouteManager>.Instance.EFEM.GetDummyDevice(dummyName - ModuleName.Dummy1);
  315. if (dummyDevice != null)
  316. {
  317. if (!dummyDevice.HasCassette)
  318. {
  319. Stop($"{dummyName} dose not have cassette");
  320. return false;
  321. }
  322. WaferInfo[] waferInfos = WaferManager.Instance.GetWafers(dummyName);
  323. if (waferInfos.Length > 0)
  324. {
  325. foreach (var item in waferInfos)
  326. {
  327. if (item != null && !item.IsEmpty)
  328. {
  329. Stop($"There are wafers inside the {dummyName},cannot do the RobotCycle action");
  330. return false;
  331. }
  332. }
  333. }
  334. }
  335. return result;
  336. }
  337. //检查puf
  338. private bool CheckPufStatus(ModuleName pufName)
  339. {
  340. bool result = true;
  341. if (!ModuleHelper.IsInstalled(pufName))
  342. {
  343. Stop($"{pufName} is not install");
  344. return false;
  345. }
  346. JetAxisBase puf1RotationAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PUF1}.Rotation");
  347. if (puf1RotationAxis == null)
  348. {
  349. Stop("Puf1 Rotation Axis is null");
  350. return false;
  351. }
  352. double puf1RotationPosition = puf1RotationAxis.MotionData.MotorPosition;
  353. if ( !puf1RotationAxis.CheckPositionIsInStation(puf1RotationPosition, "Robot"))
  354. {
  355. Stop($"PUF1 Rotation {puf1RotationPosition} is not in Robot");
  356. return false;
  357. }
  358. return result;
  359. }
  360. //检查srd
  361. private bool CheckSrdStatus(ModuleName SrdName)
  362. {
  363. bool result = true;
  364. if (!ModuleHelper.IsInstalled(SrdName))
  365. {
  366. Stop($"{SrdName} is not install");
  367. return false;
  368. }
  369. return result;
  370. }
  371. }
  372. }