CycleRobotCycleNewRoutine.cs 13 KB

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