CycleRobotCycleNewRoutine.cs 14 KB

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