CycleRobotCycleNewRoutine.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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 int _alignerAngle;
  46. private List<EfemCycleAction> _actions;
  47. private int _dummySlotNumber = 25; //当前cycle中的dummy slot 数量
  48. public CycleRobotCycleNewRoutine(EfemBase efem) : base(ModuleName.EfemRobot)
  49. {
  50. _cycleMoveRoutine = new RobotCycleMoveRoutine(efem);
  51. }
  52. public RState Start(params object[] objs)
  53. {
  54. _currentCycle = 0;
  55. string str = objs[0].ToString();
  56. _sequences = JsonConvert.DeserializeObject<List<RobotCycleParameter>>(str);
  57. if(!CheckRobotCyclePreCondiction(_sequences))
  58. {
  59. return RState.Failed;
  60. }
  61. _cycleTimes=(int)objs[1];
  62. _alignerAngle = (int)objs[2];
  63. _actions = new List<EfemCycleAction>();
  64. GenerateCycleAction();
  65. if (_cycleTimes < 1)
  66. {
  67. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Input Robot Cycle Times{_cycleTimes} error");
  68. return RState.Failed;
  69. }
  70. return Runner.Start(Module, "Start CycleRobotCycleRoutine");
  71. }
  72. private void GenerateCycleAction()
  73. {
  74. ModuleName sequenceModuleName = _sequences[0].ModuleName;
  75. WaferInfo[] waferInfos = WaferManager.Instance.GetWafers(sequenceModuleName);
  76. int count = 0;
  77. foreach (WaferInfo item in waferInfos)
  78. {
  79. if (item.IsEmpty)
  80. {
  81. continue;
  82. }
  83. _actions.AddRange(GenerateCycle(_sequences[0], item.Slot, _sequences[1].ModuleName, ModuleHelper.IsDummy(_sequences[1].ModuleName) ? count : 0));
  84. for (int i = 1; i < _sequences.Count; i++)
  85. {
  86. if (i == _sequences.Count - 1)
  87. {
  88. _actions.AddRange(GenerateCycle(_sequences[i], ModuleHelper.IsDummy(_sequences[i].ModuleName) ? count : 0, _sequences[0].ModuleName,
  89. item.Slot));
  90. }
  91. //else (i == 1)
  92. else
  93. {
  94. _actions.AddRange(GenerateCycle(_sequences[i], ModuleHelper.IsDummy(_sequences[i].ModuleName) ? count : 0, _sequences[i + 1].ModuleName,
  95. ModuleHelper.IsDummy(_sequences[i + 1].ModuleName) ? count : 0));
  96. }
  97. if (ModuleHelper.IsDummy(_sequences[i].ModuleName))
  98. {
  99. WaferInfo[] dummywaferInfos = WaferManager.Instance.GetWafers(_sequences[i].ModuleName);
  100. if (dummywaferInfos != null)
  101. {
  102. _dummySlotNumber = dummywaferInfos.Length;
  103. }
  104. }
  105. }
  106. count++;
  107. if(count >= _dummySlotNumber)
  108. {
  109. count = 0;
  110. }
  111. }
  112. }
  113. private List<EfemCycleAction> GenerateCycle(RobotCycleParameter sourceParameter,int sourceSlot,ModuleName destModule,int destSlot)
  114. {
  115. List<EfemCycleAction> actions = new List<EfemCycleAction>();
  116. if (sourceParameter.ModuleName == ModuleName.Aligner1)
  117. {
  118. EfemCycleAction action = new EfemCycleAction();
  119. action.Action = "Align";
  120. action.Parameter = sourceParameter.Parameter;
  121. actions.Add(action);
  122. }
  123. EfemCycleAction pick = new EfemCycleAction();
  124. MoveItem pickMoveItem = new MoveItem();
  125. pickMoveItem.SourceModule = sourceParameter.ModuleName;
  126. pickMoveItem.SourceSlot = sourceSlot;
  127. pickMoveItem.RobotHand = sourceParameter.RobotArm;
  128. pick.Parameter = pickMoveItem;
  129. pick.Action = "Pick";
  130. actions.Add(pick);
  131. EfemCycleAction place = new EfemCycleAction();
  132. MoveItem placeMoveItem = new MoveItem();
  133. placeMoveItem.DestinationModule = destModule;
  134. placeMoveItem.DestinationSlot = destSlot;
  135. placeMoveItem.RobotHand = sourceParameter.RobotArm;
  136. placeMoveItem.RobotFlip = sourceParameter.RobotFlip;
  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<RobotCycleParameter> lists)
  195. {
  196. bool result = true;
  197. //Robot
  198. if (!CheckRobotStatus())
  199. {
  200. return false;
  201. }
  202. //LP
  203. if(lists.FindIndex(O=>O.ModuleName.ToString()==ModuleName.LP1.ToString())!=-1)
  204. {
  205. if (!CheckLoadPortStatus(ModuleName.LP1))
  206. {
  207. return false;
  208. };
  209. }
  210. else if (lists.FindIndex(O => O.ModuleName.ToString() == ModuleName.LP1.ToString()) != -1)
  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.FindIndex(O => O.ModuleName.ToString() == ModuleName.Dummy1.ToString()) != -1)
  226. {
  227. if (!CheckDummyStatus(ModuleName.Dummy1))
  228. {
  229. return false;
  230. };
  231. }
  232. else if(lists.FindIndex(O => O.ModuleName.ToString() == ModuleName.Dummy2.ToString()) != -1)
  233. {
  234. if (!CheckDummyStatus(ModuleName.Dummy2))
  235. {
  236. return false;
  237. };
  238. }
  239. //Srd
  240. if (lists.FindIndex(O => O.ModuleName.ToString() == ModuleName.SRD1.ToString()) != -1)
  241. {
  242. if (!CheckSrdStatus(ModuleName.SRD1))
  243. {
  244. return false;
  245. };
  246. }
  247. else if(lists.FindIndex(O => O.ModuleName.ToString() == ModuleName.SRD2.ToString()) != -1)
  248. {
  249. if (!CheckSrdStatus(ModuleName.SRD2))
  250. {
  251. return false;
  252. };
  253. }
  254. return result;
  255. }
  256. //检查robot状态
  257. private bool CheckRobotStatus()
  258. {
  259. bool result = true;
  260. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  261. {
  262. Stop($"Efem robot arm already has a wafer, cannot do the RobotCycle action");
  263. result = false;
  264. }
  265. return result;
  266. }
  267. //检查loadport状态
  268. private bool CheckLoadPortStatus(ModuleName loadpoartName)
  269. {
  270. bool result = true;
  271. if (ModuleHelper.IsInstalled(loadpoartName))
  272. {
  273. Loadport loadPort = GetLoadPort(loadpoartName);
  274. if (loadPort == null)
  275. {
  276. Stop($"{loadpoartName} is null");
  277. return false;
  278. }
  279. WaferInfo[] waferInfos = WaferManager.Instance.GetWafers(loadpoartName);
  280. if (waferInfos.Length < 1)
  281. {
  282. Stop($"there is no wafer in {loadpoartName}");
  283. return false;
  284. }
  285. }
  286. else
  287. {
  288. Stop($"{loadpoartName} is not installed");
  289. return false;
  290. }
  291. return result;
  292. }
  293. private Loadport GetLoadPort(ModuleName station)
  294. {
  295. LoadPortModule loadPortModule = Singleton<RouteManager>.Instance.EFEM.GetLoadportModule(station - ModuleName.LP1);
  296. return loadPortModule.LPDevice;
  297. }
  298. //Dummy状态判断
  299. private bool CheckDummyStatus(ModuleName dummyName)
  300. {
  301. bool result = true;
  302. if (!ModuleHelper.IsInstalled(dummyName))
  303. {
  304. Stop($"{dummyName} is not installed");
  305. return false;
  306. }
  307. //若dummy存在wafer,需要人工处理
  308. DummyDevice dummyDevice = Singleton<RouteManager>.Instance.EFEM.GetDummyDevice(dummyName - ModuleName.Dummy1);
  309. if (dummyDevice != null)
  310. {
  311. if (!dummyDevice.HasCassette)
  312. {
  313. Stop($"{dummyName} dose not have cassette");
  314. return false;
  315. }
  316. WaferInfo[] waferInfos = WaferManager.Instance.GetWafers(dummyName);
  317. if (waferInfos.Length > 0)
  318. {
  319. foreach (var item in waferInfos)
  320. {
  321. if (item != null && !item.IsEmpty)
  322. {
  323. Stop($"There are wafers inside the {dummyName},cannot do the RobotCycle action");
  324. return false;
  325. }
  326. }
  327. }
  328. }
  329. return result;
  330. }
  331. //检查puf
  332. private bool CheckPufStatus(ModuleName pufName)
  333. {
  334. bool result = true;
  335. if (!ModuleHelper.IsInstalled(pufName))
  336. {
  337. Stop($"{pufName} is not install");
  338. return false;
  339. }
  340. JetAxisBase puf1RotationAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PUF1}.Rotation");
  341. if (puf1RotationAxis == null)
  342. {
  343. Stop("Puf1 Rotation Axis is null");
  344. return false;
  345. }
  346. double puf1RotationPosition = puf1RotationAxis.MotionData.MotorPosition;
  347. if ( !puf1RotationAxis.CheckPositionIsInStation(puf1RotationPosition, "Robot"))
  348. {
  349. Stop($"PUF1 Rotation {puf1RotationPosition} is not in Robot");
  350. return false;
  351. }
  352. return result;
  353. }
  354. //检查srd
  355. private bool CheckSrdStatus(ModuleName SrdName)
  356. {
  357. bool result = true;
  358. if (!ModuleHelper.IsInstalled(SrdName))
  359. {
  360. Stop($"{SrdName} is not install");
  361. return false;
  362. }
  363. return result;
  364. }
  365. }
  366. }