CycleRobotCycleNewRoutine.cs 12 KB

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