EfemPlaceRoutine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. using Aitex.Core.RT.Routine;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Sorter.Common;
  4. using PunkHPX8_RT.Devices;
  5. using MECF.Framework.Common.Routine;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.SubstrateTrackings;
  8. using PunkHPX8_Core;
  9. using Aitex.Core.RT.Log;
  10. using Aitex.Core.Util;
  11. using MECF.Framework.Common.Schedulers;
  12. using System.Collections.Generic;
  13. using PunkHPX8_RT.Devices.EFEM;
  14. using PunkHPX8_RT.Modules.SRD;
  15. using PunkHPX8_RT.Devices.AXIS;
  16. using Aitex.Core.RT.Device;
  17. using MECF.Framework.Common.Utilities;
  18. using System;
  19. using PunkHPX8_RT.Modules.LPs;
  20. using PunkHPX8_RT.Modules.VpwMain;
  21. namespace PunkHPX8_RT.Modules.EFEM
  22. {
  23. class EfemPlaceRoutine : RoutineBase, IRoutine
  24. {
  25. private enum PlaceStep
  26. {
  27. WaitIdle,
  28. SetAlignWaferSize,
  29. WaitWaferSizeIdle,
  30. SetAlignDistance,
  31. WaitAlignDistanceIdle,
  32. WaitModuleReady,
  33. Placing1,
  34. Placing2,
  35. End,
  36. }
  37. private int _moveTimeout = 20 * 1000;
  38. private ModuleName _targetModule = ModuleName.System;
  39. int _targetSlot;
  40. string _targetPufSlot;
  41. int _targetSlot2;
  42. Hand _hand;
  43. Hand _hand2;
  44. Flip _flip;
  45. EfemBase _efem;
  46. bool _bDoublePlace = false;
  47. private SRDEntity _srdModule;
  48. private Queue<MoveItem> _moveItems;
  49. private bool _isAligner;
  50. public EfemPlaceRoutine(EfemBase efem) : base(ModuleName.EfemRobot.ToString())
  51. {
  52. _efem = efem;
  53. }
  54. public RState Start(params object[] objs)
  55. {
  56. _bDoublePlace = false;
  57. _moveItems = (Queue<MoveItem>)objs[0];
  58. MoveItem moveItem = _moveItems.Peek();
  59. _targetModule = moveItem.DestinationModule;
  60. _targetSlot = moveItem.DestinationSlot;
  61. _hand = moveItem.RobotHand;
  62. _flip = moveItem.PlaceRobotFlip;
  63. if (!CheckPreCondition())
  64. {
  65. return RState.Failed;
  66. }
  67. _isAligner = ModuleHelper.IsAligner(_targetModule);
  68. _moveTimeout = SC.GetValue<int>($"EFEM.MotionTimeout") * 1000;
  69. return Runner.Start(Module, $"Place to {_targetModule}");
  70. }
  71. private Loadport GetLoadPort(ModuleName station)
  72. {
  73. LoadPortModule loadPortModule = Singleton<RouteManager>.Instance.EFEM.GetLoadportModule(station - ModuleName.LP1);
  74. return loadPortModule.LPDevice;
  75. }
  76. private bool CheckPreCondition()
  77. {
  78. if (ModuleHelper.IsAligner(_targetModule) || ModuleHelper.IsLoadPort(_targetModule))
  79. {
  80. if (_hand == Hand.Blade2)
  81. {
  82. NotifyError(eEvent.ERR_EFEM_ROBOT, $"cannot use upper arm to place to {_targetModule}", -1);
  83. return false;
  84. }
  85. }
  86. if (ModuleHelper.IsPlatingCell(_targetModule))
  87. {
  88. if (_hand == Hand.Blade1)
  89. {
  90. NotifyError(eEvent.ERR_EFEM_ROBOT, $"cannot use lower arm to place to {_targetModule}", -1);
  91. return false;
  92. }
  93. }
  94. if (_hand == Hand.Blade1 && _flip == Flip.Down)
  95. {
  96. NotifyError(eEvent.ERR_EFEM_ROBOT, $"lower arm cannot flip", -1);
  97. return false;
  98. }
  99. //LoadPort状态判断
  100. if (ModuleHelper.IsLoadPort(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  101. {
  102. Loadport loadPort = GetLoadPort(_targetModule);
  103. if (loadPort == null)
  104. {
  105. return false;
  106. }
  107. if (!loadPort.IsLoaded)
  108. {
  109. NotifyError(eEvent.ERR_EFEM_ROBOT, $"LoadPort not load, cannot do the pick action", -1);
  110. return false;
  111. }
  112. }
  113. if (ModuleHelper.IsSRD(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  114. {
  115. _srdModule = Singleton<RouteManager>.Instance.GetModule<SRDEntity>(_targetModule.ToString());
  116. if (!_srdModule.IsHomed)
  117. {
  118. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} is not homed, please home it first",-1);
  119. return false;
  120. }
  121. if (_srdModule.IsSrdDoorClosed)
  122. {
  123. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} door closed, can not place",-1);
  124. return false;
  125. }
  126. }
  127. if (ModuleHelper.IsVPWCell(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  128. {
  129. VpwMainEntity vpwMainEntity = Singleton<RouteManager>.Instance.GetModule<VpwMainEntity>(ModuleName.VPWMain1.ToString());
  130. if (vpwMainEntity.IsChamberClosed)
  131. {
  132. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} door closed, can not place", -1);
  133. return false;
  134. }
  135. }
  136. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand))
  137. {
  138. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand} already has no wafer, cannot do the place action",-1);
  139. return false;
  140. }
  141. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  142. {
  143. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target: {_targetModule}.{_targetSlot + 1} has a wafer, cannot do the place action",-1);
  144. return false;
  145. }
  146. if (_moveItems.Count >= 2)
  147. {
  148. if (!ModuleHelper.IsLoadPort(_targetModule))
  149. {
  150. NotifyError(eEvent.ERR_EFEM_ROBOT,$"Wrong double place command, target is not loadport",-1);
  151. return false;
  152. }
  153. _hand2 = _hand != Hand.Blade1 ? Hand.Blade1 : Hand.Blade2;
  154. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand2))
  155. {
  156. NotifyError(eEvent.ERR_EFEM_ROBOT,$"Efem robot arm{_hand2} has no wafer, cannot do the double place action",-1);
  157. return false;
  158. }
  159. _targetSlot2 = _moveItems.ToArray()[1].DestinationSlot;
  160. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot2))
  161. {
  162. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target: {_targetModule}.{_targetSlot2 + 1} has a wafer, cannot do the double pick action",-1);
  163. return false;
  164. }
  165. }
  166. return true;
  167. }
  168. public RState Monitor()
  169. {
  170. if (_bDoublePlace)
  171. {
  172. Runner.WaitIf(PlaceStep.WaitIdle,_isAligner,WaitModuleReady)
  173. .RunIf(PlaceStep.SetAlignWaferSize,_isAligner,SetAlignerWaferSize, CheckAlignDone, _delay_5s)
  174. .Wait(PlaceStep.WaitWaferSizeIdle, WaitModuleReady)
  175. .RunIf(PlaceStep.SetAlignDistance, _isAligner, SetAlignerDistance,CheckAlignDone, _delay_5s)
  176. .Wait(PlaceStep.WaitAlignDistanceIdle, WaitModuleReady)
  177. .Wait(PlaceStep.WaitModuleReady, WaitModuleReady)
  178. .Run(PlaceStep.Placing1, Place1, Place1Done, _moveTimeout)
  179. .Run(PlaceStep.Placing2, Place2, Place2Done, _moveTimeout)
  180. .End(PlaceStep.End, ActionDone);
  181. }
  182. else
  183. {
  184. Runner.WaitIf(PlaceStep.WaitIdle, _isAligner, WaitModuleReady)
  185. .RunIf(PlaceStep.SetAlignWaferSize, _isAligner, SetAlignerWaferSize, _delay_1ms)
  186. .Wait(PlaceStep.WaitWaferSizeIdle, WaitModuleReady)
  187. .RunIf(PlaceStep.SetAlignDistance, _isAligner, SetAlignerDistance, _delay_1ms)
  188. .Wait(PlaceStep.WaitAlignDistanceIdle, WaitModuleReady)
  189. .Wait(PlaceStep.WaitModuleReady, WaitModuleReady)
  190. .Run(PlaceStep.Placing1, Place1, Place1Done, _moveTimeout)
  191. .End(PlaceStep.End, ActionDone);
  192. }
  193. return Runner.Status;
  194. }
  195. private bool SetAlignerWaferSize()
  196. {
  197. return _efem.SetAlignWaferSize();
  198. }
  199. private bool SetAlignerDistance()
  200. {
  201. return _efem.SetAlignDistance();
  202. }
  203. public void Abort()
  204. {
  205. _efem.Halt();
  206. }
  207. private bool WaitModuleReady()
  208. {
  209. if (_efem.IsInPauseStatus)
  210. {
  211. return false;
  212. }
  213. return _efem.Status == RState.End;
  214. }
  215. private bool Place1()
  216. {
  217. return _efem.Place(_targetModule, _targetSlot, _hand, _flip);
  218. }
  219. private bool Place1Done()
  220. {
  221. if (_efem.Status == RState.End)
  222. {
  223. WaferManager.Instance.WaferMoved(ModuleName.EfemRobot, (int)_hand, _targetModule, _targetSlot);
  224. return true;
  225. }
  226. else if (_efem.Status == RState.Failed)
  227. {
  228. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot place failed: {_efem.Status}",-1);
  229. return true;
  230. }
  231. return false;
  232. }
  233. private bool CheckAlignDone()
  234. {
  235. if (_efem.Status == RState.End)
  236. {
  237. return true;
  238. }
  239. else if (_efem.Status == RState.Failed)
  240. {
  241. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, Module, $"Efem PreAligner align failed: {_efem.Status}");
  242. return true;
  243. }
  244. return false;
  245. }
  246. private bool Place2()
  247. {
  248. return _efem.Place(_targetModule, _targetSlot2, _hand2, _flip);
  249. }
  250. private bool Place2Done()
  251. {
  252. if (_efem.Status == RState.End)
  253. {
  254. WaferManager.Instance.WaferMoved(ModuleName.EfemRobot, (int)_hand2, _targetModule, _targetSlot2);
  255. return true;
  256. }
  257. else if (_efem.Status == RState.Failed)
  258. {
  259. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot place failed: {_efem.Status}",-1);
  260. return true;
  261. }
  262. return false;
  263. }
  264. private bool ActionDone()
  265. {
  266. return true;
  267. }
  268. /// <summary>
  269. /// 重试
  270. /// </summary>
  271. /// <param name="step"></param>
  272. public RState Retry(int step)
  273. {
  274. if (!CheckPreCondition())
  275. {
  276. return RState.Failed;
  277. }
  278. _efem.Reset();
  279. List<Enum> preStepIds = new List<Enum>();
  280. AddPreSteps(PlaceStep.SetAlignWaferSize, preStepIds);
  281. return Runner.Retry(PlaceStep.SetAlignWaferSize, preStepIds, Module, "Place Retry");
  282. }
  283. /// <summary>
  284. /// 忽略前
  285. /// </summary>
  286. /// <param name="step"></param>
  287. /// <param name="preStepIds"></param>
  288. private void AddPreSteps(PlaceStep step, List<Enum> preStepIds)
  289. {
  290. for (int i = 0; i < (int)step; i++)
  291. {
  292. preStepIds.Add((PlaceStep)i);
  293. }
  294. }
  295. /// <summary>
  296. /// 检验前面完成状态
  297. /// </summary>
  298. /// <returns></returns>
  299. public bool CheckCompleteCondition(int index)
  300. {
  301. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand))
  302. {
  303. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand} has no wafer", -1);
  304. return false;
  305. }
  306. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  307. {
  308. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} Slot{_targetSlot} has no wafer", -1);
  309. return false;
  310. }
  311. return true;
  312. }
  313. }
  314. }