EfemPickRoutine.cs 12 KB

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