EfemPlaceRoutine.cs 12 KB

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