CycleRobotCycleNewRoutine.cs 13 KB

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