EfemPlaceRoutine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. //LoadPort状态判断
  78. if (ModuleHelper.IsLoadPort(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  79. {
  80. Loadport loadPort = GetLoadPort(_targetModule);
  81. if (loadPort == null)
  82. {
  83. return false;
  84. }
  85. if (!loadPort.IsLoaded)
  86. {
  87. NotifyError(eEvent.ERR_EFEM_ROBOT, $"LoadPort not load, cannot do the pick action", -1);
  88. return false;
  89. }
  90. }
  91. if (ModuleHelper.IsSRD(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  92. {
  93. _srdModule = Singleton<RouteManager>.Instance.GetModule<SRDEntity>(_targetModule.ToString());
  94. if (!_srdModule.IsHomed)
  95. {
  96. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} is not homed, please home it first",-1);
  97. return false;
  98. }
  99. //判断arm是否在home位置上
  100. //JetAxisBase jetAxisBase = DEVICE.GetDevice<JetAxisBase>($"{_targetModule}.Arm");
  101. //double position = jetAxisBase.MotionData.MotorPosition;
  102. //bool result = jetAxisBase.CheckPositionIsInStation(position, "Home");
  103. //if (!result)
  104. //{
  105. // NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} armaxis {position} is not in homed place",-1);
  106. // return false;
  107. //}
  108. if (_srdModule.IsSrdDoorClosed)
  109. {
  110. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} door closed, can not place",-1);
  111. return false;
  112. }
  113. }
  114. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand))
  115. {
  116. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand} already has no wafer, cannot do the place action",-1);
  117. return false;
  118. }
  119. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  120. {
  121. if (ModuleHelper.IsPUF(_targetModule))
  122. {
  123. _targetPufSlot = _targetSlot == 0 ? "SideA" : "SideB";
  124. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target: {_targetModule}.{_targetPufSlot} has a wafer, cannot do the place action",-1);
  125. }
  126. else
  127. {
  128. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target: {_targetModule}.{_targetSlot + 1} has a wafer, cannot do the place action",-1);
  129. }
  130. return false;
  131. }
  132. if (_moveItems.Count >= 2)
  133. {
  134. if (!ModuleHelper.IsLoadPort(_targetModule))
  135. {
  136. NotifyError(eEvent.ERR_EFEM_ROBOT,$"Wrong double place command, target is not loadport",-1);
  137. return false;
  138. }
  139. _hand2 = _hand != Hand.Blade1 ? Hand.Blade1 : Hand.Blade2;
  140. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand2))
  141. {
  142. NotifyError(eEvent.ERR_EFEM_ROBOT,$"Efem robot arm{_hand2} has no wafer, cannot do the double place action",-1);
  143. return false;
  144. }
  145. _targetSlot2 = _moveItems.ToArray()[1].DestinationSlot;
  146. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot2))
  147. {
  148. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target: {_targetModule}.{_targetSlot2 + 1} has a wafer, cannot do the double pick action",-1);
  149. return false;
  150. }
  151. }
  152. return true;
  153. }
  154. public RState Monitor()
  155. {
  156. if (_bDoublePlace)
  157. {
  158. Runner.WaitIf(PlaceStep.WaitIdle,_isAligner,WaitModuleReady)
  159. .RunIf(PlaceStep.SetAlignWaferSize,_isAligner,SetAlignerWaferSize, CheckAlignDone, _delay_5s)
  160. .Wait(PlaceStep.WaitWaferSizeIdle, WaitModuleReady)
  161. .RunIf(PlaceStep.SetAlignDistance, _isAligner, SetAlignerDistance,CheckAlignDone, _delay_5s)
  162. .Wait(PlaceStep.WaitAlignDistanceIdle, WaitModuleReady)
  163. .Wait(PlaceStep.WaitModuleReady, WaitModuleReady)
  164. .Run(PlaceStep.Placing1, Place1, Place1Done, _moveTimeout)
  165. .Run(PlaceStep.Placing2, Place2, Place2Done, _moveTimeout)
  166. .End(PlaceStep.End, ActionDone);
  167. }
  168. else
  169. {
  170. Runner.WaitIf(PlaceStep.WaitIdle, _isAligner, WaitModuleReady)
  171. .RunIf(PlaceStep.SetAlignWaferSize, _isAligner, SetAlignerWaferSize, _delay_1ms)
  172. .Wait(PlaceStep.WaitWaferSizeIdle, WaitModuleReady)
  173. .RunIf(PlaceStep.SetAlignDistance, _isAligner, SetAlignerDistance, _delay_1ms)
  174. .Wait(PlaceStep.WaitAlignDistanceIdle, WaitModuleReady)
  175. .Wait(PlaceStep.WaitModuleReady, WaitModuleReady)
  176. .Run(PlaceStep.Placing1, Place1, Place1Done, _moveTimeout)
  177. .End(PlaceStep.End, ActionDone);
  178. }
  179. return Runner.Status;
  180. }
  181. private bool SetAlignerWaferSize()
  182. {
  183. return _efem.SetAlignWaferSize();
  184. }
  185. private bool SetAlignerDistance()
  186. {
  187. return _efem.SetAlignDistance();
  188. }
  189. public void Abort()
  190. {
  191. _efem.Halt();
  192. }
  193. private bool WaitModuleReady()
  194. {
  195. return _efem.Status == RState.End;
  196. }
  197. private bool Place1()
  198. {
  199. return _efem.Place(_targetModule, _targetSlot, _hand, _flip);
  200. }
  201. private bool Place1Done()
  202. {
  203. if (_efem.Status == RState.End)
  204. {
  205. WaferManager.Instance.WaferMoved(ModuleName.EfemRobot, (int)_hand, _targetModule, _targetSlot);
  206. return true;
  207. }
  208. else if (_efem.Status == RState.Failed)
  209. {
  210. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot place failed: {_efem.Status}",-1);
  211. return true;
  212. }
  213. return false;
  214. }
  215. private bool CheckAlignDone()
  216. {
  217. if (_efem.Status == RState.End)
  218. {
  219. return true;
  220. }
  221. else if (_efem.Status == RState.Failed)
  222. {
  223. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, Module, $"Efem PreAligner align failed: {_efem.Status}");
  224. return true;
  225. }
  226. return false;
  227. }
  228. private bool Place2()
  229. {
  230. return _efem.Place(_targetModule, _targetSlot2, _hand2, _flip);
  231. }
  232. private bool Place2Done()
  233. {
  234. if (_efem.Status == RState.End)
  235. {
  236. WaferManager.Instance.WaferMoved(ModuleName.EfemRobot, (int)_hand2, _targetModule, _targetSlot2);
  237. return true;
  238. }
  239. else if (_efem.Status == RState.Failed)
  240. {
  241. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot place failed: {_efem.Status}",-1);
  242. return true;
  243. }
  244. return false;
  245. }
  246. private bool ActionDone()
  247. {
  248. return true;
  249. }
  250. /// <summary>
  251. /// 重试
  252. /// </summary>
  253. /// <param name="step"></param>
  254. public RState Retry(int step)
  255. {
  256. if (!CheckPreCondition())
  257. {
  258. return RState.Failed;
  259. }
  260. _efem.Reset();
  261. List<Enum> preStepIds = new List<Enum>();
  262. AddPreSteps(PlaceStep.SetAlignWaferSize, preStepIds);
  263. return Runner.Retry(PlaceStep.SetAlignWaferSize, preStepIds, Module, "Place Retry");
  264. }
  265. /// <summary>
  266. /// 忽略前
  267. /// </summary>
  268. /// <param name="step"></param>
  269. /// <param name="preStepIds"></param>
  270. private void AddPreSteps(PlaceStep step, List<Enum> preStepIds)
  271. {
  272. for (int i = 0; i < (int)step; i++)
  273. {
  274. preStepIds.Add((PlaceStep)i);
  275. }
  276. }
  277. /// <summary>
  278. /// 检验前面完成状态
  279. /// </summary>
  280. /// <returns></returns>
  281. public bool CheckCompleteCondition(int index)
  282. {
  283. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand))
  284. {
  285. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand} has no wafer", -1);
  286. return false;
  287. }
  288. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  289. {
  290. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} Slot{_targetSlot} has no wafer", -1);
  291. return false;
  292. }
  293. return true;
  294. }
  295. }
  296. }