EfemPlaceRoutine.cs 14 KB

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