EfemPickRoutine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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.IsDummy(_targetModule)||ModuleHelper.IsAligner(_targetModule)|| ModuleHelper.IsLoadPort(_targetModule))
  94. {
  95. if (_hand == Hand.Blade2)
  96. {
  97. NotifyError(eEvent.ERR_EFEM_ROBOT, $"cannot use upper arm to pick from {_targetModule}", -1);
  98. return false;
  99. }
  100. }
  101. if (ModuleHelper.IsPlatingCell(_targetModule))
  102. {
  103. if (_hand == Hand.Blade1)
  104. {
  105. NotifyError(eEvent.ERR_EFEM_ROBOT, $"cannot use lower arm to pick from {_targetModule}", -1);
  106. return false;
  107. }
  108. }
  109. if (_hand == Hand.Blade1 && _flip == Flip.Down)
  110. {
  111. NotifyError(eEvent.ERR_EFEM_ROBOT, $"lower arm cannot flip", -1);
  112. return false;
  113. }
  114. if (ModuleHelper.IsSRD(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  115. {
  116. _srdModule = Singleton<RouteManager>.Instance.GetModule<SRDEntity>(_targetModule.ToString());
  117. if (!_srdModule.IsHomed)
  118. {
  119. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} is not homed, please home it first",-1);
  120. return false;
  121. }
  122. //判断arm是否在home位置上
  123. //JetAxisBase jetAxisBase = DEVICE.GetDevice<JetAxisBase>($"{_targetModule}.Arm");
  124. //double position = jetAxisBase.MotionData.MotorPosition;
  125. //bool result = jetAxisBase.CheckPositionIsInStation(position, "Home");
  126. //if (!result)
  127. //{
  128. // NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} armaxis {position} is not in homed place",-1);
  129. // return false;
  130. //}
  131. if (_srdModule.IsSrdDoorClosed)
  132. {
  133. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} door closed, can not pick",-1);
  134. return false;
  135. }
  136. if (!_srdModule.IsSrdChuckVacuum)
  137. {
  138. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} Vacuum on, can not pick",-1);
  139. return false;
  140. }
  141. if (_hand == Hand.Blade2)
  142. {
  143. NotifyError(eEvent.ERR_EFEM_ROBOT, $"cannot use upper hand to pick from loadport", -1);
  144. return false;
  145. }
  146. }
  147. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand))
  148. {
  149. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand} already has a wafer, cannot do the pick action",-1);
  150. return false;
  151. }
  152. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  153. {
  154. if (ModuleHelper.IsPUF(_targetModule))
  155. {
  156. _targetPufSlot = _targetSlot == 0 ? "SideA" : "SideB";
  157. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target: {_targetModule}.{_targetPufSlot} has no wafer, cannot do the pick action",-1);
  158. }
  159. else
  160. {
  161. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target slot: {_targetModule}.{_targetSlot + 1} has no wafer, cannot do the pick action",-1);
  162. }
  163. return false;
  164. }
  165. else
  166. {
  167. WaferInfo waferInfo = WaferManager.Instance.GetWafer(_targetModule, _targetSlot);
  168. if(waferInfo.Status!=WaferStatus.Normal)
  169. {
  170. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target slot: {_targetModule}.{_targetSlot + 1} wafer status is {waferInfo.Status}, cannot do the pick action", -1);
  171. return false;
  172. }
  173. }
  174. if (_moveQueue.Count >= 2)
  175. {
  176. if (!ModuleHelper.IsLoadPort(_targetModule))
  177. {
  178. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Wrong double pick command, target is not loadport",-1);
  179. return false;
  180. }
  181. _hand2 = _hand != Hand.Blade1 ? Hand.Blade1 : Hand.Blade2;
  182. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand2))
  183. {
  184. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand2} already has a wafer, cannot do the double pick action",-1);
  185. return false;
  186. }
  187. _targetSlot2 = _moveQueue.ToArray()[1].SourceSlot;
  188. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot2))
  189. {
  190. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target slot: {_targetModule}.{_targetSlot2 + 1} has no wafer, cannot do the double pick action",-1);
  191. return false;
  192. }
  193. }
  194. return true;
  195. }
  196. public RState Monitor()
  197. {
  198. if(_bDoublePick)
  199. {
  200. Runner.Wait(PickStep.WaitModuleReady, WaitModuleReady)
  201. .Run(PickStep.Picking1, Pick1, Pick1Done, _moveTimeout)
  202. .Run(PickStep.Picking2, Pick2, Pick2Done, _moveTimeout)
  203. .End(PickStep.End, ActionDone);
  204. }
  205. else
  206. {
  207. Runner.Wait(PickStep.WaitModuleReady, WaitModuleReady)
  208. .Run(PickStep.Picking1, Pick1, Pick1Done, _moveTimeout)
  209. .End(PickStep.End, ActionDone);
  210. }
  211. return Runner.Status;
  212. }
  213. public void Abort()
  214. {
  215. _efem.Halt();
  216. }
  217. private bool WaitModuleReady()
  218. {
  219. if (_efem.IsInPauseStatus)
  220. {
  221. return false;
  222. }
  223. return _efem.Status == RState.End;
  224. }
  225. private bool Pick1()
  226. {
  227. return _efem.Pick(_targetModule, _targetSlot, _hand,_flip);
  228. }
  229. private bool Pick1Done()
  230. {
  231. if (_efem.Status == RState.End)
  232. {
  233. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.EfemRobot, (int)_hand);
  234. return true;
  235. }
  236. else if (_efem.Status == RState.Failed)
  237. {
  238. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot picking failed: {_efem.Status}",-1);
  239. return true;
  240. }
  241. return false;
  242. }
  243. private bool Pick2()
  244. {
  245. return _efem.Pick(_targetModule, _targetSlot2, _hand2, _flip);
  246. }
  247. private bool Pick2Done()
  248. {
  249. if (_efem.Status == RState.End)
  250. {
  251. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot2, ModuleName.EfemRobot, (int)_hand2);
  252. return true;
  253. }
  254. else if (_efem.Status == RState.Failed)
  255. {
  256. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot picking failed: {_efem.Status}",-1);
  257. return true;
  258. }
  259. return false;
  260. }
  261. private bool ActionDone()
  262. {
  263. return true;
  264. }
  265. /// <summary>
  266. /// 重试
  267. /// </summary>
  268. /// <param name="step"></param>
  269. public RState Retry(int step)
  270. {
  271. if(!CheckPreCondition())
  272. {
  273. return RState.Failed;
  274. }
  275. _efem.Reset();
  276. List<Enum> preStepIds = new List<Enum>();
  277. AddPreSteps(PickStep.PufVacuumOff, preStepIds);
  278. return Runner.Retry(PickStep.PufVacuumOff, preStepIds, Module, "Pick Retry");
  279. }
  280. /// <summary>
  281. /// 忽略前
  282. /// </summary>
  283. /// <param name="step"></param>
  284. /// <param name="preStepIds"></param>
  285. private void AddPreSteps(PickStep step, List<Enum> preStepIds)
  286. {
  287. for (int i = 0; i < (int)step; i++)
  288. {
  289. preStepIds.Add((PickStep)i);
  290. }
  291. }
  292. /// <summary>
  293. /// 检验前面完成状态
  294. /// </summary>
  295. /// <returns></returns>
  296. public bool CheckCompleteCondition(int index)
  297. {
  298. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand))
  299. {
  300. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand} has no wafer", -1);
  301. return false;
  302. }
  303. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  304. {
  305. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} Slot{_targetSlot} has no wafer", -1);
  306. return false;
  307. }
  308. return true;
  309. }
  310. }
  311. }