EfemPlaceRoutine.cs 12 KB

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