EfemPickRoutine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 bool CheckPreCondition()
  73. {
  74. //LoadPort状态判断
  75. if (ModuleHelper.IsLoadPort(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  76. {
  77. if (!_efem[_targetModule].IsLoaded)
  78. {
  79. NotifyError(eEvent.ERR_EFEM_ROBOT, $"LoadPort not load, cannot do the pick action",-1);
  80. return false;
  81. }
  82. }
  83. if (ModuleHelper.IsSRD(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  84. {
  85. _srdModule = Singleton<RouteManager>.Instance.GetModule<SRDEntity>(_targetModule.ToString());
  86. if (!_srdModule.IsHomed)
  87. {
  88. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} is not homed, please home it first",-1);
  89. return false;
  90. }
  91. //判断arm是否在home位置上
  92. JetAxisBase jetAxisBase = DEVICE.GetDevice<JetAxisBase>($"{_targetModule}.Arm");
  93. double position = jetAxisBase.MotionData.MotorPosition;
  94. bool result = jetAxisBase.CheckPositionIsInStation(position, "Home");
  95. if (!result)
  96. {
  97. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} armaxis {position} is not in homed place",-1);
  98. return false;
  99. }
  100. if (_srdModule.IsSrdDoorClosed)
  101. {
  102. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} door closed, can not pick",-1);
  103. return false;
  104. }
  105. if (!_srdModule.IsSrdChuckVacuum)
  106. {
  107. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} Vacuum on, can not pick",-1);
  108. return false;
  109. }
  110. }
  111. if (ModuleHelper.IsPUF(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  112. {
  113. _pufModule = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(_targetModule.ToString());
  114. if (!_pufModule.IsHomed)
  115. {
  116. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} is not homed, please home it first",-1);
  117. return false;
  118. }
  119. if (!_pufModule.IsInRobotStation)
  120. {
  121. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} not in robot station, cannot do the pick action",-1);
  122. return false;
  123. }
  124. }
  125. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand))
  126. {
  127. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand} already has a wafer, cannot do the pick action",-1);
  128. return false;
  129. }
  130. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  131. {
  132. if (ModuleHelper.IsPUF(_targetModule))
  133. {
  134. _targetPufSlot = _targetSlot == 0 ? "SideA" : "SideB";
  135. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target: {_targetModule}.{_targetPufSlot} has no wafer, cannot do the pick action",-1);
  136. }
  137. else
  138. {
  139. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target slot: {_targetModule}.{_targetSlot + 1} has no wafer, cannot do the pick action",-1);
  140. }
  141. return false;
  142. }
  143. if (_moveQueue.Count >= 2)
  144. {
  145. if (!ModuleHelper.IsLoadPort(_targetModule))
  146. {
  147. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Wrong double pick command, target is not loadport",-1);
  148. return false;
  149. }
  150. _hand2 = _hand != Hand.Blade1 ? Hand.Blade1 : Hand.Blade2;
  151. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand2))
  152. {
  153. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand2} already has a wafer, cannot do the double pick action",-1);
  154. return false;
  155. }
  156. _targetSlot2 = _moveQueue.ToArray()[1].SourceSlot;
  157. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot2))
  158. {
  159. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target slot: {_targetModule}.{_targetSlot2 + 1} has no wafer, cannot do the double pick action",-1);
  160. return false;
  161. }
  162. }
  163. return true;
  164. }
  165. public RState Monitor()
  166. {
  167. if(_bDoublePick)
  168. {
  169. Runner.Wait(PickStep.WaitModuleReady, WaitModuleReady)
  170. .Run(PickStep.Picking1, Pick1, Pick1Done, _moveTimeout)
  171. .Run(PickStep.Picking2, Pick2, Pick2Done, _moveTimeout)
  172. .End(PickStep.End, ActionDone);
  173. }
  174. else
  175. {
  176. Runner.Wait(PickStep.WaitModuleReady, WaitModuleReady)
  177. .RunIf(PickStep.PufVacuumOff, ModuleHelper.IsPUF(_targetModule), PufVacuumOff, CheckPufVacuumOff, _delay_2s)
  178. .Run(PickStep.Picking1, Pick1, Pick1Done, _moveTimeout)
  179. .End(PickStep.End, ActionDone);
  180. }
  181. return Runner.Status;
  182. }
  183. /// <summary>
  184. /// Puf关闭真空
  185. /// </summary>
  186. /// <returns></returns>
  187. private bool PufVacuumOff()
  188. {
  189. PufVacuum pufVacuum = DEVICE.GetDevice<PufVacuum>($"{_targetModule}.Vacuum");
  190. if (_targetSlot == 0)
  191. {
  192. return pufVacuum.VacuumAOff();
  193. }
  194. else
  195. {
  196. return pufVacuum.VacuumBOff();
  197. }
  198. }
  199. /// <summary>
  200. /// 检验Puf是否关闭真空
  201. /// </summary>
  202. /// <returns></returns>
  203. private bool CheckPufVacuumOff()
  204. {
  205. PufVacuum pufVacuum = DEVICE.GetDevice<PufVacuum>($"{_targetModule}.Vacuum");
  206. if (_targetSlot == 0)
  207. {
  208. return pufVacuum.IsChuckAReleased;
  209. }
  210. else
  211. {
  212. return pufVacuum.ISChuckBReleased;
  213. }
  214. }
  215. public void Abort()
  216. {
  217. _efem.Halt();
  218. }
  219. private bool WaitModuleReady()
  220. {
  221. return _efem.Status == RState.End;
  222. }
  223. private bool Pick1()
  224. {
  225. return _efem.Pick(_targetModule, _targetSlot, _hand);
  226. }
  227. private bool Pick1Done()
  228. {
  229. if (_efem.Status == RState.End)
  230. {
  231. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.EfemRobot, (int)_hand);
  232. return true;
  233. }
  234. else if (_efem.Status == RState.Failed)
  235. {
  236. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot picking failed: {_efem.Status}",-1);
  237. return true;
  238. }
  239. return false;
  240. }
  241. private bool Pick2()
  242. {
  243. return _efem.Pick(_targetModule, _targetSlot2, _hand2);
  244. }
  245. private bool Pick2Done()
  246. {
  247. if (_efem.Status == RState.End)
  248. {
  249. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot2, ModuleName.EfemRobot, (int)_hand2);
  250. return true;
  251. }
  252. else if (_efem.Status == RState.Failed)
  253. {
  254. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot picking 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(PickStep.PufVacuumOff, preStepIds);
  276. return Runner.Retry(PickStep.PufVacuumOff, preStepIds, Module, "Pick Retry");
  277. }
  278. /// <summary>
  279. /// 忽略前
  280. /// </summary>
  281. /// <param name="step"></param>
  282. /// <param name="preStepIds"></param>
  283. private void AddPreSteps(PickStep step, List<Enum> preStepIds)
  284. {
  285. for (int i = 0; i < (int)step; i++)
  286. {
  287. preStepIds.Add((PickStep)i);
  288. }
  289. }
  290. /// <summary>
  291. /// 检验前面完成状态
  292. /// </summary>
  293. /// <returns></returns>
  294. public bool CheckCompleteCondition(int index)
  295. {
  296. if (WaferManager.Instance.CheckNoWafer(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.CheckHasWafer(_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. }