CycleRobotCycleNewRoutine.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. pick.Parameter = pickMoveItem;
  120. pick.Action = "Pick";
  121. actions.Add(pick);
  122. EfemCycleAction place = new EfemCycleAction();
  123. MoveItem placeMoveItem = new MoveItem();
  124. placeMoveItem.DestinationModule = destModule;
  125. placeMoveItem.DestinationSlot = destSlot;
  126. placeMoveItem.RobotHand = sourceParameter.RobotArm;
  127. placeMoveItem.RobotFlip = sourceParameter.RobotFlip;
  128. place.Parameter = placeMoveItem;
  129. place.Action = "Place";
  130. actions.Add(place);
  131. return actions;
  132. }
  133. public RState Monitor()
  134. {
  135. Runner.LoopStart(CycleRobotCycleStep.LoopStart, "Loop StartCycleRobotCycleRoutine", _cycleTimes, NullFun, _delay_1ms)
  136. .LoopRun(CycleRobotCycleStep.LoopRunRobotCycle, () => _cycleMoveRoutine.Start(_actions) == RState.Running,_delay_1ms)
  137. .LoopRunWithStopStatus(CycleRobotCycleStep.LoopRunRobotCycleWait, () => { return CommonFunction.CheckRoutineEndState(_cycleMoveRoutine); },
  138. () => CheckRoutineStopStatus(_cycleMoveRoutine, "CycleRobotCycleRoutine failed"), 86400000)//24小时
  139. .LoopEnd(CycleRobotCycleStep.LoopEnd, UpdateCycleCount, _delay_1ms)
  140. .End(CycleRobotCycleStep.End, AchievedCycleCount, _delay_1ms);
  141. return Runner.Status;
  142. }
  143. private bool CheckRoutineStopStatus(IRoutine routine, string error)
  144. {
  145. bool result = CommonFunction.CheckRoutineStopState(routine);
  146. if (result)
  147. {
  148. Stop($"{error}");
  149. }
  150. return result;
  151. }
  152. /// <summary>
  153. /// Abort
  154. /// </summary>
  155. public void Abort()
  156. {
  157. Runner.Stop("CycleRobotCycleRoutine Abort");
  158. }
  159. /// <summary>
  160. /// 统计完成的Cycle次数
  161. /// </summary>
  162. /// <returns></returns>
  163. private bool UpdateCycleCount()
  164. {
  165. _currentCycle += 1;
  166. return true;
  167. }
  168. /// <summary>
  169. ///
  170. /// </summary>
  171. /// <returns></returns>
  172. private bool AchievedCycleCount()
  173. {
  174. _currentCycle -= 1;
  175. return true;
  176. }
  177. /// <summary>
  178. /// 获取当前Cycle次数
  179. /// </summary>
  180. /// <returns></returns>
  181. public int GetCurrentCycle()
  182. {
  183. return _currentCycle;
  184. }
  185. private bool CheckRobotCyclePreCondiction(List<RobotCycleParameter> lists)
  186. {
  187. bool result = true;
  188. //Robot
  189. if (!CheckRobotStatus())
  190. {
  191. return false;
  192. }
  193. //LP
  194. if(lists.FindIndex(O=>O.ModuleName.ToString()==ModuleName.LP1.ToString())!=-1)
  195. {
  196. if (!CheckLoadPortStatus(ModuleName.LP1))
  197. {
  198. return false;
  199. };
  200. }
  201. else if (lists.FindIndex(O => O.ModuleName.ToString() == ModuleName.LP2.ToString()) != -1)
  202. {
  203. if (!CheckLoadPortStatus(ModuleName.LP2))
  204. {
  205. return false;
  206. };
  207. }
  208. //Dummy
  209. if (lists.FindIndex(O => O.ModuleName.ToString() == ModuleName.Dummy1.ToString()) != -1)
  210. {
  211. if (!CheckDummyStatus(ModuleName.Dummy1))
  212. {
  213. return false;
  214. };
  215. }
  216. else if(lists.FindIndex(O => O.ModuleName.ToString() == ModuleName.Dummy2.ToString()) != -1)
  217. {
  218. if (!CheckDummyStatus(ModuleName.Dummy2))
  219. {
  220. return false;
  221. };
  222. }
  223. //Srd
  224. if (lists.FindIndex(O => O.ModuleName.ToString() == ModuleName.SRD1.ToString()) != -1)
  225. {
  226. if (!CheckSrdStatus(ModuleName.SRD1))
  227. {
  228. return false;
  229. };
  230. }
  231. else if(lists.FindIndex(O => O.ModuleName.ToString() == ModuleName.SRD2.ToString()) != -1)
  232. {
  233. if (!CheckSrdStatus(ModuleName.SRD2))
  234. {
  235. return false;
  236. };
  237. }
  238. return result;
  239. }
  240. //检查robot状态
  241. private bool CheckRobotStatus()
  242. {
  243. bool result = true;
  244. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  245. {
  246. Stop($"Efem robot arm already has a wafer, cannot do the RobotCycle action");
  247. result = false;
  248. }
  249. return result;
  250. }
  251. //检查loadport状态
  252. private bool CheckLoadPortStatus(ModuleName loadpoartName)
  253. {
  254. bool result = true;
  255. if (ModuleHelper.IsInstalled(loadpoartName))
  256. {
  257. Loadport loadPort = GetLoadPort(loadpoartName);
  258. if (loadPort == null)
  259. {
  260. Stop($"{loadpoartName} is null");
  261. return false;
  262. }
  263. WaferInfo[] waferInfos = WaferManager.Instance.GetWafers(loadpoartName);
  264. if (waferInfos.Length < 1)
  265. {
  266. Stop($"there is no wafer in {loadpoartName}");
  267. return false;
  268. }
  269. }
  270. else
  271. {
  272. Stop($"{loadpoartName} is not installed");
  273. return false;
  274. }
  275. return result;
  276. }
  277. private Loadport GetLoadPort(ModuleName station)
  278. {
  279. LoadPortModule loadPortModule = Singleton<RouteManager>.Instance.EFEM.GetLoadportModule(station - ModuleName.LP1);
  280. return loadPortModule.LPDevice;
  281. }
  282. //Dummy状态判断
  283. private bool CheckDummyStatus(ModuleName dummyName)
  284. {
  285. bool result = true;
  286. if (!ModuleHelper.IsInstalled(dummyName))
  287. {
  288. Stop($"{dummyName} is not installed");
  289. return false;
  290. }
  291. //若dummy存在wafer,需要人工处理
  292. DummyDevice dummyDevice = Singleton<RouteManager>.Instance.EFEM.GetDummyDevice(dummyName - ModuleName.Dummy1);
  293. if (dummyDevice != null)
  294. {
  295. if (!dummyDevice.HasCassette)
  296. {
  297. Stop($"{dummyName} dose not have cassette");
  298. return false;
  299. }
  300. WaferInfo[] waferInfos = WaferManager.Instance.GetWafers(dummyName);
  301. if (waferInfos.Length > 0)
  302. {
  303. foreach (var item in waferInfos)
  304. {
  305. if (item != null && !item.IsEmpty)
  306. {
  307. Stop($"There are wafers inside the {dummyName},cannot do the RobotCycle action");
  308. return false;
  309. }
  310. }
  311. }
  312. }
  313. return result;
  314. }
  315. //检查puf
  316. private bool CheckPufStatus(ModuleName pufName)
  317. {
  318. bool result = true;
  319. if (!ModuleHelper.IsInstalled(pufName))
  320. {
  321. Stop($"{pufName} is not install");
  322. return false;
  323. }
  324. JetAxisBase puf1RotationAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PUF1}.Rotation");
  325. if (puf1RotationAxis == null)
  326. {
  327. Stop("Puf1 Rotation Axis is null");
  328. return false;
  329. }
  330. double puf1RotationPosition = puf1RotationAxis.MotionData.MotorPosition;
  331. if ( !puf1RotationAxis.CheckPositionIsInStation(puf1RotationPosition, "Robot"))
  332. {
  333. Stop($"PUF1 Rotation {puf1RotationPosition} is not in Robot");
  334. return false;
  335. }
  336. return result;
  337. }
  338. //检查srd
  339. private bool CheckSrdStatus(ModuleName SrdName)
  340. {
  341. bool result = true;
  342. if (!ModuleHelper.IsInstalled(SrdName))
  343. {
  344. Stop($"{SrdName} is not install");
  345. return false;
  346. }
  347. return result;
  348. }
  349. }
  350. }