EfemRetractRoutine.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using System;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.RT.SCCore;
  4. using Aitex.Core.Util;
  5. using Aitex.Sorter.Common;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.Schedulers;
  8. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  9. using MECF.Framework.RT.EquipmentLibrary.LogicUnits;
  10. using MECF.Framework.RT.ModuleLibrary.PMModules;
  11. using MECF.Framework.RT.ModuleLibrary.SystemModules;
  12. namespace FutureEfemLib.Efems
  13. {
  14. class EfemRetractRoutine : ModuleRoutine, IRoutine
  15. {
  16. enum RoutineStep
  17. {
  18. CheckBeforeRetract,
  19. Retract,
  20. WaitCloseSlitValveInterlock,
  21. CloseSlitValve,
  22. PostTransfer
  23. }
  24. private ModuleName _source;
  25. private int _sourceSlot;
  26. private Hand _blade;
  27. private int _timeout;
  28. // private TMSlitValveRoutine _closeSlitValveRoutine = new TMSlitValveRoutine();
  29. private EfemModule _robotModule;
  30. //private RobotPostionEnum postiontype;
  31. private ITransferTarget _target;
  32. public EfemRetractRoutine(EfemModule robotModule)
  33. {
  34. Module = "EfemRobot";
  35. Name = "Retract";
  36. _robotModule = robotModule;
  37. }
  38. private string _type;
  39. public void Init(ModuleName source, int sourceSlot, string blade,string type)
  40. {
  41. _source = source;
  42. _sourceSlot = sourceSlot;
  43. _blade = (Hand)Enum.Parse(typeof(Hand), blade);
  44. _type = type;
  45. //_closeSlitValveRoutine.Init(source.ToString(), false);
  46. }
  47. public void Init(ModuleName source, int sourceSlot, int blade)
  48. {
  49. Init(source, sourceSlot, blade);
  50. }
  51. public Result Start(params object[] objs)
  52. {
  53. Reset();
  54. _timeout = SC.GetValue<int>("EFEM.EfemRobot.PickTimeout");
  55. //if (ModuleHelper.IsLoadLock(_source))
  56. //{
  57. // LoadLock ll = DEVICE.GetDevice<LoadLock>(_source.ToString());
  58. // if (!ll.CheckEnableTransfer(EnumTransferType.Extend))
  59. // {
  60. // EV.PostWarningLog(Module, $"can not retract, {_source} not ready for transfer");
  61. // return Result.FAIL;
  62. // }
  63. //}
  64. if (ModuleHelper.IsPm(_source))
  65. {
  66. if (_type=="Pick")
  67. {
  68. //postiontype = RobotPostionEnum.PickRetracted;// _blade == Hand.Blade1 ?RobotPostionEnum.PickRetractLow: RobotPostionEnum.PickRetractUp;
  69. }
  70. else
  71. {
  72. //postiontype = RobotPostionEnum.PlaceRetract;//_blade == Hand.Blade1 ? RobotPostionEnum.PlaceRetractLow : RobotPostionEnum.PlaceRetractUp;
  73. }
  74. // PMModuleBase pm = DEVICE.GetDevice<PMModule>(_source.ToString()+"."+ _source.ToString());
  75. _target = EquipmentManager.Modules[_source] as ITransferTarget;
  76. //if (!pm.CheckReadyForTransfer(ModuleName.EfemRobot, _blade, _sourceSlot, EnumTransferType.Retract, out _))
  77. //{
  78. // EV.PostWarningLog(Module, $"can not retract, {_source} not ready for transfer");
  79. // return Result.FAIL;
  80. //}
  81. }
  82. Notify($"Start, retract from {_source} slot {_sourceSlot + 1} with {_blade}");
  83. return Result.RUN;
  84. }
  85. public void Abort()
  86. {
  87. Notify("Abort");
  88. }
  89. public Result Monitor()
  90. {
  91. try
  92. {
  93. RobotRetract((int)RoutineStep.Retract,_source, _sourceSlot, _blade, _timeout);
  94. //WaitSlitValveCloseInterlock((int)RoutineStep.WaitCloseSlitValveInterlock, TMDevice.GetSlitValve(_source), _timeout);
  95. //ExecuteRoutine((int)RoutineStep.CloseSlitValve, _closeSlitValveRoutine);
  96. if (ModuleHelper.IsPm(_source))
  97. {
  98. PostTransfer((int)RoutineStep.PostTransfer, _target as PMModuleBase, EnumTransferType.Retract, _timeout);
  99. }
  100. }
  101. catch (RoutineBreakException)
  102. {
  103. return Result.RUN;
  104. }
  105. catch (RoutineFaildException)
  106. {
  107. return Result.FAIL;
  108. }
  109. Notify($"Finish, retract from {_source} slot {_sourceSlot + 1} with {_blade}");
  110. return Result.DONE;
  111. }
  112. public void RobotRetract(int id, ModuleName chamber, int slot, Hand hand, int timeout)
  113. {
  114. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  115. {
  116. Notify("robot execute goto command");
  117. //string reason;
  118. //if (!_robotModule.RobotDevice.GotoRE(chamber, hand, slot, postiontype, out reason))
  119. //{
  120. // Stop(reason);
  121. // return false;
  122. //}
  123. return true;
  124. }, () =>
  125. {
  126. if (_robotModule.RobotDevice.IsError)
  127. return null;
  128. if (_robotModule.RobotDevice.IsIdle)
  129. return true;
  130. return false;
  131. }, timeout * 1000);
  132. if (ret.Item1)
  133. {
  134. if (ret.Item2 == Result.FAIL)
  135. {
  136. Stop(string.Format("failed."));
  137. throw (new RoutineFaildException());
  138. }
  139. else if (ret.Item2 == Result.TIMEOUT) //timeout
  140. {
  141. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  142. throw (new RoutineFaildException());
  143. }
  144. else
  145. throw (new RoutineBreakException());
  146. }
  147. }
  148. public void PostTransfer(int id, PMModuleBase pm, EnumTransferType type, int timeout)
  149. {
  150. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  151. {
  152. Notify($"{pm.Name} post transfer ");
  153. if (!pm.PostTransfer(ModuleName.EfemRobot, Hand.Blade1, 0, type, out string reason))
  154. {
  155. Stop(reason);
  156. return false;
  157. }
  158. return true;
  159. }, () =>
  160. {
  161. if (pm.IsError)
  162. {
  163. return null;
  164. }
  165. return pm.IsReady;
  166. }, timeout * 1000);
  167. if (ret.Item1)
  168. {
  169. if (ret.Item2 == Result.FAIL)
  170. {
  171. Stop($"{pm.Name} error");
  172. throw (new RoutineFaildException());
  173. }
  174. else if (ret.Item2 == Result.TIMEOUT) //timeout
  175. {
  176. Stop($"{pm.Name} post transfer timeout, over {timeout} seconds");
  177. throw (new RoutineFaildException());
  178. }
  179. else
  180. throw (new RoutineBreakException());
  181. }
  182. }
  183. }
  184. }