EfemPickRoutine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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.PickRobotFlip;
  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. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target slot: {_targetModule}.{_targetSlot + 1} has no wafer, cannot do the pick action",-1);
  155. return false;
  156. }
  157. else
  158. {
  159. WaferInfo waferInfo = WaferManager.Instance.GetWafer(_targetModule, _targetSlot);
  160. if(waferInfo.Status!=WaferStatus.Normal)
  161. {
  162. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target slot: {_targetModule}.{_targetSlot + 1} wafer status is {waferInfo.Status}, cannot do the pick action", -1);
  163. return false;
  164. }
  165. }
  166. if (_moveQueue.Count >= 2)
  167. {
  168. if (!ModuleHelper.IsLoadPort(_targetModule))
  169. {
  170. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Wrong double pick command, target is not loadport",-1);
  171. return false;
  172. }
  173. _hand2 = _hand != Hand.Blade1 ? Hand.Blade1 : Hand.Blade2;
  174. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand2))
  175. {
  176. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand2} already has a wafer, cannot do the double pick action",-1);
  177. return false;
  178. }
  179. _targetSlot2 = _moveQueue.ToArray()[1].SourceSlot;
  180. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot2))
  181. {
  182. NotifyError(eEvent.ERR_EFEM_ROBOT, $"The target slot: {_targetModule}.{_targetSlot2 + 1} has no wafer, cannot do the double pick action",-1);
  183. return false;
  184. }
  185. }
  186. return true;
  187. }
  188. public RState Monitor()
  189. {
  190. if(_bDoublePick)
  191. {
  192. Runner.Wait(PickStep.WaitModuleReady, WaitModuleReady)
  193. .Run(PickStep.Picking1, Pick1, Pick1Done, _moveTimeout)
  194. .Run(PickStep.Picking2, Pick2, Pick2Done, _moveTimeout)
  195. .End(PickStep.End, ActionDone);
  196. }
  197. else
  198. {
  199. Runner.Wait(PickStep.WaitModuleReady, WaitModuleReady)
  200. .Run(PickStep.Picking1, Pick1, Pick1Done, _moveTimeout)
  201. .End(PickStep.End, ActionDone);
  202. }
  203. return Runner.Status;
  204. }
  205. public void Abort()
  206. {
  207. _efem.Halt();
  208. }
  209. private bool WaitModuleReady()
  210. {
  211. if (_efem.IsInPauseStatus)
  212. {
  213. return false;
  214. }
  215. return _efem.Status == RState.End;
  216. }
  217. private bool Pick1()
  218. {
  219. return _efem.Pick(_targetModule, _targetSlot, _hand,_flip);
  220. }
  221. private bool Pick1Done()
  222. {
  223. if (_efem.Status == RState.End)
  224. {
  225. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.EfemRobot, (int)_hand);
  226. return true;
  227. }
  228. else if (_efem.Status == RState.Failed)
  229. {
  230. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot picking failed: {_efem.Status}",-1);
  231. return true;
  232. }
  233. return false;
  234. }
  235. private bool Pick2()
  236. {
  237. return _efem.Pick(_targetModule, _targetSlot2, _hand2, _flip);
  238. }
  239. private bool Pick2Done()
  240. {
  241. if (_efem.Status == RState.End)
  242. {
  243. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot2, ModuleName.EfemRobot, (int)_hand2);
  244. return true;
  245. }
  246. else if (_efem.Status == RState.Failed)
  247. {
  248. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot picking failed: {_efem.Status}",-1);
  249. return true;
  250. }
  251. return false;
  252. }
  253. private bool ActionDone()
  254. {
  255. return true;
  256. }
  257. /// <summary>
  258. /// 重试
  259. /// </summary>
  260. /// <param name="step"></param>
  261. public RState Retry(int step)
  262. {
  263. if(!CheckPreCondition())
  264. {
  265. return RState.Failed;
  266. }
  267. _efem.Reset();
  268. List<Enum> preStepIds = new List<Enum>();
  269. AddPreSteps(PickStep.PufVacuumOff, preStepIds);
  270. return Runner.Retry(PickStep.PufVacuumOff, preStepIds, Module, "Pick Retry");
  271. }
  272. /// <summary>
  273. /// 忽略前
  274. /// </summary>
  275. /// <param name="step"></param>
  276. /// <param name="preStepIds"></param>
  277. private void AddPreSteps(PickStep step, List<Enum> preStepIds)
  278. {
  279. for (int i = 0; i < (int)step; i++)
  280. {
  281. preStepIds.Add((PickStep)i);
  282. }
  283. }
  284. /// <summary>
  285. /// 检验前面完成状态
  286. /// </summary>
  287. /// <returns></returns>
  288. public bool CheckCompleteCondition(int index)
  289. {
  290. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand))
  291. {
  292. NotifyError(eEvent.ERR_EFEM_ROBOT, $"Efem robot arm{_hand} has no wafer", -1);
  293. return false;
  294. }
  295. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  296. {
  297. NotifyError(eEvent.ERR_EFEM_ROBOT, $"{_targetModule} Slot{_targetSlot} has no wafer", -1);
  298. return false;
  299. }
  300. return true;
  301. }
  302. }
  303. }