EfemPickRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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.LPs;
  15. using PunkHPX8_RT.Modules.SRD;
  16. using System.Runtime.InteropServices;
  17. using Aitex.Core.RT.Device;
  18. using PunkHPX8_RT.Devices.AXIS;
  19. using MECF.Framework.Common.Utilities;
  20. using PunkHPX8_RT.Modules.Transporter;
  21. using System;
  22. using Aitex.Core.UI.ControlDataContext;
  23. using Aitex.Core.Common;
  24. namespace PunkHPX8_RT.Modules.EFEM
  25. {
  26. class EfemPickRoutine : RoutineBase, IRoutine
  27. {
  28. private enum PickStep
  29. {
  30. WaitModuleReady,
  31. PufVacuumOff,
  32. Picking1,
  33. Picking2,
  34. End,
  35. }
  36. private int _moveTimeout = 20 * 1000;
  37. private ModuleName _targetModule = ModuleName.System;
  38. int _targetSlot;
  39. int _targetSlot2;
  40. string _targetPufSlot;
  41. Hand _hand;
  42. Hand _hand2;
  43. Flip _flip;
  44. EfemBase _efem;
  45. bool _bDoublePick = false;
  46. private SRDEntity _srdModule;
  47. private Queue<MoveItem> _moveQueue;
  48. public EfemPickRoutine(EfemBase efem) : base(ModuleName.EfemRobot.ToString())
  49. {
  50. _efem = efem;
  51. }
  52. public RState Start(params object[] objs)
  53. {
  54. _bDoublePick = false;
  55. _moveQueue = (Queue<MoveItem>)objs[0];
  56. MoveItem moveItem = _moveQueue.Peek();
  57. _targetModule = moveItem.SourceModule;
  58. _targetSlot = moveItem.SourceSlot;
  59. _hand = moveItem.RobotHand;
  60. _flip = moveItem.RobotFlip;
  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 (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand))
  122. {
  123. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand} already has a wafer, cannot do the pick action",-1);
  124. return false;
  125. }
  126. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  127. {
  128. if (ModuleHelper.IsPUF(_targetModule))
  129. {
  130. _targetPufSlot = _targetSlot == 0 ? "SideA" : "SideB";
  131. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target: {_targetModule}.{_targetPufSlot} has no wafer, cannot do the pick action",-1);
  132. }
  133. else
  134. {
  135. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target slot: {_targetModule}.{_targetSlot + 1} has no wafer, cannot do the pick action",-1);
  136. }
  137. return false;
  138. }
  139. else
  140. {
  141. WaferInfo waferInfo = WaferManager.Instance.GetWafer(_targetModule, _targetSlot);
  142. if(waferInfo.Status!=WaferStatus.Normal)
  143. {
  144. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target slot: {_targetModule}.{_targetSlot + 1} wafer status is {waferInfo.Status}, cannot do the pick action", -1);
  145. return false;
  146. }
  147. }
  148. if (_moveQueue.Count >= 2)
  149. {
  150. if (!ModuleHelper.IsLoadPort(_targetModule))
  151. {
  152. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Wrong double pick command, target is not loadport",-1);
  153. return false;
  154. }
  155. _hand2 = _hand != Hand.Blade1 ? Hand.Blade1 : Hand.Blade2;
  156. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand2))
  157. {
  158. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand2} already has a wafer, cannot do the double pick action",-1);
  159. return false;
  160. }
  161. _targetSlot2 = _moveQueue.ToArray()[1].SourceSlot;
  162. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot2))
  163. {
  164. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target slot: {_targetModule}.{_targetSlot2 + 1} has no wafer, cannot do the double pick action",-1);
  165. return false;
  166. }
  167. }
  168. return true;
  169. }
  170. public RState Monitor()
  171. {
  172. if(_bDoublePick)
  173. {
  174. Runner.Wait(PickStep.WaitModuleReady, WaitModuleReady)
  175. .Run(PickStep.Picking1, Pick1, Pick1Done, _moveTimeout)
  176. .Run(PickStep.Picking2, Pick2, Pick2Done, _moveTimeout)
  177. .End(PickStep.End, ActionDone);
  178. }
  179. else
  180. {
  181. Runner.Wait(PickStep.WaitModuleReady, WaitModuleReady)
  182. .Run(PickStep.Picking1, Pick1, Pick1Done, _moveTimeout)
  183. .End(PickStep.End, ActionDone);
  184. }
  185. return Runner.Status;
  186. }
  187. public void Abort()
  188. {
  189. _efem.Halt();
  190. }
  191. private bool WaitModuleReady()
  192. {
  193. return _efem.Status == RState.End;
  194. }
  195. private bool Pick1()
  196. {
  197. return _efem.Pick(_targetModule, _targetSlot, _hand,_flip);
  198. }
  199. private bool Pick1Done()
  200. {
  201. if (_efem.Status == RState.End)
  202. {
  203. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.EfemRobot, (int)_hand);
  204. return true;
  205. }
  206. else if (_efem.Status == RState.Failed)
  207. {
  208. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot picking failed: {_efem.Status}",-1);
  209. return true;
  210. }
  211. return false;
  212. }
  213. private bool Pick2()
  214. {
  215. return _efem.Pick(_targetModule, _targetSlot2, _hand2, _flip);
  216. }
  217. private bool Pick2Done()
  218. {
  219. if (_efem.Status == RState.End)
  220. {
  221. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot2, ModuleName.EfemRobot, (int)_hand2);
  222. return true;
  223. }
  224. else if (_efem.Status == RState.Failed)
  225. {
  226. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot picking failed: {_efem.Status}",-1);
  227. return true;
  228. }
  229. return false;
  230. }
  231. private bool ActionDone()
  232. {
  233. return true;
  234. }
  235. /// <summary>
  236. /// 重试
  237. /// </summary>
  238. /// <param name="step"></param>
  239. public RState Retry(int step)
  240. {
  241. if(!CheckPreCondition())
  242. {
  243. return RState.Failed;
  244. }
  245. _efem.Reset();
  246. List<Enum> preStepIds = new List<Enum>();
  247. AddPreSteps(PickStep.PufVacuumOff, preStepIds);
  248. return Runner.Retry(PickStep.PufVacuumOff, preStepIds, Module, "Pick Retry");
  249. }
  250. /// <summary>
  251. /// 忽略前
  252. /// </summary>
  253. /// <param name="step"></param>
  254. /// <param name="preStepIds"></param>
  255. private void AddPreSteps(PickStep step, List<Enum> preStepIds)
  256. {
  257. for (int i = 0; i < (int)step; i++)
  258. {
  259. preStepIds.Add((PickStep)i);
  260. }
  261. }
  262. /// <summary>
  263. /// 检验前面完成状态
  264. /// </summary>
  265. /// <returns></returns>
  266. public bool CheckCompleteCondition(int index)
  267. {
  268. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand))
  269. {
  270. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand} has no wafer", -1);
  271. return false;
  272. }
  273. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  274. {
  275. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} Slot{_targetSlot} has no wafer", -1);
  276. return false;
  277. }
  278. return true;
  279. }
  280. }
  281. }