CycleRobotCycleNewRoutine.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using CyberX8_Core;
  5. using CyberX8_RT.Devices.EFEM;
  6. using CyberX8_RT.Modules.Rinse;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.Routine;
  9. using MECF.Framework.Common.Schedulers;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using MECF.Framework.Common.Utilities;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. namespace CyberX8_RT.Modules.EFEM
  18. {
  19. public class CycleRobotCycleNewRoutine : ModuleRoutineBase, IRoutine
  20. {
  21. private enum CycleRobotCycleStep
  22. {
  23. LoopStart,
  24. LoopRunRobotCycle,
  25. LoopRunRobotCycleWait,
  26. LoopEnd,
  27. End
  28. }
  29. /// <summary>
  30. /// Cycle次数
  31. /// </summary>
  32. private int _cycleTimes;
  33. /// <summary>
  34. /// 当前处于第几次Cycle
  35. /// </summary>
  36. private int _currentCycle;
  37. private object[] param;
  38. private RobotCycleMoveRoutine _cycleMoveRoutine;
  39. private List<ModuleName> _sequences;
  40. private int _alignerAngle;
  41. private List<EfemCycleAction> _actions;
  42. public CycleRobotCycleNewRoutine(EfemBase efem) : base(ModuleName.EfemRobot)
  43. {
  44. _cycleMoveRoutine = new RobotCycleMoveRoutine(efem);
  45. }
  46. public RState Start(params object[] objs)
  47. {
  48. string str = objs[0].ToString();
  49. _sequences = new List<ModuleName>();
  50. foreach(string item in str.Split('-'))
  51. {
  52. _sequences.Add((ModuleName)Enum.Parse(typeof(ModuleName), item));
  53. }
  54. _cycleTimes=(int)objs[1];
  55. _alignerAngle = (int)objs[2];
  56. _actions = new List<EfemCycleAction>();
  57. GenerateCycleAction();
  58. if (_cycleTimes < 1)
  59. {
  60. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Input Robot Cycle Times{_cycleTimes} error");
  61. return RState.Failed;
  62. }
  63. return Runner.Start(Module, "Start CycleRobotCycleRoutine");
  64. }
  65. private void GenerateCycleAction()
  66. {
  67. if (!ModuleHelper.IsLoadPort(_sequences[0]))
  68. {
  69. return;
  70. }
  71. WaferInfo[] waferInfos = WaferManager.Instance.GetWafers(_sequences[0]);
  72. int count = 0;
  73. foreach (WaferInfo item in waferInfos)
  74. {
  75. if (item.IsEmpty)
  76. {
  77. continue;
  78. }
  79. _actions.AddRange(GenerateCycle(_sequences[0], item.Slot, _sequences[1], ModuleHelper.IsDummy(_sequences[1]) ? count : 0));
  80. for (int i = 1; i < _sequences.Count; i++)
  81. {
  82. if (i == 1)
  83. {
  84. _actions.AddRange(GenerateCycle(_sequences[i], ModuleHelper.IsDummy(_sequences[i]) ? count : 0, _sequences[i + 1],
  85. ModuleHelper.IsDummy(_sequences[i + 1]) ? count : 0));
  86. }
  87. else if (i == _sequences.Count - 1)
  88. {
  89. _actions.AddRange(GenerateCycle(_sequences[i], ModuleHelper.IsDummy(_sequences[i]) ? count : 0, _sequences[0],
  90. item.Slot));
  91. }
  92. }
  93. count++;
  94. }
  95. }
  96. private List<EfemCycleAction> GenerateCycle(ModuleName source,int sourceSlot,ModuleName destModule,int destSlot)
  97. {
  98. List<EfemCycleAction> actions = new List<EfemCycleAction>();
  99. if (source == ModuleName.Aligner1)
  100. {
  101. EfemCycleAction action = new EfemCycleAction();
  102. action.Action = "Align";
  103. action.Parameter = _alignerAngle;
  104. actions.Add(action);
  105. }
  106. EfemCycleAction pick = new EfemCycleAction();
  107. MoveItem pickMoveItem = new MoveItem();
  108. pickMoveItem.SourceModule = source;
  109. pickMoveItem.SourceSlot = sourceSlot;
  110. pick.Parameter = pickMoveItem;
  111. pick.Action = "Pick";
  112. actions.Add(pick);
  113. EfemCycleAction place = new EfemCycleAction();
  114. MoveItem placeMoveItem = new MoveItem();
  115. placeMoveItem.DestinationModule = destModule;
  116. placeMoveItem.DestinationSlot = destSlot;
  117. place.Parameter = placeMoveItem;
  118. place.Action = "Place";
  119. actions.Add(place);
  120. return actions;
  121. }
  122. public RState Monitor()
  123. {
  124. Runner.LoopStart(CycleRobotCycleStep.LoopStart, "Loop StartCycleRobotCycleRoutine", _cycleTimes, NullFun, _delay_1ms)
  125. .LoopRun(CycleRobotCycleStep.LoopRunRobotCycle, () => _cycleMoveRoutine.Start(_actions) == RState.Running,_delay_1ms)
  126. .LoopRunWithStopStatus(CycleRobotCycleStep.LoopRunRobotCycleWait, () => { return CommonFunction.CheckRoutineEndState(_cycleMoveRoutine); },
  127. () => CheckRoutineStopStatus(_cycleMoveRoutine, "CycleRobotCycleRoutine failed"))
  128. .LoopEnd(CycleRobotCycleStep.LoopEnd, UpdateCycleCount, _delay_1ms)
  129. .End(CycleRobotCycleStep.End, AchievedCycleCount, _delay_1ms);
  130. return Runner.Status;
  131. }
  132. private bool CheckRoutineStopStatus(IRoutine routine, string error)
  133. {
  134. bool result = CommonFunction.CheckRoutineStopState(routine);
  135. if (result)
  136. {
  137. Stop($"{error}");
  138. }
  139. return result;
  140. }
  141. /// <summary>
  142. /// Abort
  143. /// </summary>
  144. public void Abort()
  145. {
  146. Runner.Stop("CycleRobotCycleRoutine Abort");
  147. }
  148. /// <summary>
  149. /// 统计完成的Cycle次数
  150. /// </summary>
  151. /// <returns></returns>
  152. private bool UpdateCycleCount()
  153. {
  154. _currentCycle += 1;
  155. return true;
  156. }
  157. /// <summary>
  158. ///
  159. /// </summary>
  160. /// <returns></returns>
  161. private bool AchievedCycleCount()
  162. {
  163. _currentCycle -= 1;
  164. return true;
  165. }
  166. /// <summary>
  167. /// 获取当前Cycle次数
  168. /// </summary>
  169. /// <returns></returns>
  170. public int GetCurrentCycle()
  171. {
  172. return _currentCycle;
  173. }
  174. }
  175. }