CycleRobotCycleNewRoutine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. return result;
  210. }
  211. //检查robot状态
  212. private bool CheckRobotStatus()
  213. {
  214. bool result = true;
  215. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  216. {
  217. Stop($"Efem robot arm already has a wafer, cannot do the RobotCycle action");
  218. result = false;
  219. }
  220. return result;
  221. }
  222. //检查loadport状态
  223. private bool CheckLoadPortStatus(ModuleName loadpoartName)
  224. {
  225. bool result = true;
  226. if (ModuleHelper.IsInstalled(loadpoartName))
  227. {
  228. Loadport loadPort = GetLoadPort(loadpoartName);
  229. if (loadPort == null)
  230. {
  231. Stop($"{loadpoartName} is null");
  232. return false;
  233. }
  234. WaferInfo[] waferInfos = WaferManager.Instance.GetWafers(loadpoartName);
  235. if (waferInfos.Length < 1)
  236. {
  237. Stop($"there is no wafer in {loadpoartName}");
  238. return false;
  239. }
  240. }
  241. else
  242. {
  243. Stop($"{loadpoartName} is not installed");
  244. return false;
  245. }
  246. return result;
  247. }
  248. private Loadport GetLoadPort(ModuleName station)
  249. {
  250. LoadPortModule loadPortModule = Singleton<RouteManager>.Instance.EFEM.GetLoadportModule(station - ModuleName.LP1);
  251. return loadPortModule.LPDevice;
  252. }
  253. //Dummy状态判断
  254. private bool CheckDummyStatus(ModuleName dummyName)
  255. {
  256. bool result = true;
  257. if (!ModuleHelper.IsInstalled(dummyName))
  258. {
  259. Stop($"{dummyName} is not installed");
  260. return false;
  261. }
  262. //若dummy存在wafer,需要人工处理
  263. DummyDevice dummyDevice = Singleton<RouteManager>.Instance.EFEM.GetDummyDevice(dummyName - ModuleName.Dummy1);
  264. if (dummyDevice != null)
  265. {
  266. if (!dummyDevice.HasCassette)
  267. {
  268. Stop($"{dummyName} dose not have cassette");
  269. return false;
  270. }
  271. WaferInfo[] waferInfos = WaferManager.Instance.GetWafers(dummyName);
  272. if (waferInfos.Length > 0)
  273. {
  274. foreach (var item in waferInfos)
  275. {
  276. if (item != null && !item.IsEmpty)
  277. {
  278. Stop($"There are wafers inside the {dummyName},cannot do the RobotCycle action");
  279. return false;
  280. }
  281. }
  282. }
  283. }
  284. return result;
  285. }
  286. //检查puf
  287. private bool CheckPufStatus(ModuleName pufName)
  288. {
  289. bool result = true;
  290. if (!ModuleHelper.IsInstalled(pufName))
  291. {
  292. Stop($"{pufName} is not install");
  293. return false;
  294. }
  295. JetAxisBase puf1RotationAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PUF1}.Rotation");
  296. if (puf1RotationAxis == null)
  297. {
  298. Stop("Puf1 Rotation Axis is null");
  299. return false;
  300. }
  301. double puf1RotationPosition = puf1RotationAxis.MotionData.MotorPosition;
  302. if ( !puf1RotationAxis.CheckPositionIsInStation(puf1RotationPosition, "Robot"))
  303. {
  304. Stop($"PUF1 Rotation {puf1RotationPosition} is not in Robot");
  305. return false;
  306. }
  307. return result;
  308. }
  309. //检查srd
  310. private bool CheckSrdStatus(ModuleName SrdName)
  311. {
  312. bool result = true;
  313. if (!ModuleHelper.IsInstalled(SrdName))
  314. {
  315. Stop($"{SrdName} is not install");
  316. return false;
  317. }
  318. return result;
  319. }
  320. }
  321. }