CycleRobotCycleNewRoutine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. /// <summary>
  44. /// 当前执行到哪一步
  45. /// </summary>
  46. private string _currentStep;
  47. private RobotCycleMoveRoutine _cycleMoveRoutine;
  48. private List<RobotCycleParameter> _sequences;
  49. private List<EfemCycleAction> _actions;
  50. private int _dummySlotNumber = 25; //当前cycle中的dummy slot 数量
  51. public CycleRobotCycleNewRoutine(EfemBase efem) : base(ModuleName.EfemRobot)
  52. {
  53. _cycleMoveRoutine = new RobotCycleMoveRoutine(efem);
  54. }
  55. public RState Start(params object[] objs)
  56. {
  57. _currentCycle = 0;
  58. string str = objs[0].ToString();
  59. _sequences = JsonConvert.DeserializeObject<List<RobotCycleParameter>>(str);
  60. if(!CheckRobotCyclePreCondiction(_sequences))
  61. {
  62. return RState.Failed;
  63. }
  64. _cycleTimes=(int)objs[1];
  65. _actions = new List<EfemCycleAction>();
  66. GenerateCycleAction();
  67. if (_cycleTimes < 1)
  68. {
  69. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Input Robot Cycle Times{_cycleTimes} error");
  70. return RState.Failed;
  71. }
  72. return Runner.Start(Module, "Start CycleRobotCycleRoutine");
  73. }
  74. private void GenerateCycleAction()
  75. {
  76. ModuleName sequenceModuleName = _sequences[0].ModuleName;
  77. WaferInfo[] waferInfos = WaferManager.Instance.GetWafers(sequenceModuleName);
  78. foreach (WaferInfo item in waferInfos)
  79. {
  80. if (item.IsEmpty)
  81. {
  82. continue;
  83. }
  84. // generateCycle的参数:源模块,源模块slot,目的模块,目的模块slot
  85. if(_sequences.Count == 1)
  86. {
  87. _actions.AddRange(GenerateCycle(_sequences[0], item.Slot, _sequences[0].ModuleName, 0));
  88. }
  89. else
  90. {
  91. _actions.AddRange(GenerateCycle(_sequences[0], item.Slot, _sequences[1].ModuleName, 0));
  92. }
  93. for (int i = 1; i < _sequences.Count; i++)
  94. {
  95. if (i == _sequences.Count - 1)
  96. {
  97. _actions.AddRange(GenerateCycle(_sequences[i], 0, _sequences[0].ModuleName, item.Slot));
  98. }
  99. //else (i == 1)
  100. else
  101. {
  102. _actions.AddRange(GenerateCycle(_sequences[i], 0, _sequences[i + 1].ModuleName, 0));
  103. }
  104. }
  105. }
  106. }
  107. /// <summary>
  108. /// 返回从哪儿取,放到哪儿的一个EfemCycleAction列表
  109. /// </summary>
  110. /// <param name="sourceParameter"></param>
  111. /// <param name="sourceSlot"></param>
  112. /// <param name="destModule"></param>
  113. /// <param name="destSlot"></param>
  114. /// <returns></returns>
  115. private List<EfemCycleAction> GenerateCycle(RobotCycleParameter sourceParameter,int sourceSlot,ModuleName destModule,int destSlot)
  116. {
  117. List<EfemCycleAction> actions = new List<EfemCycleAction>();
  118. if (sourceParameter.ModuleName == ModuleName.Aligner1)
  119. {
  120. EfemCycleAction action = new EfemCycleAction();
  121. action.Action = "Align";
  122. action.Parameter = sourceParameter.Parameter;
  123. actions.Add(action);
  124. }
  125. EfemCycleAction pick = new EfemCycleAction();
  126. MoveItem pickMoveItem = new MoveItem();
  127. pickMoveItem.SourceModule = sourceParameter.ModuleName;
  128. pickMoveItem.SourceSlot = sourceSlot;
  129. pickMoveItem.RobotHand = sourceParameter.RobotArm;
  130. pickMoveItem.PickRobotFlip = sourceParameter.PickRobotFlip;
  131. pick.Parameter = pickMoveItem;
  132. pick.Action = "Pick";
  133. actions.Add(pick);
  134. EfemCycleAction place = new EfemCycleAction();
  135. MoveItem placeMoveItem = new MoveItem();
  136. placeMoveItem.DestinationModule = destModule;
  137. placeMoveItem.DestinationSlot = destSlot;
  138. placeMoveItem.RobotHand = sourceParameter.RobotArm;
  139. placeMoveItem.PlaceRobotFlip = sourceParameter.PlaceRobotFlip;
  140. place.Parameter = placeMoveItem;
  141. place.Action = "Place";
  142. actions.Add(place);
  143. return actions;
  144. }
  145. public RState Monitor()
  146. {
  147. Runner.LoopStart(CycleRobotCycleStep.LoopStart, "Loop StartCycleRobotCycleRoutine", _cycleTimes, NullFun, _delay_1ms)
  148. .LoopRun(CycleRobotCycleStep.LoopRunRobotCycle, () => _cycleMoveRoutine.Start(_actions) == RState.Running,_delay_1ms)
  149. .LoopRunWithStopStatus(CycleRobotCycleStep.LoopRunRobotCycleWait, () => { return CommonFunction.CheckRoutineEndState(_cycleMoveRoutine); },
  150. () => CheckRoutineStopStatus(_cycleMoveRoutine, "CycleRobotCycleRoutine failed"),false, 86400000)//24小时
  151. .LoopEnd(CycleRobotCycleStep.LoopEnd, UpdateCycleCount, _delay_1ms)
  152. .End(CycleRobotCycleStep.End, NullFun, _delay_1ms);
  153. return Runner.Status;
  154. }
  155. private bool CheckRoutineStopStatus(IRoutine routine, string error)
  156. {
  157. bool result = CommonFunction.CheckRoutineStopState(routine);
  158. if (result)
  159. {
  160. Stop($"{error}");
  161. }
  162. return result;
  163. }
  164. /// <summary>
  165. /// Abort
  166. /// </summary>
  167. public void Abort()
  168. {
  169. Runner.Stop("CycleRobotCycleRoutine Abort");
  170. }
  171. /// <summary>
  172. /// 统计完成的Cycle次数
  173. /// </summary>
  174. /// <returns></returns>
  175. private bool UpdateCycleCount()
  176. {
  177. _currentCycle += 1;
  178. return true;
  179. }
  180. /// <summary>
  181. ///
  182. /// </summary>
  183. /// <returns></returns>
  184. private bool AchievedCycleCount()
  185. {
  186. _currentCycle -= 1;
  187. return true;
  188. }
  189. /// <summary>
  190. /// 获取当前Cycle次数
  191. /// </summary>
  192. /// <returns></returns>
  193. public int GetCurrentCycle()
  194. {
  195. return _currentCycle;
  196. }
  197. private bool CheckRobotCyclePreCondiction(List<RobotCycleParameter> lists)
  198. {
  199. bool result = true;
  200. //Robot
  201. if (!CheckRobotStatus())
  202. {
  203. return false;
  204. }
  205. //LP
  206. if(lists.FindIndex(O=>O.ModuleName.ToString()==ModuleName.LP1.ToString())!=-1)
  207. {
  208. if (!CheckLoadPortStatus(ModuleName.LP1))
  209. {
  210. return false;
  211. };
  212. }
  213. else if (lists.FindIndex(O => O.ModuleName.ToString() == ModuleName.LP2.ToString()) != -1)
  214. {
  215. if (!CheckLoadPortStatus(ModuleName.LP2))
  216. {
  217. return false;
  218. };
  219. }
  220. return result;
  221. }
  222. //检查robot状态
  223. private bool CheckRobotStatus()
  224. {
  225. bool result = true;
  226. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  227. {
  228. Stop($"Efem robot arm already has a wafer, cannot do the RobotCycle action");
  229. result = false;
  230. }
  231. return result;
  232. }
  233. //检查loadport状态
  234. private bool CheckLoadPortStatus(ModuleName loadpoartName)
  235. {
  236. bool result = true;
  237. if (ModuleHelper.IsInstalled(loadpoartName))
  238. {
  239. Loadport loadPort = GetLoadPort(loadpoartName);
  240. if (loadPort == null)
  241. {
  242. Stop($"{loadpoartName} is null");
  243. return false;
  244. }
  245. WaferInfo[] waferInfos = WaferManager.Instance.GetWafers(loadpoartName);
  246. if (waferInfos.Length < 1)
  247. {
  248. Stop($"there is no wafer in {loadpoartName}");
  249. return false;
  250. }
  251. }
  252. else
  253. {
  254. Stop($"{loadpoartName} is not installed");
  255. return false;
  256. }
  257. return result;
  258. }
  259. private Loadport GetLoadPort(ModuleName station)
  260. {
  261. LoadPortModule loadPortModule = Singleton<RouteManager>.Instance.EFEM.GetLoadportModule(station - ModuleName.LP1);
  262. return loadPortModule.LPDevice;
  263. }
  264. //Dummy状态判断
  265. private bool CheckDummyStatus(ModuleName dummyName)
  266. {
  267. bool result = true;
  268. if (!ModuleHelper.IsInstalled(dummyName))
  269. {
  270. Stop($"{dummyName} is not installed");
  271. return false;
  272. }
  273. //若dummy存在wafer,需要人工处理
  274. DummyDevice dummyDevice = Singleton<RouteManager>.Instance.EFEM.GetDummyDevice(dummyName - ModuleName.Dummy1);
  275. if (dummyDevice != null)
  276. {
  277. if (!dummyDevice.HasCassette)
  278. {
  279. Stop($"{dummyName} dose not have cassette");
  280. return false;
  281. }
  282. WaferInfo[] waferInfos = WaferManager.Instance.GetWafers(dummyName);
  283. if (waferInfos.Length > 0)
  284. {
  285. foreach (var item in waferInfos)
  286. {
  287. if (item != null && !item.IsEmpty)
  288. {
  289. Stop($"There are wafers inside the {dummyName},cannot do the RobotCycle action");
  290. return false;
  291. }
  292. }
  293. }
  294. }
  295. return result;
  296. }
  297. //检查srd
  298. private bool CheckSrdStatus(ModuleName SrdName)
  299. {
  300. bool result = true;
  301. if (!ModuleHelper.IsInstalled(SrdName))
  302. {
  303. Stop($"{SrdName} is not install");
  304. return false;
  305. }
  306. return result;
  307. }
  308. }
  309. }