EfemPlaceRoutine.cs 10.0 KB

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