EfemPickRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. EfemBase _efem;
  44. bool _bDoublePick = false;
  45. private SRDEntity _srdModule;
  46. private Queue<MoveItem> _moveQueue;
  47. public EfemPickRoutine(EfemBase efem) : base(ModuleName.EfemRobot.ToString())
  48. {
  49. _efem = efem;
  50. }
  51. public RState Start(params object[] objs)
  52. {
  53. _bDoublePick = false;
  54. _moveQueue = (Queue<MoveItem>)objs[0];
  55. _targetModule = _moveQueue.Peek().SourceModule;
  56. _targetSlot = _moveQueue.Peek().SourceSlot;
  57. _hand = _moveQueue.Peek().RobotHand;
  58. if(_moveQueue.Count >= 2)
  59. {
  60. _bDoublePick = true;
  61. }
  62. if (!CheckPreCondition())
  63. {
  64. return RState.Failed;
  65. }
  66. _moveTimeout = SC.GetValue<int>($"EFEM.MotionTimeout") * 1000;
  67. return Runner.Start(Module, $"Pick from {_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 pick",-1);
  110. return false;
  111. }
  112. if (!_srdModule.IsSrdChuckVacuum)
  113. {
  114. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} Vacuum on, can not pick",-1);
  115. return false;
  116. }
  117. }
  118. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand))
  119. {
  120. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand} already has a wafer, cannot do the pick action",-1);
  121. return false;
  122. }
  123. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  124. {
  125. if (ModuleHelper.IsPUF(_targetModule))
  126. {
  127. _targetPufSlot = _targetSlot == 0 ? "SideA" : "SideB";
  128. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target: {_targetModule}.{_targetPufSlot} has no wafer, cannot do the pick action",-1);
  129. }
  130. else
  131. {
  132. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target slot: {_targetModule}.{_targetSlot + 1} has no wafer, cannot do the pick action",-1);
  133. }
  134. return false;
  135. }
  136. else
  137. {
  138. WaferInfo waferInfo = WaferManager.Instance.GetWafer(_targetModule, _targetSlot);
  139. if(waferInfo.Status!=WaferStatus.Normal)
  140. {
  141. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target slot: {_targetModule}.{_targetSlot + 1} wafer status is {waferInfo.Status}, cannot do the pick action", -1);
  142. return false;
  143. }
  144. }
  145. if (_moveQueue.Count >= 2)
  146. {
  147. if (!ModuleHelper.IsLoadPort(_targetModule))
  148. {
  149. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Wrong double pick command, target is not loadport",-1);
  150. return false;
  151. }
  152. _hand2 = _hand != Hand.Blade1 ? Hand.Blade1 : Hand.Blade2;
  153. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand2))
  154. {
  155. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand2} already has a wafer, cannot do the double pick action",-1);
  156. return false;
  157. }
  158. _targetSlot2 = _moveQueue.ToArray()[1].SourceSlot;
  159. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot2))
  160. {
  161. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target slot: {_targetModule}.{_targetSlot2 + 1} has no wafer, cannot do the double pick action",-1);
  162. return false;
  163. }
  164. }
  165. return true;
  166. }
  167. public RState Monitor()
  168. {
  169. if(_bDoublePick)
  170. {
  171. Runner.Wait(PickStep.WaitModuleReady, WaitModuleReady)
  172. .Run(PickStep.Picking1, Pick1, Pick1Done, _moveTimeout)
  173. .Run(PickStep.Picking2, Pick2, Pick2Done, _moveTimeout)
  174. .End(PickStep.End, ActionDone);
  175. }
  176. else
  177. {
  178. Runner.Wait(PickStep.WaitModuleReady, WaitModuleReady)
  179. .Run(PickStep.Picking1, Pick1, Pick1Done, _moveTimeout)
  180. .End(PickStep.End, ActionDone);
  181. }
  182. return Runner.Status;
  183. }
  184. public void Abort()
  185. {
  186. _efem.Halt();
  187. }
  188. private bool WaitModuleReady()
  189. {
  190. return _efem.Status == RState.End;
  191. }
  192. private bool Pick1()
  193. {
  194. return _efem.Pick(_targetModule, _targetSlot, _hand);
  195. }
  196. private bool Pick1Done()
  197. {
  198. if (_efem.Status == RState.End)
  199. {
  200. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.EfemRobot, (int)_hand);
  201. return true;
  202. }
  203. else if (_efem.Status == RState.Failed)
  204. {
  205. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot picking failed: {_efem.Status}",-1);
  206. return true;
  207. }
  208. return false;
  209. }
  210. private bool Pick2()
  211. {
  212. return _efem.Pick(_targetModule, _targetSlot2, _hand2);
  213. }
  214. private bool Pick2Done()
  215. {
  216. if (_efem.Status == RState.End)
  217. {
  218. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot2, ModuleName.EfemRobot, (int)_hand2);
  219. return true;
  220. }
  221. else if (_efem.Status == RState.Failed)
  222. {
  223. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot picking failed: {_efem.Status}",-1);
  224. return true;
  225. }
  226. return false;
  227. }
  228. private bool ActionDone()
  229. {
  230. return true;
  231. }
  232. /// <summary>
  233. /// 重试
  234. /// </summary>
  235. /// <param name="step"></param>
  236. public RState Retry(int step)
  237. {
  238. if(!CheckPreCondition())
  239. {
  240. return RState.Failed;
  241. }
  242. _efem.Reset();
  243. List<Enum> preStepIds = new List<Enum>();
  244. AddPreSteps(PickStep.PufVacuumOff, preStepIds);
  245. return Runner.Retry(PickStep.PufVacuumOff, preStepIds, Module, "Pick Retry");
  246. }
  247. /// <summary>
  248. /// 忽略前
  249. /// </summary>
  250. /// <param name="step"></param>
  251. /// <param name="preStepIds"></param>
  252. private void AddPreSteps(PickStep step, List<Enum> preStepIds)
  253. {
  254. for (int i = 0; i < (int)step; i++)
  255. {
  256. preStepIds.Add((PickStep)i);
  257. }
  258. }
  259. /// <summary>
  260. /// 检验前面完成状态
  261. /// </summary>
  262. /// <returns></returns>
  263. public bool CheckCompleteCondition(int index)
  264. {
  265. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand))
  266. {
  267. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand} has no wafer", -1);
  268. return false;
  269. }
  270. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  271. {
  272. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} Slot{_targetSlot} has no wafer", -1);
  273. return false;
  274. }
  275. return true;
  276. }
  277. }
  278. }