EfemPlaceRoutine.cs 13 KB

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