EfemPlaceRoutine.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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.RobotFlip;
  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.Upper)
  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. return _efem.Status == RState.End;
  217. }
  218. private bool Place1()
  219. {
  220. return _efem.Place(_targetModule, _targetSlot, _hand, _flip);
  221. }
  222. private bool Place1Done()
  223. {
  224. if (_efem.Status == RState.End)
  225. {
  226. WaferManager.Instance.WaferMoved(ModuleName.EfemRobot, (int)_hand, _targetModule, _targetSlot);
  227. return true;
  228. }
  229. else if (_efem.Status == RState.Failed)
  230. {
  231. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot place failed: {_efem.Status}",-1);
  232. return true;
  233. }
  234. return false;
  235. }
  236. private bool CheckAlignDone()
  237. {
  238. if (_efem.Status == RState.End)
  239. {
  240. return true;
  241. }
  242. else if (_efem.Status == RState.Failed)
  243. {
  244. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, Module, $"Efem PreAligner align failed: {_efem.Status}");
  245. return true;
  246. }
  247. return false;
  248. }
  249. private bool Place2()
  250. {
  251. return _efem.Place(_targetModule, _targetSlot2, _hand2, _flip);
  252. }
  253. private bool Place2Done()
  254. {
  255. if (_efem.Status == RState.End)
  256. {
  257. WaferManager.Instance.WaferMoved(ModuleName.EfemRobot, (int)_hand2, _targetModule, _targetSlot2);
  258. return true;
  259. }
  260. else if (_efem.Status == RState.Failed)
  261. {
  262. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot place failed: {_efem.Status}",-1);
  263. return true;
  264. }
  265. return false;
  266. }
  267. private bool ActionDone()
  268. {
  269. return true;
  270. }
  271. /// <summary>
  272. /// 重试
  273. /// </summary>
  274. /// <param name="step"></param>
  275. public RState Retry(int step)
  276. {
  277. if (!CheckPreCondition())
  278. {
  279. return RState.Failed;
  280. }
  281. _efem.Reset();
  282. List<Enum> preStepIds = new List<Enum>();
  283. AddPreSteps(PlaceStep.SetAlignWaferSize, preStepIds);
  284. return Runner.Retry(PlaceStep.SetAlignWaferSize, preStepIds, Module, "Place Retry");
  285. }
  286. /// <summary>
  287. /// 忽略前
  288. /// </summary>
  289. /// <param name="step"></param>
  290. /// <param name="preStepIds"></param>
  291. private void AddPreSteps(PlaceStep step, List<Enum> preStepIds)
  292. {
  293. for (int i = 0; i < (int)step; i++)
  294. {
  295. preStepIds.Add((PlaceStep)i);
  296. }
  297. }
  298. /// <summary>
  299. /// 检验前面完成状态
  300. /// </summary>
  301. /// <returns></returns>
  302. public bool CheckCompleteCondition(int index)
  303. {
  304. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand))
  305. {
  306. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand} has no wafer", -1);
  307. return false;
  308. }
  309. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  310. {
  311. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} Slot{_targetSlot} has no wafer", -1);
  312. return false;
  313. }
  314. return true;
  315. }
  316. }
  317. }