EfemHomeRoutine.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using Aitex.Core.RT.Routine;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Sorter.Common;
  4. using CyberX8_RT.Devices;
  5. using MECF.Framework.Common.Routine;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.SubstrateTrackings;
  8. using CyberX8_Core;
  9. using Aitex.Core.RT.Log;
  10. using Aitex.Core.Common;
  11. using Aitex.Core.Util;
  12. using MECF.Framework.Common.Schedulers;
  13. using System.Collections.Generic;
  14. using CyberX8_RT.Devices.EFEM;
  15. using MECF.Framework.Common.Utilities;
  16. namespace CyberX8_RT.Modules.EFEM
  17. {
  18. class EfemHomeRoutine : ModuleRoutineBase, IRoutine
  19. {
  20. private enum HomeStep
  21. {
  22. PowerOn,
  23. SetHomeSpeed,
  24. InitAligner,
  25. HomeAll,
  26. CheckWaferPresence,
  27. DummyMap,
  28. CheckDummyMap,
  29. SetRobotSpeed,
  30. End,
  31. }
  32. private enum HomeModuleStep
  33. {
  34. SetHomeSpeed,
  35. Home,
  36. HomeAxes,
  37. SetRobotSpeed,
  38. End,
  39. }
  40. private int _homeTimeout = 30 * 1000;
  41. ModuleName _targetModule;
  42. EfemBase _efem;
  43. int _defaultSpeed = SC.GetValue<int>("EFEM.DefaultMoveSpeedInPercent");
  44. int _homeSpeed = SC.GetValue<int>("EFEM.DefaultHomeSpeedInPercent");
  45. bool _isLP1Unable = SC.GetValue<bool>("EFEM.IsLoadPort1Unable");
  46. bool _isLP2Unable = SC.GetValue<bool>("EFEM.IsLoadPort2Unable");
  47. bool _isLP3Unable = SC.GetValue<bool>("EFEM.IsLoadPort3Unable");
  48. private
  49. Hand _hand = Hand.Blade1;
  50. private EfemMapDummyRoutine _mapDummyRoutine;
  51. public EfemHomeRoutine(EfemBase efem) : base(ModuleName.EfemRobot)
  52. {
  53. _efem = efem;
  54. _mapDummyRoutine = new EfemMapDummyRoutine(efem);
  55. }
  56. public RState Start(params object[] objs)
  57. {
  58. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand))
  59. {
  60. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Efem robot arm{_hand} already has a wafer, cannot do the home action");
  61. return RState.Failed;
  62. }
  63. _isLP1Unable = SC.GetValue<bool>("EFEM.IsLoadPort1Unable");
  64. _isLP2Unable = SC.GetValue<bool>("EFEM.IsLoadPort2Unable");
  65. _isLP3Unable = SC.GetValue<bool>("EFEM.IsLoadPort3Unable");
  66. _defaultSpeed = SC.GetValue<int>("EFEM.DefaultMoveSpeedInPercent");
  67. _homeSpeed = SC.GetValue<int>("EFEM.DefaultHomeSpeedInPercent");
  68. _targetModule = (ModuleName)objs[0];
  69. _homeTimeout = SC.GetValue<int>($"EFEM.HomeTimeout") * 1000;
  70. return Runner.Start(Module, $"Home {_targetModule}");
  71. }
  72. public RState Monitor()
  73. {
  74. if(_targetModule == ModuleName.EFEM)
  75. {
  76. Runner.Run(HomeStep.PowerOn, PowerOn, IsStepComplete, _delay_5s)
  77. .Run(HomeStep.SetHomeSpeed, SetHomeSpeed, IsStepComplete, _delay_5s)
  78. .Run(HomeStep.InitAligner, HomeAligner, IsStepComplete, _homeTimeout)
  79. .Run(HomeStep.HomeAll, HomeAll, IsStepComplete, _homeTimeout)
  80. .Run(HomeStep.CheckWaferPresence, CheckWaferPresence, VerifyWaferPresence, _delay_5s)
  81. .Run(HomeStep.DummyMap, StartMapDummy,_delay_1ms)
  82. .WaitWithStopCondition(HomeStep.CheckDummyMap,()=>CommonFunction.CheckRoutineEndState(_mapDummyRoutine),
  83. ()=>CommonFunction.CheckRoutineStopState(_mapDummyRoutine))
  84. .Run(HomeStep.SetRobotSpeed, SetRobotSpeed, IsStepComplete, _delay_5s)
  85. .End(HomeStep.End, NullFun, _delay_1ms);
  86. }
  87. else
  88. {
  89. Runner.Run(HomeStep.PowerOn, PowerOn, IsStepComplete, _delay_5s)
  90. .Run(HomeModuleStep.SetHomeSpeed, SetHomeSpeed, IsStepComplete, _delay_5s)
  91. .Run(HomeModuleStep.Home, HomeModule, IsStepComplete, _homeTimeout)
  92. .Run(HomeModuleStep.SetRobotSpeed, SetRobotSpeed, IsStepComplete, _delay_5s)
  93. .End(HomeModuleStep.End, NullFun, _delay_50ms);
  94. }
  95. return Runner.Status;
  96. }
  97. private bool StartMapDummy()
  98. {
  99. return _mapDummyRoutine.Start() == RState.Running;
  100. }
  101. public void Abort()
  102. {
  103. }
  104. private bool IsStepComplete()
  105. {
  106. if (_efem.Status == RState.End)
  107. {
  108. return true;
  109. }
  110. else if (_efem.Status == RState.Failed)
  111. {
  112. Runner.Stop($"Efem home failed: {_efem.Status}");
  113. return true;
  114. }
  115. else
  116. return false;
  117. }
  118. private bool HomeAll()
  119. {
  120. return _efem.HomeAll();
  121. }
  122. private bool HomeAligner()
  123. {
  124. return _efem.Home(ModuleName.Aligner1);
  125. }
  126. private bool HomeModule()
  127. {
  128. return _efem.Home(_targetModule);
  129. }
  130. private bool CheckWaferPresence()
  131. {
  132. return _efem.CheckWaferPresence();
  133. }
  134. private bool PowerOn()
  135. {
  136. return _efem.RobotPowerOn(ModuleName.EfemRobot, true);
  137. }
  138. private bool SetHomeSpeed()
  139. {
  140. return _efem.SetRobotSpeed(ModuleName.EfemRobot, _homeSpeed);
  141. }
  142. private bool SetRobotSpeed()
  143. {
  144. return _efem.SetRobotSpeed(ModuleName.EfemRobot, _defaultSpeed);
  145. }
  146. private bool VerifyWaferPresence()
  147. {
  148. if (_efem.Status == RState.End)
  149. {
  150. var waferPresence = _efem.GetWaferPresence();
  151. //000/111 upperArmWafer, lowerArmWafer, alignerWafer1,
  152. //if (waferPresence.Length != 3)
  153. //{
  154. // LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"EFEM Track wafer present return invalid value, Wafer Presence:{waferPresence}, should be 3 characters");
  155. // return false;
  156. //}
  157. //aligner2
  158. //if (waferPresence[3] == '1')
  159. //{
  160. // if (WaferManager.Instance.CheckNoWafer(ModuleName.Aligner2, 0))
  161. // {
  162. // WaferManager.Instance.CreateWafer(ModuleName.Aligner2, 0, WaferStatus.Normal);
  163. // }
  164. //}
  165. //else
  166. //{
  167. // if (WaferManager.Instance.CheckHasWafer(ModuleName.Aligner2, 0))
  168. // {
  169. // LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $" {ModuleName.Aligner2} has wafer information, while EFEM return empty, manually delete if really no wafer");
  170. // }
  171. //}
  172. //cooling1
  173. //if (waferPresence[4] == '1')
  174. //{
  175. // if (WaferManager.Instance.CheckNoWafer(ModuleName.Cooling1, 0))
  176. // {
  177. // WaferManager.Instance.CreateWafer(ModuleName.Cooling1, 0, WaferStatus.Normal);
  178. // }
  179. //}
  180. //else
  181. //{
  182. // if (WaferManager.Instance.CheckHasWafer(ModuleName.Cooling1, 0))
  183. // {
  184. // LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $" {ModuleName.Cooling1} has wafer information, while EFEM return empty, manually delete if really no wafer");
  185. // }
  186. //}
  187. //cooling2
  188. //if (waferPresence[5] == '1')
  189. //{
  190. // if (WaferManager.Instance.CheckNoWafer(ModuleName.Cooling2, 0))
  191. // {
  192. // WaferManager.Instance.CreateWafer(ModuleName.Cooling2, 0, WaferStatus.Normal);
  193. // }
  194. //}
  195. //else
  196. //{
  197. // if (WaferManager.Instance.CheckHasWafer(ModuleName.Cooling2, 0))
  198. // {
  199. // LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $" {ModuleName.Cooling2} has wafer information, while EFEM return empty, manually delete if really no wafer");
  200. // }
  201. //}
  202. return true;
  203. }
  204. else if (_efem.Status == RState.Failed||_efem.Status==RState.Timeout)
  205. {
  206. LOG.Write(eEvent.ERR_EFEM_ROBOT, Module, $"Efem StateTrack failed: {_efem.Status}");
  207. return false;
  208. }
  209. else
  210. return false;
  211. }
  212. }
  213. }