EfemExtendRoutine.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 EfemExtendRoutine : ModuleRoutine, IRoutine
  15. {
  16. enum RoutineStep
  17. {
  18. WaitOpenSlitValveInterlock,
  19. OpenSlitValve,
  20. CheckBeforeExtend,
  21. Extend,
  22. PrepareTransfer,
  23. }
  24. private ModuleName _source;
  25. private int _sourceSlot;
  26. private Hand _hand;
  27. private int _timeout;
  28. //private TMSlitValveRoutine _openSlitValveRoutine = new TMSlitValveRoutine();
  29. private ITransferTarget _target;
  30. private EfemModule _robotModule;
  31. //private RobotPostionEnum postiontype;
  32. public EfemExtendRoutine(EfemModule robotModule)
  33. {
  34. Module = "Efem";
  35. Name = "Extend";
  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. _hand = (Hand)Enum.Parse(typeof(Hand), blade);
  44. _type = type;
  45. // _openSlitValveRoutine.Init(source.ToString(), true);
  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 extend, {_source} not ready for transfer");
  61. // return Result.FAIL;
  62. // }
  63. //}
  64. if (ModuleHelper.IsPm(_source))
  65. {
  66. if (_type=="Place")
  67. {
  68. //postiontype = RobotPostionEnum.PlaceExtendUp;//_hand == Hand.Blade1 ? RobotPostionEnum.PlaceExtendDown : RobotPostionEnum.PlaceExtendUp;
  69. }
  70. else
  71. {
  72. //postiontype = RobotPostionEnum.PickExtendLow;//_hand == Hand.Blade1 ? RobotPostionEnum.PickExtendLow : RobotPostionEnum.PickExtendUp;
  73. }
  74. _target = EquipmentManager.Modules[_source] as ITransferTarget;
  75. //if (!pm.CheckReadyForTransfer(ModuleName.EfemRobot,_hand, _sourceSlot, EnumTransferType.Extend, out _))
  76. //{
  77. // EV.PostWarningLog(Module, $"can not extend, {_source} not ready for transfer");
  78. // return Result.FAIL;
  79. //}
  80. }
  81. Notify($"Start, extend to {_source} slot {_sourceSlot + 1} with {_hand}");
  82. return Result.RUN;
  83. }
  84. public void Abort()
  85. {
  86. Notify("Abort");
  87. }
  88. public Result Monitor()
  89. {
  90. try
  91. {
  92. //if (!_target.CheckReadyForTransfer(ModuleName.EfemRobot, _hand, _sourceSlot, EnumTransferType.Pick, out _))
  93. //{
  94. // PrepareTransfer((int)RoutineStep.PrepareTransfer, _target as PMModuleBase, EnumTransferType.Extend, _timeout);
  95. //}
  96. //WaitSlitValveOpenInterlock((int)RoutineStep.WaitOpenSlitValveInterlock, TMDevice.GetSlitValve(_source), _timeout);
  97. //ExecuteRoutine((int)RoutineStep.OpenSlitValve, _openSlitValveRoutine);
  98. // CheckBeforeExtend((int)RoutineStep.CheckBeforeExtend, _source, _sourceSlot, _hand);
  99. RobotExtend((int)RoutineStep.Extend, _source, _sourceSlot, _hand, _timeout);
  100. }
  101. catch (RoutineBreakException)
  102. {
  103. return Result.RUN;
  104. }
  105. catch (RoutineFaildException)
  106. {
  107. return Result.FAIL;
  108. }
  109. Notify($"Finish, extend to {_source} slot {_sourceSlot + 1} with {_hand}");
  110. return Result.DONE;
  111. }
  112. public void RobotExtend(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 PrepareTransfer(int id, PMModuleBase pm, EnumTransferType type, int timeout)
  149. {
  150. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  151. {
  152. Notify($"{pm.Name} Prepare transfer ");
  153. if (!pm.PrepareTransfer(ModuleName.EfemRobot, Hand.Blade1, 0, type, 0, 0, false, 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} Prepare transfer timeout, over {timeout} seconds");
  177. throw (new RoutineFaildException());
  178. }
  179. else
  180. throw (new RoutineBreakException());
  181. }
  182. }
  183. }
  184. }